Skip to content

Commit

Permalink
- Reldens - v4.0.0-beta.32
Browse files Browse the repository at this point in the history
- Merge pull request #236 from damian-pastorini/v4.0.0-beta.32
  • Loading branch information
damian-pastorini authored Feb 7, 2024
2 parents bf90c50 + 7a12a89 commit 071af38
Show file tree
Hide file tree
Showing 32 changed files with 2,542 additions and 2,132 deletions.
8 changes: 4 additions & 4 deletions lib/ads/client/providers/crazy-games/videos-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ class VideosHandler

send(props)
{
let room = this.gameManager.activeRoomEvents?.room;
if(!room){
Logger.warning('CrazyGames - Room undefined to send an Ad Video message.');
let roomEvents = this.gameManager?.activeRoomEvents;
if(!roomEvents){
Logger.warning('CrazyGames - RoomEvents undefined to send an Ad Video message.');
return false;
}
return room.send('*', props);
return roomEvents?.send(props);
}

}
Expand Down
8 changes: 4 additions & 4 deletions lib/ads/client/providers/game-monetize.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,12 @@ class GameMonetize

send(props)
{
let room = this.gameManager.activeRoomEvents?.room;
if(!room){
Logger.warning('GameMonetize - Room undefined to send an Ad Video message.');
let roomEvents = this.gameManager?.activeRoomEvents;
if(!roomEvents){
Logger.warning('GameMonetize - RoomEvents undefined to send an Ad Video message.');
return false;
}
return room.send('*', props);
return roomEvents.send(props);
}

}
Expand Down
5 changes: 1 addition & 4 deletions lib/audio/client/audio-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ class AudioUi
for(let settingInput of audioSettingInputs){
settingInput.addEventListener('click', async (event) => {
await this.audioManager.setAudio(event.target.dataset.categoryKey, settingInput.checked);
this.gameManager.activeRoomEvents.room.send(
'*',
new AudioUpdate(settingInput.value, settingInput.checked)
);
this.gameManager.activeRoomEvents.send(new AudioUpdate(settingInput.value, settingInput.checked));
this.sceneAudioPlayer.playSceneAudio(this.audioManager, this.gameManager.getActiveScene());
});
}
Expand Down
16 changes: 13 additions & 3 deletions lib/chat/client/chat-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ class ChatUi
// both global or private messages use the global chat room:
this.useGlobalRoom()
? this.useGlobalRoomForMessage(message)
: this.gameManager.activeRoomEvents.room.send('*', message);
: this.gameManager.activeRoomEvents.send(message);
// for last empty the input once the message was sent:
this.chatInput.value = '';
if(this.closeChatBoxAfterSend){
Expand Down Expand Up @@ -535,7 +535,7 @@ class ChatUi
this.sendPrivateMessage(message, globalChat);
return;
}
globalChat.send('*', message);
this.globalSend(globalChat, message);
}

sendPrivateMessage(message, globalChat)
Expand All @@ -545,7 +545,17 @@ class ChatUi
return false;
}
message.t = playerName;
globalChat.send('*', message);
this.globalSend(globalChat, message);
}

globalSend(globalChat, message)
{
try {
globalChat.send('*', message);
} catch (error) {
Logger.critical(error);
this.gameDom.alertReload(this.gameManager.services.translator.t('game.errors.connectionLost'));
}
}

}
Expand Down
21 changes: 17 additions & 4 deletions lib/game/client/room-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ class RoomEvents
};
let overrideSendOptions = sc.get(props, 'overrideSendOptions', {});
Object.assign(optionSend, overrideSendOptions);
this.room.send('*', optionSend);
this.send(optionSend);
});
}
}
Expand Down Expand Up @@ -592,9 +592,9 @@ class RoomEvents
// @NOTE: player states must be requested since are private user data that we can share with other players or
// broadcast to the rooms.
// request player stats after the player was added to the scene:
this.room.send('*', {act: GameConst.PLAYER_STATS});
this.send({act: GameConst.PLAYER_STATS});
// send notification about client joined:
this.room.send('*', {act: GameConst.CLIENT_JOINED});
this.send({act: GameConst.CLIENT_JOINED});
let playerAddEventData = { player: currentScene.player, previousScene, roomEvents: this};
await this.events.emit('reldens.playersOnAddReady', playerAddEventData);
let eventData = {currentScene, previousScene, roomEvents: this};
Expand Down Expand Up @@ -681,14 +681,27 @@ class RoomEvents

