Skip to content

Commit

Permalink
- Reldens - v4.0.0-beta.33
Browse files Browse the repository at this point in the history
- Merge pull request #237 from damian-pastorini/v4.0.0-beta.33
  • Loading branch information
damian-pastorini authored Feb 10, 2024
2 parents 071af38 + fb893f8 commit a2d93b5
Show file tree
Hide file tree
Showing 39 changed files with 557 additions and 257 deletions.
2 changes: 1 addition & 1 deletion lib/actions/server/skills/type-physical-attack.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class TypePhysicalAttack extends PhysicalAttack
removeBullet(body)
{
body.world.removeBodies.push(body);
// @TODO - BETA - Refactor and extract Colyseus into a driver.
// @TODO - BETA - Refactor and extract Colyseus into a driver. Check is been used?
this.room.state.removeBody(this.key+'_bullet_'+body.id);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/actions/server/skills/type-physical-effect.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class TypePhysicalEffect extends PhysicalEffect
removeBullet(body)
{
body.world.removeBodies.push(body);
// @TODO - BETA - Refactor and extract Colyseus into a driver.
// @TODO - BETA - Refactor and extract Colyseus into a driver. Check is been used?
this.room.state.removeBody(this.key+'_bullet_'+body.id);
}

Expand Down
13 changes: 7 additions & 6 deletions lib/audio/client/scene-audio-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,36 +38,37 @@ class SceneAudioPlayer
continue;
}
sprite.on('animationstart', (event) => {
let associatedAudio = this.attachAudioToSprite(sprite, event.key, audioManager, sceneDynamic);
if(associatedAudio !== false){
let animationKey = AudioConst.AUDIO_ANIMATION_KEY_START+event.key;
let associatedAudio = this.attachAudioToSprite(sprite, animationKey, audioManager, sceneDynamic);
if(false !== associatedAudio){
this.playSpriteAudio(associatedAudio, sceneDynamic.key, audioManager);
}
});
sprite.on('animationupdate', (event) => {
let animationKey = AudioConst.AUDIO_ANIMATION_KEY_UPDATE+event.key;
let associatedAudio = this.attachAudioToSprite(sprite, animationKey, audioManager, sceneDynamic);
if(associatedAudio !== false){
if(false !== associatedAudio){
this.playSpriteAudio(associatedAudio, sceneDynamic.key, audioManager);
}
});
sprite.on('animationcomplete', (event) => {
let animationKey = AudioConst.AUDIO_ANIMATION_KEY_COMPLETE+event.key;
let associatedAudio = this.attachAudioToSprite(sprite, animationKey, audioManager, sceneDynamic);
if(associatedAudio !== false){
if(false !== associatedAudio){
this.playSpriteAudio(associatedAudio, sceneDynamic.key, audioManager);
}
});
sprite.on('animationrepeat', (event) => {
let animationKey = AudioConst.AUDIO_ANIMATION_KEY_REPEAT+event.key;
let associatedAudio = this.attachAudioToSprite(sprite, animationKey, audioManager, sceneDynamic);
if(associatedAudio !== false){
if(false !== associatedAudio){
this.playSpriteAudio(associatedAudio, sceneDynamic.key, audioManager);
}
});
sprite.on('animationstop', (event) => {
let animationKey = AudioConst.AUDIO_ANIMATION_KEY_STOP+event.key;
let associatedAudio = this.attachAudioToSprite(sprite, animationKey, audioManager, sceneDynamic);
if(associatedAudio !== false){
if(false !== associatedAudio){
this.playSpriteAudio(associatedAudio, sceneDynamic.key, audioManager);
}
});
Expand Down
1 change: 1 addition & 0 deletions lib/audio/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
module.exports.AudioConst = {
AUDIO_UPDATE: 'ap',
AUDIO_DELETE: 'ad',
AUDIO_ANIMATION_KEY_START: 'i_',
AUDIO_ANIMATION_KEY_UPDATE: 'u_',
AUDIO_ANIMATION_KEY_COMPLETE: 'c_',
AUDIO_ANIMATION_KEY_REPEAT: 'r_',
Expand Down
3 changes: 2 additions & 1 deletion lib/game/client/game-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const { ConfigManager } = require('../../config/client/config-manager');
const { TranslationsMapper } = require('../../snippets/client/translations-mapper');
const Translations = require('./snippets/en_US');
const { GameDom } = require('./game-dom');
const { RoomsConst } = require('../../rooms/constants');
const { GameConst } = require('../constants');
const { ErrorManager, EventsManagerSingleton, Logger, sc } = require('@reldens/utils');

Expand Down Expand Up @@ -188,7 +189,7 @@ class GameManager
// since the user is now registered:
this.userData.isNewUser = false;
await this.joinFeaturesRooms();
let useLastLocation = '' !== selectedScene && selectedScene !== '@lastLocation';
let useLastLocation = '' !== selectedScene && selectedScene !== RoomsConst.ROOM_LAST_LOCATION_KEY;
let playerScene = useLastLocation ? selectedScene : this.playerData.state.scene;
this.playerData.state.scene = playerScene;
let joinedFirstRoom = await this.gameClient.joinOrCreate(playerScene, this.userData);
Expand Down
20 changes: 16 additions & 4 deletions lib/game/client/room-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ class RoomEvents

async runChangeScene(message)
{
if(message.act === GameConst.CHANGING_SCENE){
this.gameManager.getActiveScene().scene.setVisible(false);
}
if(
message.act !== GameConst.CHANGED_SCENE
|| message.scene !== this.room.name
Expand Down Expand Up @@ -578,6 +581,10 @@ class RoomEvents

async createEngineScene(player, room, previousScene)
{
let previousSceneInstance = this.gameEngine.scene.getScene(previousScene);
if(previousSceneInstance){
previousSceneInstance.scene.setVisible(false);
}
// this event happens once for every scene:
await this.events.emit('reldens.createEngineScene', player, room, previousScene, this);
!this.gameManager.room
Expand Down Expand Up @@ -645,12 +652,17 @@ class RoomEvents

async destroyPreviousScene(previousScene, player)
{
if(!previousScene || !this.gameEngine.scene.getScene(previousScene)){
if(!previousScene){
Logger.warning('Missing previous scene data.', previousScene);
return false;
}
let previousSceneInstance = this.gameEngine.scene.getScene(previousScene);
if(!previousSceneInstance){
Logger.warning('Missing previous scene instance.', previousSceneInstance);
return false;
}
// destroy previous scene tile set:
await this.gameEngine.scene.getScene(previousScene).changeScene();
// stop the previous scene and start the new one:
// previousSceneInstance.scene.setVisible(false);
await previousSceneInstance.changeScene();
this.gameEngine.scene.stop(previousScene);
this.gameEngine.scene.start(player.state.scene);
}
Expand Down
18 changes: 18 additions & 0 deletions lib/game/client/scene-dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ class SceneDynamic extends Scene
}
for(let i of playerKeys){
let entityState = this.interpolatePlayersPosition[i];
if(!entityState){
continue;
}
let entity = this.player.players[i];
if(!entity){
continue;
Expand All @@ -297,6 +300,9 @@ class SceneDynamic extends Scene
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);
if(!entityState.mov){
delete this.interpolatePlayersPosition[i];
}
}
}

Expand All @@ -323,6 +329,9 @@ class SceneDynamic extends Scene
return;
}
let entityState = this.interpolateObjectsPositions[i];
if(!entityState){
return;
}
if(this.isCurrentPosition(entity, entityState)){
delete this.interpolateObjectsPositions[i];
return;
Expand All @@ -332,6 +341,9 @@ class SceneDynamic extends Scene
y: Phaser.Math.Linear(entity.y, entityState.y, this.interpolationSpeed)
};
objectsPlugin.updateBulletBodyPosition(i, bodyData);
if(!entityState.mov){
delete this.interpolateObjectsPositions[i];
}
}

isBullet(objectKey)
Expand All @@ -346,6 +358,9 @@ class SceneDynamic extends Scene
return;
}
let entityState = this.interpolateObjectsPositions[i];
if(!entityState){
return;
}
if(this.isCurrentPosition(entity, entityState)){
delete this.interpolateObjectsPositions[i];
return;
Expand All @@ -357,6 +372,9 @@ class SceneDynamic extends Scene
mov: entityState.mov
};
objectsPlugin.updateObjectsAnimations(i, bodyData, this);
if(!entityState.mov){
delete this.interpolateObjectsPositions[i];
}
}

isCurrentPosition(entity, entityState)
Expand Down
1 change: 1 addition & 0 deletions lib/game/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports.GameConst = {
ACTION_KEY: 'act',
CREATE_PLAYER: 'cp',
CREATE_PLAYER_RESULT: 'cps',
CHANGING_SCENE: 'cgs',
CHANGED_SCENE: 'cs',
RECONNECT: 'r',
ROOM_GAME: 'room_game',
Expand Down
7 changes: 6 additions & 1 deletion lib/game/server/login-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

const { PasswordManager } = require('./password-manager');
const { RoomsConst } = require('../../rooms/constants');
const { GameConst } = require('../constants');
const { ErrorManager, Logger, sc } = require('@reldens/utils');

Expand Down Expand Up @@ -141,7 +142,11 @@ class LoginManager
continue;
}
let config = this.config.get('client/rooms/selection');
if(config.allowOnLogin && userData['selectedScene'] && userData['selectedScene'] !== '@lastLocation'){
if(
config.allowOnLogin
&& userData['selectedScene']
&& userData['selectedScene'] !== RoomsConst.ROOM_LAST_LOCATION_KEY
){
await this.applySelectedLocation(player, userData['selectedScene']);
}
player.state.scene = await this.getRoomNameById(player.state.room_id);
Expand Down
19 changes: 18 additions & 1 deletion lib/objects/client/animation-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,18 @@ class AnimationEngine
this.zeroPad = props.zeroPad || false;
this.prefix = props.prefix || false;
this.isInteractive = props.isInteractive || false;
this.highlightOnOver = Boolean(sc.get(
props,
'highlightOnOver',
this.gameManager.config.getWithoutLogs('client/ui/animations/highlightOnOver', true)
));
this.highlightColor = sc.get(
props,
'highlightColor',
this.gameManager.config.getWithoutLogs('client/ui/animations/highlightColor', '0x00ff00')
);
this.restartTime = sc.get(props, 'restartTime', false);
this.calculateAnimPosition();
this.extraAnimations = {};
// @NOTE: having this here we will get the animations generated for each object instance, so normally you would
// get duplicated animations for any respawn "multiple" object, BUT, at the same time, you could have an
// animation for a specific instance ID, we need to keep this here and check if the animation already exists on
Expand Down Expand Up @@ -203,6 +212,14 @@ class AnimationEngine
currentScene.player.currentTarget = thisTarget;
this.gameManager.gameEngine.showTarget(this.targetName, thisTarget, previousTarget);
});
if(this.highlightOnOver){
this.sceneSprite.on('pointerover', () => {
this.sceneSprite.setTint(this.highlightColor);
});
this.sceneSprite.on('pointerout', () => {
this.sceneSprite.clearTint();
});
}
}

runAnimation()
Expand Down
25 changes: 21 additions & 4 deletions lib/objects/client/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,17 @@ class ObjectsPlugin extends PluginInterface
await this.events.emit('reldens.objectBodyChange', {body, key, changes: {[bodyProp]: value}});
this.updateBodyProperties(bodyProp, stateProps, body, value);
let currentScene = gameManager.activeRoomEvents.getActiveScene();
if(currentScene.clientInterpolation && GameConst.STATUS.AVOID_INTERPOLATION !== body.inState){
let isBullet = -1 !== key.indexOf('bullet');
let currentBody = isBullet ? this.bullets[key] : currentScene.objectsAnimations[key];
let currentBodyAxleCondition = currentBody && 0 < currentBody.x || currentBody && 0 < currentBody.y;
let axleCondition = 0 < body.x || 0 < body.y;
let canInterpolate = GameConst.STATUS.AVOID_INTERPOLATION !== body.inState;
this.setVisibility(currentBody, currentBodyAxleCondition, axleCondition);
Logger.debug({key, bodyProp, value, currentBody, updatedBody: body});
if(currentScene.clientInterpolation && canInterpolate && axleCondition && currentBodyAxleCondition){
currentScene.interpolateObjectsPositions[key] = body;
return;
}
let isBullet = -1 !== key.indexOf('bullet');
if(isBullet){
return this.updateBulletBodyPosition(key, body);
}
Expand All @@ -141,6 +147,14 @@ class ObjectsPlugin extends PluginInterface
}
}

setVisibility(currentBody, currentBodyAxleCondition, axleCondition)
{
if(!currentBody || !currentBody.sceneSprite){
return;
}
currentBody?.sceneSprite?.setVisible(axleCondition);
}

updateBodyProperties(bodyProp, stateProps, body, value)
{
if(bodyProp === 'state'){
Expand All @@ -154,17 +168,20 @@ class ObjectsPlugin extends PluginInterface

updateBulletBodyPosition(key, body)
{
if(!this.bullets[key]){
return;
}
this.bullets[key].x = body.x;
this.bullets[key].y = body.y;
this.events.emit('reldens.objectBodyChanged', {body, key});
}

updateObjectsAnimations(key, body, currentScene)
{
if(!sc.hasOwn(currentScene.objectsAnimations, key)){
let objectAnimation = sc.get(currentScene.objectsAnimations, key);
if(!objectAnimation){
return false;
}
let objectAnimation = currentScene.objectsAnimations[key];
objectAnimation.updateObjectAndSpritePositions(body.x, body.y);
this.events.emit('reldens.objectBodyChanged', {body, key});
let objectNewDepth = objectAnimation.updateObjectDepth();
Expand Down
24 changes: 12 additions & 12 deletions lib/rooms/client/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

const { ActionsConst } = require('../../actions/constants');
const { RoomsConst } = require('../constants');
const { PluginInterface } = require('../../features/plugin-interface');
const { Logger, sc } = require('@reldens/utils');

Expand Down Expand Up @@ -49,20 +50,22 @@ class RoomsPlugin extends PluginInterface
ActionsConst.SELECTORS.PLAYER_SELECTION_ADDITIONAL_INFO
);
if(!playerCreationAdditional && !playerSelectionAdditional){
Logger.warning('Missing element.', {playerCreationAdditional, playerSelectionAdditional});
return false;
}
let lastLocationLabel = gameManager.config.get('client/rooms/selection/loginLastLocationLabel');
if(playerCreationAdditional){
let creationRoomSelection = [...roomSelection];
let index = roomSelection.indexOf(lastLocationLabel);
let index = roomSelection.indexOf({
name: RoomsConst.ROOM_LAST_LOCATION_KEY,
title: gameManager.config.get('client/rooms/selection/loginLastLocationLabel')
});
if(-1 !== index){
creationRoomSelection.splice(index, 1);
roomSelection.splice(index, 1);
}
let div = this.createSelectorElements(gameManager, creationRoomSelection);
let div = this.createSelectorElements(gameManager, roomSelection);
playerCreationAdditional.append(div);
}
if(playerSelectionAdditional){
let div = this.createSelectorElements(gameManager, roomSelection, lastLocationLabel);
let div = this.createSelectorElements(gameManager, roomSelection);
playerSelectionAdditional.append(div);
}
}
Expand All @@ -80,7 +83,7 @@ class RoomsPlugin extends PluginInterface
gameManager.initialGameData.selectedScene = selectedScene;
}

createSelectorElements(gameManager, roomSelection, lastLocationLabel)
createSelectorElements(gameManager, roomSelection)
{
let div = gameManager.gameDom.createElement('div');
div.classList.add('input-box');
Expand All @@ -91,11 +94,8 @@ class RoomsPlugin extends PluginInterface
select.name = 'selectedScene';
select.classList.add('select-element');
select.classList.add('scene-select');
for(let roomName of roomSelection){
let option = new Option(roomName, roomName);
if(lastLocationLabel && roomName === lastLocationLabel){
option.value = '@lastLocation';
}
for(let roomData of roomSelection){
let option = new Option(roomData.title, roomData.name);
select.append(option);
}
div.append(label);
Expand Down
1 change: 1 addition & 0 deletions lib/rooms/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ module.exports.RoomsConst = {
TILE_INDEX: 'i',
NEXT_SCENE: 'n',
MAPS_BUCKET: '/assets/maps',
ROOM_LAST_LOCATION_KEY: '@lastLocation'
};
Loading

0 comments on commit a2d93b5

Please sign in to comment.