mirror of
https://github.com/shiroikitsu8/Bayshore_6r_legacy.git
synced 2024-11-13 18:50:59 +01:00
add optional screenshot, and delete car feature
This commit is contained in:
parent
396f05705d
commit
1d4b6b995c
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,3 +10,4 @@ config.json
|
|||||||
package-lock.json
|
package-lock.json
|
||||||
ecosystem.config.js
|
ecosystem.config.js
|
||||||
static/*
|
static/*
|
||||||
|
screenshot/*
|
@ -12,6 +12,7 @@
|
|||||||
"scratchEnabled": 1,
|
"scratchEnabled": 1,
|
||||||
"scratchType": 1,
|
"scratchType": 1,
|
||||||
"giveMeterReward": 0,
|
"giveMeterReward": 0,
|
||||||
"newCardsBanned": 0
|
"newCardsBanned": 0,
|
||||||
|
"enableScreenshot": 0
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -47,12 +47,16 @@ export interface GameOptions {
|
|||||||
grantFullTuneTicketToNewUsers: number;
|
grantFullTuneTicketToNewUsers: number;
|
||||||
|
|
||||||
// Give meter reward every n*100 play
|
// Give meter reward every n*100 play
|
||||||
giveMeterReward: number; //1 is on, 0 is off
|
giveMeterReward: number; // 1 is on, 0 is off
|
||||||
|
|
||||||
// if the new card is not in the User databese
|
// if the new card is not in the User databese
|
||||||
// set this option to 1 will not create a new card
|
// set this option to 1 will not create a new card
|
||||||
// and prevent new card registration
|
// and prevent new card registration
|
||||||
newCardsBanned: number;//1 is on, 0 is off
|
newCardsBanned: number; // 1 is on, 0 is off
|
||||||
|
|
||||||
|
// revision check
|
||||||
|
// set this option to 1 to enable screenshot feature
|
||||||
|
enableScreenshot: number; // 1 is on, 0 is off
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Config {
|
export class Config {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { Application } from "express";
|
import { Application } from "express";
|
||||||
|
import { Config } from "../config";
|
||||||
import { Module } from "module";
|
import { Module } from "module";
|
||||||
import { prisma } from "..";
|
import { prisma } from "..";
|
||||||
|
|
||||||
@ -28,6 +29,19 @@ export default class CarModule extends Module {
|
|||||||
// Get Challenger Data
|
// Get Challenger Data
|
||||||
let opponentsTarget = await carFunctions.getOpponentsTarget(body.carId, registeredTarget.registeredargetAvailable);
|
let opponentsTarget = await carFunctions.getOpponentsTarget(body.carId, registeredTarget.registeredargetAvailable);
|
||||||
|
|
||||||
|
// Set Screenshot Count
|
||||||
|
let screenshotCount = 0;
|
||||||
|
|
||||||
|
// Check if screenshot feature enabled or not
|
||||||
|
let enableScreenshot = Config.getConfig().gameOptions.enableScreenshot || 0;
|
||||||
|
|
||||||
|
// Screenshot feature enabled
|
||||||
|
if(enableScreenshot === 1)
|
||||||
|
{
|
||||||
|
// Set the screnshot chance count
|
||||||
|
screenshotCount = 99;
|
||||||
|
}
|
||||||
|
|
||||||
// Response data
|
// Response data
|
||||||
let msg = {
|
let msg = {
|
||||||
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
|
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
|
||||||
@ -43,7 +57,7 @@ export default class CarModule extends Module {
|
|||||||
rgPreviousVersionPlayCount: 0,
|
rgPreviousVersionPlayCount: 0,
|
||||||
stCompleted_100Episodes: car!.stCompleted100Episodes,
|
stCompleted_100Episodes: car!.stCompleted100Episodes,
|
||||||
auraMotifAutoChange: false,
|
auraMotifAutoChange: false,
|
||||||
screenshotCount: 0,
|
screenshotCount: screenshotCount,
|
||||||
transferred: false,
|
transferred: false,
|
||||||
|
|
||||||
// Stamp or Challenger
|
// Stamp or Challenger
|
||||||
@ -136,33 +150,52 @@ export default class CarModule extends Module {
|
|||||||
// Get the request body for the update car request
|
// Get the request body for the update car request
|
||||||
let body = wm.wm.protobuf.UpdateCarRequest.decode(req.body);
|
let body = wm.wm.protobuf.UpdateCarRequest.decode(req.body);
|
||||||
|
|
||||||
// Update the car
|
// Not deleting car
|
||||||
await carFunctions.updateCar(body);
|
if(body.toBeDeleted === false || body.toBeDeleted === undefined || body.toBeDeleted === null)
|
||||||
|
|
||||||
// Update the car setting
|
|
||||||
await carFunctions.updateCarSetting(body);
|
|
||||||
|
|
||||||
// Update the car window Sticker
|
|
||||||
await carFunctions.updateCarWindowSticker(body);
|
|
||||||
|
|
||||||
// Update the car Custom Wing
|
|
||||||
await carFunctions.updateCarCustomWing(body);
|
|
||||||
|
|
||||||
// Get car item (custom color or discarded card)
|
|
||||||
if(body.earnedItems.length !== 0)
|
|
||||||
{
|
{
|
||||||
console.log('Car Item reward available, continuing ...');
|
// Update the car
|
||||||
for(let i=0; i<body.earnedItems.length; i++){
|
await carFunctions.updateCar(body);
|
||||||
await prisma.carItem.create({
|
|
||||||
data: {
|
// Update the car setting
|
||||||
carId: body.carId,
|
await carFunctions.updateCarSetting(body);
|
||||||
category: body.earnedItems[i].category,
|
|
||||||
itemId: body.earnedItems[i].itemId,
|
// Update the car window Sticker
|
||||||
amount: 1
|
await carFunctions.updateCarWindowSticker(body);
|
||||||
}
|
|
||||||
});
|
// Update the car Custom Wing
|
||||||
|
await carFunctions.updateCarCustomWing(body);
|
||||||
|
|
||||||
|
// Get car item (custom color or discarded card)
|
||||||
|
if(body.earnedItems.length !== 0)
|
||||||
|
{
|
||||||
|
console.log('Car Item reward available, continuing ...');
|
||||||
|
for(let i=0; i<body.earnedItems.length; i++){
|
||||||
|
await prisma.carItem.create({
|
||||||
|
data: {
|
||||||
|
carId: body.carId,
|
||||||
|
category: body.earnedItems[i].category,
|
||||||
|
itemId: body.earnedItems[i].itemId,
|
||||||
|
amount: 1
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Deleting car
|
||||||
|
else
|
||||||
|
{
|
||||||
|
console.log('Deleting Car ID : ' + body.carId);
|
||||||
|
|
||||||
|
// Mark Deleted Car
|
||||||
|
await prisma.carState.update({
|
||||||
|
where:{
|
||||||
|
dbId: body.carId
|
||||||
|
},
|
||||||
|
data:{
|
||||||
|
toBeDeleted: body.toBeDeleted
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Response data
|
// Response data
|
||||||
let msg = {
|
let msg = {
|
||||||
|
@ -230,22 +230,22 @@ export default class GameModule extends Module {
|
|||||||
// Save Screenshot
|
// Save Screenshot
|
||||||
app.post('/method/save_screenshot', async (req, res) => {
|
app.post('/method/save_screenshot', async (req, res) => {
|
||||||
|
|
||||||
// Get the information from the request
|
// Get the request body
|
||||||
let body = wm.wm.protobuf.SaveScreenshotRequest.decode(req.body);
|
let body = wm.wm.protobuf.SaveScreenshotRequest.decode(req.body);
|
||||||
|
|
||||||
// TODO: Actual stuff here
|
// Perform the save screenshot request for the car
|
||||||
// This is literally just bare-bones so the shit boots
|
await gameFunction.saveScreenshot(body);
|
||||||
|
|
||||||
// Response data
|
// Response data
|
||||||
let msg = {
|
let msg = {
|
||||||
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
|
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Encode the response
|
// Encode the response
|
||||||
let message = wm.wm.protobuf.SaveScreenshotResponse.encode(msg);
|
let message = wm.wm.protobuf.SaveScreenshotResponse.encode(msg);
|
||||||
|
|
||||||
// Send the response to the client
|
// Send the response to the client
|
||||||
common.sendResponse(message, res);
|
common.sendResponse(message, res);
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
import { prisma } from "../..";
|
import { prisma } from "../..";
|
||||||
|
import { Config } from "../../config";
|
||||||
|
import path from "path";
|
||||||
|
import fs from "fs";
|
||||||
|
|
||||||
// Import Proto
|
// Import Proto
|
||||||
import { wm } from "../../wmmt/wm.proto";
|
import { wm } from "../../wmmt/wm.proto";
|
||||||
@ -408,3 +411,40 @@ export async function getGhostBattleRecord(body: wm.protobuf.LoadGameHistoryRequ
|
|||||||
|
|
||||||
return { ghostBattle_records }
|
return { ghostBattle_records }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Save Screenshot
|
||||||
|
export async function saveScreenshot(body: wm.protobuf.SaveScreenshotRequest)
|
||||||
|
{
|
||||||
|
// Check if screenshot feature enabled or not
|
||||||
|
let enableScreenshot = Config.getConfig().gameOptions.enableScreenshot || 0;
|
||||||
|
|
||||||
|
// Screenshot feature enabled
|
||||||
|
if(enableScreenshot === 1)
|
||||||
|
{
|
||||||
|
let filename: string | undefined = undefined;
|
||||||
|
|
||||||
|
filename = `${body.timestamp}_${body.carId}_${body.imageType}.png`;
|
||||||
|
|
||||||
|
let dir = path.join('screenshot');
|
||||||
|
|
||||||
|
if (!fs.existsSync(dir)){
|
||||||
|
fs.mkdirSync(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Combine the filename with the save location
|
||||||
|
let fullname = path.join('screenshot', filename);
|
||||||
|
|
||||||
|
// Attempt to write to the file
|
||||||
|
fs.writeFile(fullname, body.image, (err) => {
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
console.log(`Screenshot saved successfully as '${filename}'`)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -39,6 +39,9 @@ export default class UserModule extends Module {
|
|||||||
state: true,
|
state: true,
|
||||||
gtWing: true,
|
gtWing: true,
|
||||||
lastPlayedPlace: true
|
lastPlayedPlace: true
|
||||||
|
},
|
||||||
|
where:{
|
||||||
|
state: { toBeDeleted: false } // except deleted car
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user