Skip to content

Commit

Permalink
move loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Techbot committed May 17, 2024
1 parent b820e0f commit 9648425
Showing 1 changed file with 63 additions and 46 deletions.
109 changes: 63 additions & 46 deletions client/src/game/scenes/MainScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import axios from "axios";
import Player from "../entities/player";
import Messenger from "../entities/messenger";
import Rewards from "../entities/rewards";
import Load from "../entities/loader";
import Load from "../loaders/loader";
import Portals from "../entities/portals";
import Switches from "../entities/switches";
import NPCs from "../entities/npcs";
Expand Down Expand Up @@ -84,22 +84,22 @@ export class MainScene extends Phaser.Scene {

constructor() {
super({ key: "main" });
this.jigs = useJigsStore();
this.client = new Client(BACKEND_URL);
this.Portals = new Portals;
this.jigs = useJigsStore();
this.client = new Client(BACKEND_URL);
this.Portals = new Portals;
this.Switches = new Switches;
this.Walls = new Walls;
this.NPCs = new NPCs;
this.Mobs = new Mobs;
this.Rewards = new Rewards;
this.Folio = new Folios;
this.Walls = new Walls;
this.NPCs = new NPCs;
this.Mobs = new Mobs;
this.Rewards = new Rewards;
this.Folio = new Folios;
}

preload() {
var self = this;
// var self = this;
this.Loader = new Load;
this.messenger = new Messenger;
this.Loader.load(self);
this.Loader.load(this);
this.load.audio('walk', ['/assets/audio/thud.ogg', '/assets/audio/thud.mp3']);
this.load.image('nextPage', 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/assets/images/arrow-down-left.png');
this.load.addFile(new WebFont(this.load, ['Roboto', 'Neutron Demo']))
Expand All @@ -112,20 +112,36 @@ export class MainScene extends Phaser.Scene {
this.input.setDefaultCursor('url(/assets/images/cursors/blank.cur), pointer');
this.debugFPS = this.add.text(4, 4, "", { color: "#ff0000", });
// connect with the room
await this.connect(this.jigs.city + "-" + this.padding(this.jigs.tiled, 3, 0));
this.walkSound = this.sound.add('walk',{ volume: 0.3 });
this.soundtrack = this.sound.add(this.jigs.soundtrack, { volume: 0.6 });
// const room = await this.connect(this.jigs.city + "-" + this.padding(this.jigs.tiled, 3, 0));

// console.log("room" + room);

try {
const room = await this.connect(this.jigs.city + "-" + this.padding(this.jigs.tiled, 3, 0));
console.log("joined successfully " + this.room);
if (this.room == undefined) {
console.log("undefined room ");
this.scene.start('DeadScene');
return;
}
} catch (e) {
console.error("join error", e);
this.scene.start('SceneSelector');
}

this.walkSound = this.sound.add('walk', { volume: 0.03 });
this.soundtrack = this.sound.add(this.jigs.soundtrack, { volume: 0.06 });
this.soundtrack.play();
this.messenger.initMessages(self);
this.messenger.initMessages(this);

this.room.state.players.onAdd((player, sessionId) => {
this.localPlayer = new Player(this, this.room, player);
var entity: any;
// is current player
if (sessionId === this.room.sessionId) {
self.jigs.playerState = "alive";
this.jigs.playerState = "alive";
this.jigs.content = "City: " + this.jigs.city;
self.events.emit('content');
this.events.emit('content');
this.Rewards.add(this);
this.NPCs.add(this);
this.Mobs.add(this);
Expand Down Expand Up @@ -182,62 +198,62 @@ export class MainScene extends Phaser.Scene {
}

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.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.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"];
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"];
if (response.data[0].value["MapGrid"]["switchesArray"]) {
this.jigs.switchesArray = response.data[0].value["MapGrid"]["switchesArray"];
}


this.jigs.fireArray = response.data[0].value["MapGrid"]["fireArray"];
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"];
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.rewardsArray = response.data[0].value["MapGrid"]["rewardsArray"];
this.jigs.nodeTitle = response.data[0].value["MapGrid"]["name"];
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"];
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.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.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;
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);
// console.log(this.jigs.choice);
}


hydrateSwitches(response,id) {
hydrateSwitches(response, id) {
this.jigs.switchesArray.push(id);
//this.updatePhaser
}
Expand All @@ -250,8 +266,9 @@ export class MainScene extends Phaser.Scene {
.setPadding(4)
try {
this.room = await this.client.joinOrCreate(room,
{ playerId: this.jigs.playerId,
profileId: this.jigs.profileId,
{
playerId: this.jigs.playerId,
profileId: this.jigs.profileId,
});
// connection successful!
connectionStatusText.destroy();
Expand Down Expand Up @@ -283,7 +300,7 @@ export class MainScene extends Phaser.Scene {
}

if (this.jigs.mobArray != undefined) {
this.Mobs.updateMobs(this);
this.Mobs.updateMobs(this);
}

for (let sessionId in this.playerEntities) {
Expand Down

0 comments on commit 9648425

Please sign in to comment.