mirror of
https://github.com/cloudmaker97/TikTok-mGBA-Emulator.git
synced 2025-12-06 07:58:38 +00:00
Zweiter Prototyp mit erfolgreichem Test gestartet
This commit is contained in:
parent
8a65ce78a5
commit
7e2ac464ae
8 changed files with 40 additions and 15 deletions
|
|
@ -116,7 +116,6 @@ export class GameController {
|
||||||
let gameKeyInterpretation = message.getMessageGameKey();
|
let gameKeyInterpretation = message.getMessageGameKey();
|
||||||
if (gameKeyInterpretation !== false) {
|
if (gameKeyInterpretation !== false) {
|
||||||
this.getUserStorage().getUser(user.getUserId()).then((storageUser) => {
|
this.getUserStorage().getUser(user.getUserId()).then((storageUser) => {
|
||||||
console.log(storageUser);
|
|
||||||
if (storageUser === undefined) {
|
if (storageUser === undefined) {
|
||||||
this.getUserStorage().createUser(parseInt(user.getUserId()), FREE_GAME_INPUT_MOVES);
|
this.getUserStorage().createUser(parseInt(user.getUserId()), FREE_GAME_INPUT_MOVES);
|
||||||
this.chatHandlerForGameInteraction(message, user);
|
this.chatHandlerForGameInteraction(message, user);
|
||||||
|
|
@ -127,16 +126,26 @@ export class GameController {
|
||||||
if(hasBalance) {
|
if(hasBalance) {
|
||||||
// Subtract the credit from the user when the user is not a developer
|
// Subtract the credit from the user when the user is not a developer
|
||||||
if(!this.getDeveloperUserIds().includes(parseInt(user.getUserId()))) {
|
if(!this.getDeveloperUserIds().includes(parseInt(user.getUserId()))) {
|
||||||
this.getUserStorage().updateUserCredits(user.getUserId(), storageUser.credits - 1);
|
this.getUserStorage().updateUserCredits(user.getUserId(), storageUser.credits - 1).then(() => {
|
||||||
|
// Send the button tap to the mGBA API
|
||||||
|
this.mgbaHttpClient
|
||||||
|
.buttonTapCreate({
|
||||||
|
key: gameKeyInterpretation.toString(),
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
Logger.logMessage(`Button tap for ${gameKeyInterpretation} created by ${user.getDisplayName()}`, "ChatInteraction");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Send the button tap to the mGBA API
|
||||||
|
this.mgbaHttpClient
|
||||||
|
.buttonTapCreate({
|
||||||
|
key: gameKeyInterpretation.toString(),
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
Logger.logMessage(`Button tap for ${gameKeyInterpretation} created by ${user.getDisplayName()}`, "ChatInteraction");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// Send the button tap to the mGBA API
|
|
||||||
this.mgbaHttpClient
|
|
||||||
.buttonTapCreate({
|
|
||||||
key: gameKeyInterpretation.toString(),
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
Logger.logMessage(`Button tap for ${gameKeyInterpretation} created by ${user.getDisplayName()}`, "GameInput");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -159,6 +168,7 @@ export class GameController {
|
||||||
private giftHandler(data: any): void {
|
private giftHandler(data: any): void {
|
||||||
let giftObject = this.availableGifts.get(data.giftId);
|
let giftObject = this.availableGifts.get(data.giftId);
|
||||||
if(giftObject) {
|
if(giftObject) {
|
||||||
|
Logger.logMessage(`Gift received: ${giftObject.getName()} from ${data.userId} with value ${giftObject.getCostDiamonds()}`, "ChatInteraction", LogLevel.INFO);
|
||||||
let giftValue = giftObject.getCostDiamonds();
|
let giftValue = giftObject.getCostDiamonds();
|
||||||
this.getUserStorage().getUser(data.userId).then((storageUser) => {
|
this.getUserStorage().getUser(data.userId).then((storageUser) => {
|
||||||
if(storageUser === undefined) {
|
if(storageUser === undefined) {
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,19 @@ export class UserStorage {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async intervalUserCredits(amountOfCredits: number): Promise<void> {
|
||||||
|
Logger.logMessage(`Increasing credits for all users by ${amountOfCredits}`, "Database", LogLevel.INFO);
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.database.run('UPDATE users SET credits = credits + ?', [amountOfCredits], (err) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the credits for a user in the database
|
* Update the credits for a user in the database
|
||||||
* @param userId {string}
|
* @param userId {string}
|
||||||
|
|
@ -28,6 +41,7 @@ export class UserStorage {
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
public async updateUserCredits(userId: string, credits: number): Promise<void> {
|
public async updateUserCredits(userId: string, credits: number): Promise<void> {
|
||||||
|
Logger.logMessage(`Updating credits for user ${userId} to ${credits}`, "Database", LogLevel.INFO);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.database.run('UPDATE users SET credits = ? WHERE id = ?', [credits, userId], (err) => {
|
this.database.run('UPDATE users SET credits = ? WHERE id = ?', [credits, userId], (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
@ -45,8 +59,9 @@ export class UserStorage {
|
||||||
* @returns {Promise<IUser>}
|
* @returns {Promise<IUser>}
|
||||||
*/
|
*/
|
||||||
public async getUser(userId: string): Promise<IUser> {
|
public async getUser(userId: string): Promise<IUser> {
|
||||||
|
Logger.logMessage(`Getting user ${userId} from the database`, "Database", LogLevel.INFO);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.database.get('SELECT * FROM users WHERE id = ?', [userId], (err, row: IUser) => {
|
this.database.get('SELECT * FROM users WHERE id = ?', [parseInt(userId)], (err, row: IUser) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,3 @@
|
||||||
import { GameController } from "./classes/controller/GameController";
|
import { GameController } from "./classes/controller/GameController";
|
||||||
import { UserStorage } from "./classes/modules/database/Storage";
|
|
||||||
|
|
||||||
new GameController("mr.vadim_");
|
new GameController("Hoodienie");
|
||||||
|
|
||||||
new UserStorage();
|
|
||||||
BIN
roms/pokemon_red.gb
Normal file
BIN
roms/pokemon_red.gb
Normal file
Binary file not shown.
BIN
roms/pokemon_red.sav
Normal file
BIN
roms/pokemon_red.sav
Normal file
Binary file not shown.
3
start.bat
Normal file
3
start.bat
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
start ./http/server/mGBA-http-server.exe
|
||||||
|
cd node
|
||||||
|
pnpm start
|
||||||
BIN
stream/graphics/gba_pokemon.jpg
Normal file
BIN
stream/graphics/gba_pokemon.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 162 KiB |
BIN
stream/graphics/gba_pokemon.png
Normal file
BIN
stream/graphics/gba_pokemon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 434 KiB |
Loading…
Reference in a new issue