createPlayerEngineInstance(currentScene, player, gameManager, room)
{
return new PlayerEngine({scene: currentScene, playerData: player, gameManager, room});
return new PlayerEngine({scene: currentScene, playerData: player, gameManager, room, roomEvents: this});
}

createPreloaderInstance(props)
{
return new ScenePreloader(props);
}

send(data, key)
{
try {
if(!key){
key = '*';
}
this.room.send(key, data);
} catch (error) {
Logger.critical(error, data);
this.gameManager.gameDom.alertReload(this.gameManager.services.translator.t('game.errors.connectionLost'));
}
}

}

module.exports.RoomEvents = RoomEvents;
32 changes: 12 additions & 20 deletions lib/game/client/scene-dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,17 @@ class SceneDynamic extends Scene
setPropertiesFromConfig()
{
// @TODO - BETA - Move defaults to constants.
if(!this.gameManager.config){
if(!this.configManager){
this.configuredFrameRate = 10;
this.clientInterpolation = true;
this.interpolationSpeed = 0.5;
this.interpolationSpeed = 0.1;
this.minimapConfig = {};
return false;
}
this.configuredFrameRate = this.gameManager.config.getWithoutLogs(
'client/general/animations/frameRate',
10
);
this.clientInterpolation = this.gameManager.config.getWithoutLogs(
'client/general/engine/clientInterpolation',
true
);
this.interpolationSpeed = this.gameManager.config.getWithoutLogs(
'client/general/engine/interpolationSpeed',
0.5
);
this.minimapConfig = this.gameManager.config.getWithoutLogs('client/ui/minimap', {});
this.configuredFrameRate = this.configManager.getWithoutLogs('client/general/animations/frameRate', 10);
this.clientInterpolation = this.configManager.getWithoutLogs('client/general/engine/clientInterpolation', true);
this.interpolationSpeed = this.configManager.getWithoutLogs('client/general/engine/interpolationSpeed', 0.1);
this.minimapConfig = this.configManager.getWithoutLogs('client/ui/minimap', {});
return true;
}

Expand Down Expand Up @@ -290,22 +281,22 @@ class SceneDynamic extends Scene
if(0 === playerKeys.length){
return;
}
if(!sc.get(this.player, 'players')){
return;
}
for(let i of playerKeys){
if(!this.player){
break;
}
let entityState = this.interpolatePlayersPosition[i];
let entity = this.player.players[i];
if(!entity){
continue;
}
if(entity.x === entityState.x && entity.y === entityState.y){
if(this.isCurrentPosition(entity, entityState)){
delete this.interpolatePlayersPosition[i];
continue;
}
let newX = Phaser.Math.Linear(entity.x, (entityState.x - this.player.leftOff), this.interpolationSpeed);
let newY = Phaser.Math.Linear(entity.y, (entityState.y - this.player.topOff), this.interpolationSpeed);
this.player.processPlayerPositionAnimationUpdate(entity, entityState, i, newX, newY);
delete this.interpolatePlayersPosition[i];
}
}

Expand Down Expand Up @@ -371,6 +362,7 @@ class SceneDynamic extends Scene
isCurrentPosition(entity, entityState)
{
if(!entity || !entityState){
Logger.warning('None entity found to compare current entity position.');
return false;
}
return entity.x === entityState.x && entity.y === entityState.y;
Expand Down
12 changes: 7 additions & 5 deletions lib/game/client/scene-preloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,15 @@ class ScenePreloader extends Scene
if(this.gameManager.createdAnimations[anim.k]){
return;
}
this.gameManager.createdAnimations[anim.k] = this.anims.create({
let animationConfig = {
key: anim.k,
frames: this.anims.generateFrameNumbers(anim.img, {start: anim.start, end: anim.end}),
frameRate: sc.hasOwn(anim, 'rate') ? anim.rate : this.configuredFrameRate,
repeat: anim.repeat,
hideOnComplete: sc.hasOwn(anim, 'hide') ? anim.hide : true,
});
};
Logger.debug('Creating animation: '+anim.k, animationConfig);
this.gameManager.createdAnimations[anim.k] = this.anims.create(animationConfig);
return this.gameManager.createdAnimations[anim.k];
}

Expand Down Expand Up @@ -437,7 +439,7 @@ class ScenePreloader extends Scene
target: currentScene.player.currentTarget,
type: action
};
this.gameManager.activeRoomEvents.room.send('*', dataSend);
this.gameManager.activeRoomEvents.send(dataSend);
});
}

