Skip to content

Commit

Permalink
Merge pull request #224 from Techbot/217-main-scene-create-and-add-ne…
Browse files Browse the repository at this point in the history
…w-hydrater-class

fixes #217 adds hrdater class with one extra function to be deleted
  • Loading branch information
Techbot authored Jul 2, 2024
2 parents 4837291 + b62f12d commit d30110f
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 8 deletions.
2 changes: 1 addition & 1 deletion client/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default {
this.room = new Room;
this.client = new Client(BACKEND_URL);
this.jigs = useJigsStore();
this.jigs.hydrateState(1);
// this.jigs.hydrateState(1);
},
methods: {
formSubmit(e) {
Expand Down
12 changes: 5 additions & 7 deletions client/src/game/scenes/MainScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ import { Room, Client } from "colyseus.js";
import { BACKEND_URL } from "../backend";
import { useJigsStore } from '../../stores/jigs';
import axios from "axios";

import Player from "../entities/player";
import Messenger from "../entities/messenger";
import Rewards from "../entities/rewards";
import Load from "../loaders/loader";
import Portals from "../entities/portals";
import Switches from "../entities/switches";
import NPCs from "../entities/npcs";
import Mobs from "../entities/mobs";
import Bosses from "../entities/bosses";
import Walls from "../entities/walls";
import Folios from "../entities/folios";
import Load from "../loaders/loader";
import Hydrater from '../../utils/hydrater';

export class MainScene extends Phaser.Scene {
room: Room;
Expand Down Expand Up @@ -83,6 +83,7 @@ export class MainScene extends Phaser.Scene {
Folio: Folios;
walkSound: Phaser.Sound.BaseSound;
soundtrack: Phaser.Sound.BaseSound;
hydrater: Hydrater;

constructor() {
super({ key: "main" });
Expand All @@ -96,6 +97,7 @@ export class MainScene extends Phaser.Scene {
this.Bosses = new Bosses;
this.Rewards = new Rewards;
this.Folio = new Folios;
this.hydrater = new Hydrater;
}

preload() {
Expand Down Expand Up @@ -137,7 +139,6 @@ export class MainScene extends Phaser.Scene {
this.soundtrack = this.sound.add(this.jigs.soundtrack, { volume: 0.06 });
this.soundtrack.play();
this.messenger.initMessages(this);

this.room.state.players.onAdd((player, sessionId) => {
this.localPlayer = new Player(this, this.room, player);
var entity: any;
Expand All @@ -155,9 +156,6 @@ export class MainScene extends Phaser.Scene {
this.Walls.add(this);
this.Folio.add(this);
this.localPlayer.add();



} else {
entity = this.physics.add.sprite(player.x, player.y, 'otherPlayer').setDepth(5).setScale(.85);
// listening for server updates
Expand Down Expand Up @@ -200,7 +198,7 @@ export class MainScene extends Phaser.Scene {
axios
.get("/mystate?_wrapper_format=drupal_ajax")
.then((response) => {
this.hydrate(response, 0);
this.hydrater.hydrate(response, 0);
})
}
}
Expand Down
137 changes: 137 additions & 0 deletions client/src/utils/hydrater.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/**
* ------- Htdrator ---------
*/
import Phaser from "phaser";
import { useJigsStore } from '../stores/jigs.ts';

export default class Hydrater {
jigs: any;

constructor() {
this.jigs = useJigsStore();
}

hydratePlayer(response) {
console.log("***************** mapgrid " + response.data[0].value["player"]["mapgrid"])
this.jigs.playerStats = response.data[0].value["player"];
this.jigs.health = response.data[0].value["health"];
this.jigs.energy = response.data[0].value["energy"];
//this.jigs.playerId = parseInt(response.data[0].value["player"]["id"]);
//this.profileId = parseInt(response.data[0].value["player"]["profileId"]);
//this.playerName = response.data[0].value["player"]["name"];
//this.playerSwitches = response.data[0].value["player"]["flickedSwitches"];
this.jigs.userMapGrid = response.data[0].value["player"]["mapgrid"];
//this.tiled = parseInt(response.data[0].value["MapGrid"]["tiled"]);
}

hydrateMap(response, incMob) {
// this.jigs.playerStats = response.data[0].value["player"];
// this.jigs.playerId = parseInt(response.data[0].value["player"]["id"]);
// this.jigs.profileId = parseInt(response.data[0].value["player"]["profileId"]);
// this.jigs.playerName = response.data[0].value["player"]["name"];
// this.jigs.gameState = response.data[0].value["player"]["userState"];
// this.jigs.userMapGrid = parseInt(response.data[0].value["player"]["userMG"]);

this.jigs.tiled = parseInt(response.data[0].value["MapGrid"]["tiled"]);
this.jigs.soundtrack = response.data[0].value["MapGrid"]["soundtrack"];
this.jigs.mapWidth = parseInt(response.data[0].value["MapGrid"]["mapWidth"]);
this.jigs.mapHeight = parseInt(response.data[0].value["MapGrid"]["mapHeight"]);
this.jigs.portalsArray = response.data[0].value["MapGrid"]["portalsArray"];

if (response.data[0].value["MapGrid"]["switchesArray"]) {
this.jigs.switchesArray = response.data[0].value["MapGrid"]["switchesArray"];
}

this.jigs.dialogueArray = response.data[0].value["MapGrid"]["dialogueArray"];
this.jigs.fireArray = response.data[0].value["MapGrid"]["fireArray"];
this.jigs.fireBarrelsArray = response.data[0].value["MapGrid"]["fireBarrelsArray"];
this.jigs.leverArray = response.data[0].value["MapGrid"]["leverArray"];
this.jigs.machineArray = response.data[0].value["MapGrid"]["machineArray"];
this.jigs.crystalArray = response.data[0].value["MapGrid"]["crystalArray"];
this.jigs.foliosArray = response.data[0].value["MapGrid"]["foliosArray"];
this.jigs.wallsArray = response.data[0].value["MapGrid"]["wallsArray"];
this.jigs.npcArray = response.data[0].value["MapGrid"]["npcArray"];
if (incMob) {
this.jigs.mobArray = response.data[0].value["MapGrid"]["mobArray"];
}
this.jigs.bossesArray = response.data[0].value["MapGrid"]["bossesArray"];

this.jigs.rewardsArray = response.data[0].value["MapGrid"]["rewardsArray"];
this.jigs.nodeTitle = response.data[0].value["MapGrid"]["name"];
this.jigs.tilesetArray_1 = response.data[0].value["MapGrid"]["tileset"]["tilesetArray_1"];
this.jigs.tilesetArray_2 = response.data[0].value["MapGrid"]["tileset"]["tilesetArray_2"];
this.jigs.tilesetArray_3 = response.data[0].value["MapGrid"]["tileset"]["tilesetArray_3"];
this.jigs.tilesetArray_4 = response.data[0].value["MapGrid"]["tileset"]["tilesetArray_4"];
this.jigs.city = response.data[0].value["City"];
// Regex replaces close/open p with \n new line
// And replaces all other html tags with null.
this.jigs.debug = parseInt(response.data[0].value["gameConfig"]["Debug"]);
this.jigs.content = response.data[0].value["gameConfig"]["Body"].replaceAll('</p><p>', '\n').replaceAll(/(<([^>]+)>)/ig, '');
}

hydrate(response, incMob) {
this.jigs.playerStats = response.data[0].value["player"];
this.jigs.playerId = parseInt(response.data[0].value["player"]["id"]);
this.jigs.profileId = parseInt(response.data[0].value["player"]["profileId"]);
this.jigs.playerName = response.data[0].value["player"]["name"];

//this.jigs.gameState = response.data[0].value["player"]["userState"];
this.jigs.userMapGrid = parseInt(response.data[0].value["player"]["userMG"]);

this.jigs.tiled = parseInt(response.data[0].value["MapGrid"]["tiled"]);
this.jigs.soundtrack = response.data[0].value["MapGrid"]["soundtrack"];
this.jigs.mapWidth = parseInt(response.data[0].value["MapGrid"]["mapWidth"]);
this.jigs.mapHeight = parseInt(response.data[0].value["MapGrid"]["mapHeight"]);
this.jigs.portalsArray = response.data[0].value["MapGrid"]["portalsArray"];

if (response.data[0].value["MapGrid"]["switchesArray"]) {
this.jigs.switchesArray = response.data[0].value["MapGrid"]["switchesArray"];
}

this.jigs.dialogueArray = response.data[0].value["MapGrid"]["dialogueArray"];
this.jigs.fireArray = response.data[0].value["MapGrid"]["fireArray"];
this.jigs.fireBarrelsArray = response.data[0].value["MapGrid"]["fireBarrelsArray"];
this.jigs.leverArray = response.data[0].value["MapGrid"]["leverArray"];
this.jigs.machineArray = response.data[0].value["MapGrid"]["machineArray"];
this.jigs.crystalArray = response.data[0].value["MapGrid"]["crystalArray"];
this.jigs.foliosArray = response.data[0].value["MapGrid"]["foliosArray"];
this.jigs.wallsArray = response.data[0].value["MapGrid"]["wallsArray"];
this.jigs.npcArray = response.data[0].value["MapGrid"]["npcArray"];
if (incMob) {
this.jigs.mobArray = response.data[0].value["MapGrid"]["mobArray"];
}
this.jigs.bossesArray = response.data[0].value["MapGrid"]["bossesArray"];

this.jigs.rewardsArray = response.data[0].value["MapGrid"]["rewardsArray"];
this.jigs.nodeTitle = response.data[0].value["MapGrid"]["name"];
this.jigs.tilesetArray_1 = response.data[0].value["MapGrid"]["tileset"]["tilesetArray_1"];
this.jigs.tilesetArray_2 = response.data[0].value["MapGrid"]["tileset"]["tilesetArray_2"];
this.jigs.tilesetArray_3 = response.data[0].value["MapGrid"]["tileset"]["tilesetArray_3"];
this.jigs.tilesetArray_4 = response.data[0].value["MapGrid"]["tileset"]["tilesetArray_4"];
this.jigs.city = response.data[0].value["City"];
// Regex replaces close/open p with \n new line
// And replaces all other html tags with null.
this.jigs.debug = parseInt(response.data[0].value["gameConfig"]["Debug"]);
this.jigs.content = response.data[0].value["gameConfig"]["Body"].replaceAll('</p><p>', '\n').replaceAll(/(<([^>]+)>)/ig, '');
}





hydrateMission(response) {
this.jigs.title = response.data[0].value["title"];
this.jigs.missionHandlerDialog = response.data[0].value["handler_dialog"];
let no = { text: 'No I am not ready.', value: 0 }
let yes = { text: response.data[0].value["choice"], value: response.data[0].value["value"] };
this.jigs.choice = new Array;
this.jigs.choice.push(yes);
this.jigs.choice.push(no);
// console.log(this.jigs.choice);
}

hydrateSwitches(response, id) {
this.jigs.switchesArray.push(id);
//this.updatePhaser
}
}

0 comments on commit d30110f

Please sign in to comment.