Skip to content

Commit

Permalink
- Reldens - v4.0.0-beta.28
Browse files Browse the repository at this point in the history
- Merge pull request #226 from damian-pastorini/v4.0.0-beta.28
  • Loading branch information
damian-pastorini committed Oct 23, 2023
2 parents 8a46719 + 86bc455 commit 4810799
Show file tree
Hide file tree
Showing 61 changed files with 5,111 additions and 5,818 deletions.
3 changes: 2 additions & 1 deletion lib/actions/client/preloader-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ class PreloaderHandler
}
}

createWithMultipleDirections(uiScene, data, animDir) {
createWithMultipleDirections(uiScene, data, animDir)
{
// @TODO - BETA - Refactor and implement animDir = 1 (both): up_right, up_left, down_right,
// down_left.
uiScene.directionalAnimations[this.getAnimationKey(data)] = data.animationData.dir;
Expand Down
2 changes: 1 addition & 1 deletion lib/actions/client/receiver-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class ReceiverWrapper extends Receiver
hitSprite.setDepth(300000);
return hitSprite;
}
if (sc.hasOwn(targetSprite, 'targetSprite')) {
if(sc.hasOwn(targetSprite, 'targetSprite')){
targetSprite.moveSprites[hitAnimKey + '_' + targetSpriteId] = hitSprite;
}
let animData = allAnimations[hitAnimKey];
Expand Down
2 changes: 1 addition & 1 deletion lib/actions/server/pvp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

const { Battle } = require('./battle');
const { Logger } = require('@reldens/utils');
const {GameConst} = require("../../game/constants");
const { GameConst } = require('../../game/constants');

class Pvp extends Battle
{
Expand Down
3 changes: 2 additions & 1 deletion lib/actions/server/skills/type-physical-attack.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ class TypePhysicalAttack extends PhysicalAttack
removeBullet(body)
{
body.world.removeBodies.push(body);
delete this.room.state.bodies[this.key+'_bullet_'+body.id];
// @TODO - BETA - Refactor and extract Colyseus into a driver.
this.room.state.bodies.delete(this.key+'_bullet_'+body.id);
}

}
Expand Down
3 changes: 2 additions & 1 deletion lib/actions/server/skills/type-physical-effect.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ class TypePhysicalEffect extends PhysicalEffect
removeBullet(body)
{
body.world.removeBodies.push(body);
delete this.room.state.bodies[this.key+'_bullet_'+body.id];
// @TODO - BETA - Refactor and extract Colyseus into a driver.
this.room.state.bodies.delete(this.key+'_bullet_'+body.id);
}

}
Expand Down
8 changes: 4 additions & 4 deletions lib/ads/client/providers/crazy-games/banners-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,19 @@ class BannersHandler
position: '' === sc.get(activeAd.styles, 'position', '') ? activeAd.position : 'absolute'
};
let top = sc.get(activeAd.styles, 'top', null);
if (null !== top) {
if(null !== top){
styles.top = top;
}
let bottom = sc.get(activeAd.styles, 'bottom', null);
if (null !== bottom) {
if(null !== bottom){
styles.bottom = bottom;
}
let left = sc.get(activeAd.styles, 'left', null);
if (null !== left) {
if(null !== left){
styles.left = left;
}
let right = sc.get(activeAd.styles, 'right', null);
if (null !== right) {
if(null !== right){
styles.right = right;
}
return styles;
Expand Down
6 changes: 3 additions & 3 deletions lib/ads/client/providers/crazy-games/videos-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ class VideosHandler
this.isPlayingAd = false;
Logger.info('CrazyGames - Ad-finished callback.', (new Date()).getTime());
this.send({act: AdsConst.ACTIONS.AD_ENDED, ads_id: activeAd.id});
await this.gameManager.audioManager.changeMuteState(true);
await this.gameManager.audioManager.changeMuteState(false, false); // unmute and unlock audio
});
let adError = sc.get(activeAd, 'adErrorCallback', async (error) => {
this.isPlayingAd = false;
Logger.info('CrazyGames - Ad-error callback.', error, (new Date()).getTime());
this.send({act: AdsConst.ACTIONS.AD_ENDED, ads_id: activeAd.id, error});
await this.gameManager.audioManager.changeMuteState(true);
await this.gameManager.audioManager.changeMuteState(false, false); // unmute and unlock audio
});
let rewardItemKey = sc.get(activeAd, 'rewardItemKey', false);
let adType = rewardItemKey ? 'rewarded' : 'midgame';
await this.gameManager.audioManager.changeMuteState(false);
await this.gameManager.audioManager.changeMuteState(true, true); // mute and lock audio
await this.sdk.ad.requestAd(adType, {adStarted, adFinished, adError});
}

Expand Down
4 changes: 2 additions & 2 deletions lib/ads/client/providers/game-monetize.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class GameMonetize
async adStartedCallback(event)
{
this.isPlayingAd = true;
await this.gameManager.audioManager.changeMuteState(false);
await this.gameManager.audioManager.changeMuteState(true, true); // mute and lock audio
if(!this.activeAdBeenPlayed){
Logger.info('AdStartedCallback undefined activeAd.', event, this.activeAdBeenPlayed);
return false;
Expand All @@ -126,7 +126,7 @@ class GameMonetize
async adEndedCallback(event)
{
this.isPlayingAd = false;
await this.gameManager.audioManager.changeMuteState(true);
await this.gameManager.audioManager.changeMuteState(false, false); // unmute and unlock audio
if(!this.activeAdBeenPlayed){
Logger.info('AdEndedCallback undefined activeAd.', event, this.activeAdBeenPlayed);
return false;
Expand Down
2 changes: 1 addition & 1 deletion lib/ads/server/ads-type/event-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class EventVideo extends BaseAd
setVideoDataFromModel(adsModel)
{
let adsVideo = sc.get(adsModel, 'parent_event_video');
if (!adsVideo) {
if(!adsVideo){
Logger.warning('Parent video not provided on AdsModel for EventVideo.', adsModel);
return false;
}
Expand Down
68 changes: 53 additions & 15 deletions lib/audio/client/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class AudioManager
this.playerConfig = sc.get(props, 'playerConfig', {});
// @NOTE: it's important to add any been played audios here for the "changeMuteState" method.
this.playing = {};
this.currentMuteState = false;
this.changedMutedState = {};
this.lockedMuteState = false;
this.defaultAudioConfig = {
mute: false,
volume: 1,
Expand All @@ -36,6 +38,10 @@ class AudioManager

async setAudio(audioKey, enabled)
{
if(this.lockedMuteState){
Logger.info('Locked mute state to set audio.');
return false;
}
await this.events.emit('reldens.setAudio', {
audioManager: this,
categoryKey: audioKey,
Expand Down Expand Up @@ -341,24 +347,56 @@ class AudioManager
}
}

async changeMuteState(newMuteState)
async changeMuteState(newMuteState, newMuteLockState)
{
let playingKeys = Object.keys(this.playing);
if(0 === playingKeys.length){
let changedKeys = Object.keys(this.changedMutedState);
if(0 === changedKeys.length){
return false;
}
for(let id of changedKeys){
await this.setAudio(id, !this.changedMutedState[id]);
}
this.changedMutedState = {};
return true;
if(false === newMuteLockState){
this.lockedMuteState = false;
}
this.currentMuteState = newMuteState;
if(this.lockedMuteState && false !== newMuteLockState){
Logger.info('Locked mute state from changes.');
return false;
}
return newMuteState ? await this.muteCategories(newMuteLockState) : await this.restoreMute(newMuteLockState);
}

async muteCategories(newMuteLockState)
{
let categoriesKeys = Object.keys(this.categories);
if(0 < categoriesKeys.length){
Logger.info('Mute categories not found.');
return false;
}
for(let i of categoriesKeys){
this.changedMutedState[i] = this.currentMuteState;
await this.setAudio(i, false);
}
this.setMuteLock(newMuteLockState);
return true;
}

async restoreMute(newMuteLockState)
{
let changedKeys = Object.keys(this.changedMutedState);
if(0 === changedKeys.length){
this.setMuteLock(newMuteLockState);
return false;
}
for(let i of changedKeys){
await this.setAudio(i, true);
}
this.setMuteLock(newMuteLockState);
this.changedMutedState = {};
for(let i of playingKeys){
this.changedMutedState[i] = newMuteState;
await this.setAudio(i, newMuteState);
return true;
}

setMuteLock(newMuteLockState)
{
if(false === newMuteLockState){
this.lockedMuteState = false;
}
if(true === newMuteLockState){
this.lockedMuteState = true;
}
}

Expand Down
6 changes: 4 additions & 2 deletions lib/audio/client/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ class AudioPlugin extends PluginInterface
return false;
}
this.events.on('reldens.beforeCreateEngine', (initialGameData, gameManager) => {
gameManager.audioManager = new AudioManager({events: this.events});
this.initialAudiosData = sc.get(initialGameData, 'audio', {});
if(!gameManager.audioManager){
gameManager.audioManager = new AudioManager({events: this.events});
this.initialAudiosData = sc.get(initialGameData, 'audio', {});
}
});
this.events.on('reldens.joinedRoom', (room, gameManager) => {
gameManager.audioManager.updateDefaultConfig(
Expand Down
21 changes: 19 additions & 2 deletions lib/audio/client/scene-audio-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class SceneAudioPlayer
return false;
}
sceneDynamic['associatedAudio'] = audioManager.findAudio(sceneDynamic.key, sceneDynamic.key);

if(sceneDynamic['associatedAudio']){
this.playSpriteAudio(sceneDynamic['associatedAudio'], sceneDynamic.key, audioManager);
return sceneDynamic['associatedAudio'];
Expand Down Expand Up @@ -90,7 +89,7 @@ class SceneAudioPlayer
playSpriteAudio(associatedAudio, sceneKey, audioManager)
{
// @NOTE:
// - We need the status update from the actual category in the audio manager (the category associated to the
// - We need the status update from the actual category in the audio manager the category associated to the
// audio here is just the storage reference.
// - We need to check the category enable every time the audio could be reproduced because the user can turn
// the category on/off at any time.
Expand All @@ -115,6 +114,9 @@ class SceneAudioPlayer
// - if is single category then just in the playing property with that category key:
if(audioCategory.single_audio){
audioManager.playing[audioCategory.category_key] = audioInstance;
if(this.isMutedState(audioManager, audioCategory.category_key, audioInstance)){
return false;
}
audioInstance.mute = false;
audioInstance.play();
return true;
Expand All @@ -124,6 +126,9 @@ class SceneAudioPlayer
// - if it does not have a marker we save the audio instance under the tree category_key > audio_key:
if(!associatedAudio.marker){
audioManager.playing[audioCategory.category_key][associatedAudio.audio.data.audio_key] = audioInstance;
if(this.isMutedState(audioManager, audioCategory.category_key, audioInstance)){
return false;
}
// and play the audio:
audioInstance.mute = false;
audioInstance.play();
Expand All @@ -132,6 +137,9 @@ class SceneAudioPlayer
// - if it has a marker we save the audio instance under the tree category_key > marker_key:
if(associatedAudio.marker){
audioManager.playing[audioCategory.category_key][associatedAudio.marker] = audioInstance;
if(this.isMutedState(audioManager, audioCategory.category_key, audioInstance)){
return false;
}
// and play the audio passing the marker:
audioInstance.mute = false;
audioInstance.play(associatedAudio.marker);
Expand All @@ -140,6 +148,15 @@ class SceneAudioPlayer
}
}

isMutedState(audioManager, mutedKey, audioInstance)
{
if(false === audioManager.currentMuteState){
return false;
}
Logger.info('AudioManager in muted state to play audio.', {mutedKey, audioInstance});
audioManager.changedMutedState[mutedKey] = audioManager.currentMuteState;
return true;
}
}

module.exports.SceneAudioPlayer = new SceneAudioPlayer();
3 changes: 2 additions & 1 deletion lib/bundlers/drivers/parcel-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"data-url:*": ["...", "@parcel/optimizer-data-url"],
"*.css": ["@parcel/optimizer-css"],
"*.{html,xhtml}": ["@parcel/optimizer-htmlnano"],
"*.{js,mjs,cjs}": ["@parcel/optimizer-terser"],
"*.{js,mjs,cjs}": ["@parcel/optimizer-swc"],
"*.svg": ["@parcel/optimizer-svgo"],
"*.{jpg,jpeg,png}": ["@parcel/optimizer-image"]
},
Expand All @@ -66,6 +66,7 @@
"*.svg": "@parcel/packager-svg",
"*.{xml,rss,atom}": "@parcel/packager-xml",
"*.ts": "@parcel/packager-ts",
"*.wasm": "@parcel/packager-wasm",
"*.{jsonld,svg,webmanifest}": "@parcel/packager-raw-url",
"*": "@parcel/packager-raw"
},
Expand Down
2 changes: 1 addition & 1 deletion lib/chat/client/chat-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class ChatUi
let appendToMain = '' === messageType
? this.gameManager.gameDom.getElement(ChatConst.SELECTORS.CHAT_MESSAGES)
: false;
if(appendToMain) {
if(appendToMain){
appendToMain.innerHTML += output;
}
if(!appendToTab && !alsoShowInTab && !appendToMain){
Expand Down
2 changes: 1 addition & 1 deletion lib/chat/server/messages/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Validator
Logger.critical('Invalid message');
return false;
}
for(let prop of props) {
for(let prop of props){
if(!message[prop]){
Logger.critical('Missing message property: '+prop);
return false;
Expand Down
4 changes: 3 additions & 1 deletion lib/features/client/config-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const { TeamsPlugin } = require('../../teams/client/plugin');
const { RewardsPlugin } = require('../../rewards/client/plugin');
const { SnippetsPlugin } = require('../../snippets/client/plugin');
const { AdsPlugin } = require('../../ads/client/plugin');
const { WorldPlugin } = require('../../world/client/plugin');

module.exports.ClientCoreFeatures = {
chat: ChatPlugin,
Expand All @@ -33,5 +34,6 @@ module.exports.ClientCoreFeatures = {
teams: TeamsPlugin,
rewards: RewardsPlugin,
snippets: SnippetsPlugin,
ads: AdsPlugin
ads: AdsPlugin,
world: WorldPlugin
};
9 changes: 4 additions & 5 deletions lib/game/client/minimap-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ class MinimapUi
return false;
}
let box = scenePreloader.elementsUi['minimap'].getChildByProperty('id', 'minimap-ui');
// @TODO - BETA - Replace styles by classes.
box.style.display = 'none';
box.classList.add('hidden');
if(openButton){
openButton.style.display = 'block';
openButton.classList.remove('hidden');
}
minimap.minimapCamera.setVisible(false);
if(minimap.circle){
Expand All @@ -36,8 +35,8 @@ class MinimapUi
return false;
}
let box = scenePreloader.elementsUi['minimap'].getChildByProperty('id', 'minimap-ui');
box.style.display = 'block';
openButton.style.display = 'none';
box.classList.remove('hidden');
openButton.classList.add('hidden');
minimap.minimapCamera.setVisible(true);
if(minimap.circle){
minimap.circle.setVisible(true);
Expand Down
14 changes: 5 additions & 9 deletions lib/game/client/minimap.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*
*/

const { Display } = require('phaser');
const { sc } = require('@reldens/utils');

class Minimap
Expand Down Expand Up @@ -82,18 +81,15 @@ class Minimap

createRoundCamera(scene)
{
this.scope = scene.add.circle(
this.scope = scene.add.graphics();
this.scope.fillStyle(0x00ff00).fillCircle(
sc.get(this.config, 'circleX', 220),
sc.get(this.config, 'circleY', 88),
sc.get(this.config, 'circleRadio', 80.35),
sc.get(this.config, 'circleColor', 'rgb(0,0,0)'),
sc.get(this.config, 'circleAlpha', 1)
sc.get(this.config, 'circleRadio', 80.35)
);
this.scope.depth = sc.get(this.config, 'scopeDepth', 102);
this.minimapCamera.setMask(new Display.Masks.BitmapMask(scene, this.scope));
this.scope.visible = false;
this.minimapCamera.setMask(this.scope.createGeometryMask());
}

}

module.exports.Minimap = Minimap;
module.exports.Minimap = Minimap;
Loading

0 comments on commit 4810799

Please sign in to comment.