Expand Down Expand Up @@ -476,7 +478,7 @@ class ScenePreloader extends Scene
type: action.type
};
}
this.gameManager.activeRoomEvents.room.send('*', dataSend);
this.gameManager.activeRoomEvents.send(dataSend);
}

endHold(event, button)
Expand All @@ -486,7 +488,7 @@ class ScenePreloader extends Scene
button.classList.remove('button-opacity-off');
}
clearTimeout(this.holdTimer);
this.gameManager.activeRoomEvents.room.send('*', {act: GameConst.STOP});
this.gameManager.activeRoomEvents.send({act: GameConst.STOP});
}

createProgressBar()
Expand Down
4 changes: 3 additions & 1 deletion lib/game/client/snippets/en_US.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ module.exports = {
joiningFeatureRoom: 'There was an error while joining the feature room "%joinRoomName".',
reconnectClient: 'Reconnect Game Client error.',
sessionEnded: 'Your session ended, please login again.',
connectionLost: 'Connection lost, please login again.',
serverDown: 'Server is offline.'
}
},
pleaseSelectScene: 'Please select a Scene'
}
}
2 changes: 1 addition & 1 deletion lib/game/client/user-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class UserInterface
closeButton.id = GameConst.UI_BOX + GameConst.UI_CLOSE + '-' + this.id;
closeButton.addEventListener('click', () => {
if(!sc.hasOwn(this.animProps, 'sendCloseMessage') || false === this.animProps['sendCloseMessage']){
uiScene.gameManager.activeRoomEvents.room.send('*', {act: GameConst.CLOSE_UI_ACTION, id: this.id});
uiScene.gameManager.activeRoomEvents.send({act: GameConst.CLOSE_UI_ACTION, id: this.id});
}
// @TODO - BETA - Replace styles classes.
if(sc.get(this.animProps, 'defaultClose', true)){
Expand Down
20 changes: 19 additions & 1 deletion lib/game/server/login-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ class LoginManager
{
// check if the passwords match:
if(!this.passwordManager.validatePassword(userData.password, user.password)){
let result = {error: 'Invalid user data.'};
let result = {error: 'Login, invalid user data.'};
Logger.debug('Invalid user data.', userData);
this.events.emitSync('reldens.loginInvalidPassword', this, user, userData, result);
return result;
}
Expand Down Expand Up @@ -218,6 +219,14 @@ class LoginManager
return result;
}
let initialState = await this.prepareInitialState(loginData['selectedScene']);
if(!await this.validateInitialState(initialState)){
let result = {
error: true,
message: 'There was an error with the player initial state, please contact the administrator.'
};
await this.events.emit('reldens.playerSceneUnavailable', this, loginData, result);
return result;
}
let playerData = {
name: loginData['new-player-name'],
user_id: loginData.user_id,
Expand All @@ -244,6 +253,15 @@ class LoginManager
}
}

async validateInitialState(initialState)
{
let roomId = sc.get(initialState, 'room_id', false);
if(false === roomId){
return false;
}
return await this.roomsManager.loadRoomById(roomId);
}

async prepareInitialState(roomName)
{
let config = this.config.get('client/rooms/selection');
Expand Down
1 change: 1 addition & 0 deletions lib/game/server/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class ServerManager
'colyseus: '+PackageData.dependencies['colyseus'],
'phaser: '+PackageData.dependencies['phaser'],
'firebase: '+PackageData.dependencies['firebase'],
'firebaseui: '+PackageData.dependencies['firebaseui'],
'reldens/utils: '+PackageData.dependencies['@reldens/utils'],
'reldens/storage: '+PackageData.dependencies['@reldens/storage'],
'reldens/modifiers: '+PackageData.dependencies['@reldens/modifiers'],
Expand Down
2 changes: 1 addition & 1 deletion lib/inventory/client/exchange/trade-target-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TradeTargetAction
}
tradeStartButton.addEventListener('click', () => {
let sendData = {act: InventoryConst.ACTIONS.TRADE_START, id: target.id};
gameManager.room.send('*', sendData);
gameManager.activeRoomEvents.send(sendData);
});
}

Expand Down
4 changes: 2 additions & 2 deletions lib/inventory/client/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ class InventoryPlugin extends PluginInterface
idx: idx,
act: InventoryConst.ACTIONS.REMOVE
};
preloadScene.gameManager.room.send('*', optionSend);
preloadScene.gameManager.activeRoomEvents.send(optionSend);
});
if(this.isUsable(item)){
let useBtn = domMan.getElement('#item-use-'+idx);
Expand All @@ -397,7 +397,7 @@ class InventoryPlugin extends PluginInterface

clickedBox(itemId, action, preloadScene)
{
preloadScene.gameManager.room.send('*', {act: action, idx: itemId});
preloadScene.gameManager.activeRoomEvents.send({act: action, idx: itemId});
}

getUsableContent(item, gameManager, uiScene)
Expand Down
8 changes: 4 additions & 4 deletions lib/inventory/client/trade-message-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class TradeMessageHandler
{
let confirmButton = this.gameManager.gameDom.getElement('.confirm-'+this.message.id);
confirmButton?.addEventListener('click', () => {
this.gameManager.activeRoomEvents.room.send('*', {
this.gameManager.activeRoomEvents.send({
act: InventoryConst.ACTIONS.TRADE_ACTION,
id: this.message.id,
value: this.message.id,
Expand All @@ -160,7 +160,7 @@ class TradeMessageHandler
});
let disconfirmButton = this.gameManager.gameDom.getElement('.disconfirm-'+this.message.id);
disconfirmButton?.addEventListener('click', () => {
this.gameManager.activeRoomEvents.room.send('*', {
this.gameManager.activeRoomEvents.send({
act: InventoryConst.ACTIONS.TRADE_ACTION,
id: this.message.id,
value: this.message.id,
Expand Down Expand Up @@ -301,7 +301,7 @@ class TradeMessageHandler
itemKey: item.key,
};
dataSend[ObjectsConst.TRADE_ACTIONS.SUB_ACTION] = ObjectsConst.TRADE_ACTIONS.REMOVE;
this.gameManager.activeRoomEvents.room.send('*', dataSend);
this.gameManager.activeRoomEvents.send(dataSend);
});
}
return true;
Expand Down Expand Up @@ -440,7 +440,7 @@ class TradeMessageHandler
qty: Number(qtySelected)
};
dataSend[ObjectsConst.TRADE_ACTIONS.SUB_ACTION] = ObjectsConst.TRADE_ACTIONS.ADD;
this.gameManager.activeRoomEvents.room.send('*', dataSend);
this.gameManager.activeRoomEvents.send(dataSend);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/objects/client/animation-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class AnimationEngine
id: tempId,
type: this.type
};
this.gameManager.activeRoomEvents.room.send('*', dataSend);
this.gameManager.activeRoomEvents.send(dataSend);
if(!this.targetName){
return false;
}
Expand Down
Loading

0 comments on commit 071af38

Please sign in to comment.