Rename Missions -> Zones, cleaned up zone classes
This commit is contained in:
parent
c46c74cb7e
commit
d041bcd9bb
@ -3,7 +3,7 @@ const Phaser = require('phaser');
|
|||||||
const Header = require('./header');
|
const Header = require('./header');
|
||||||
const Menu = require('./menu');
|
const Menu = require('./menu');
|
||||||
const Combat = require('./combat');
|
const Combat = require('./combat');
|
||||||
const Missions = require('./missions');
|
const Zones = require('./zones');
|
||||||
|
|
||||||
function renderCryps() {
|
function renderCryps() {
|
||||||
const config = {
|
const config = {
|
||||||
@ -38,7 +38,7 @@ function renderCryps() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (key === 'zone') {
|
if (key === 'zone') {
|
||||||
return game.scene.add('Missions', Missions, true, data);
|
return game.scene.add('Zones', Zones, true, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -122,7 +122,7 @@ class MenuGameList extends Phaser.Scene {
|
|||||||
});
|
});
|
||||||
|
|
||||||
zones.on('pointerdown', () => {
|
zones.on('pointerdown', () => {
|
||||||
if (this.scene.get('Missions')) return false;
|
if (this.scene.get('Zones')) return false;
|
||||||
return ws.sendAccountZone();
|
return ws.sendAccountZone();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -44,7 +44,7 @@ class Menu extends Phaser.Scene {
|
|||||||
this.registry.events.off('changedata', this.updateData, this);
|
this.registry.events.off('changedata', this.updateData, this);
|
||||||
this.registry.events.off('setdata', this.updateData, this);
|
this.registry.events.off('setdata', this.updateData, this);
|
||||||
|
|
||||||
const ACTIVE_SCENES = ['MenuCrypList', 'MenuGameList', 'ItemList', 'Missions', 'MissionsControls'];
|
const ACTIVE_SCENES = ['MenuCrypList', 'MenuGameList', 'ItemList', 'Zones'];
|
||||||
ACTIVE_SCENES.forEach((sKey) => {
|
ACTIVE_SCENES.forEach((sKey) => {
|
||||||
if (this.scene.get(sKey)) this.scene.get(sKey).cleanUp();
|
if (this.scene.get(sKey)) this.scene.get(sKey).cleanUp();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -5,15 +5,12 @@ const {
|
|||||||
POSITIONS: { GAME_LIST },
|
POSITIONS: { GAME_LIST },
|
||||||
} = require('./constants');
|
} = require('./constants');
|
||||||
|
|
||||||
class MissionsControls extends Phaser.Scene {
|
class ZoneControls extends Phaser.Scene {
|
||||||
constructor() {
|
constructor() {
|
||||||
super({ key: 'MissionsControls' });
|
super({ key: 'ZoneControls' });
|
||||||
}
|
}
|
||||||
|
|
||||||
create() {
|
create(zoneId) {
|
||||||
this.ws = this.registry.get('ws');
|
|
||||||
this.zone = this.registry.get('zone');
|
|
||||||
console.log(this.registry.get('account'));
|
|
||||||
const WIDTH = Math.floor(GAME_LIST.width() / 2);
|
const WIDTH = Math.floor(GAME_LIST.width() / 2);
|
||||||
const HEIGHT = GAME_LIST.height();
|
const HEIGHT = GAME_LIST.height();
|
||||||
|
|
||||||
@ -27,8 +24,8 @@ class MissionsControls extends Phaser.Scene {
|
|||||||
.setOrigin(0.5, 0.5);
|
.setOrigin(0.5, 0.5);
|
||||||
|
|
||||||
menu.on('pointerdown', () => {
|
menu.on('pointerdown', () => {
|
||||||
this.scene.get('Missions').cleanUp();
|
this.scene.get('Zones').cleanUp();
|
||||||
this.ws.sendZoneClose(this.zone.id);
|
this.registry.get('ws').sendZoneClose(zoneId);
|
||||||
this.cleanUp();
|
this.cleanUp();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -41,4 +38,4 @@ class MissionsControls extends Phaser.Scene {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = MissionsControls;
|
module.exports = ZoneControls;
|
||||||
@ -1,16 +1,16 @@
|
|||||||
const Phaser = require('phaser');
|
const Phaser = require('phaser');
|
||||||
|
|
||||||
class PassiveNode extends Phaser.GameObjects.Sprite {
|
class ZoneNode extends Phaser.GameObjects.Sprite {
|
||||||
constructor(scene, x, y, id, alloc, text) {
|
constructor(scene, x, y, id, success, tag) {
|
||||||
super(scene, x, y);
|
super(scene, x, y);
|
||||||
this.setTexture('eye');
|
this.setTexture('eye');
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
this.alloc = alloc;
|
this.success = success;
|
||||||
// this.text = (text.indexOf(',') > -1) ? text.split(',') : text;
|
// this.text = (text.indexOf(',') > -1) ? text.split(',') : text;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.setPosition(x, y);
|
this.setPosition(x, y);
|
||||||
|
|
||||||
const nodeNoDigits = text.replace(/[0-9]/g, '');
|
const nodeNoDigits = tag.replace(/[0-9]/g, '');
|
||||||
switch (nodeNoDigits) {
|
switch (nodeNoDigits) {
|
||||||
case 'BOSS':
|
case 'BOSS':
|
||||||
this.setScale(0.25);
|
this.setScale(0.25);
|
||||||
@ -21,12 +21,11 @@ class PassiveNode extends Phaser.GameObjects.Sprite {
|
|||||||
default:
|
default:
|
||||||
this.setScale(0.05);
|
this.setScale(0.05);
|
||||||
}
|
}
|
||||||
if (this.alloc) {
|
if (this.success) {
|
||||||
this.setTint(0xff0000);
|
this.setTint(0xff0000);
|
||||||
}
|
}
|
||||||
|
this.text = tag;
|
||||||
this.text = `${text}: id = '${id}`;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = PassiveNode;
|
module.exports = ZoneNode;
|
||||||
@ -1,14 +1,14 @@
|
|||||||
const Phaser = require('phaser');
|
const Phaser = require('phaser');
|
||||||
const Node = require('./missions.node');
|
const Node = require('./zone.node');
|
||||||
const MissionControls = require('./missions.controls');
|
const ZoneControls = require('./zone.controls');
|
||||||
const { POSITIONS: { COMBAT } } = require('./constants');
|
const { POSITIONS: { COMBAT } } = require('./constants');
|
||||||
|
|
||||||
// Mouse click hold to move, Q + E to zoom in and out
|
// Mouse click hold to move, Q + E to zoom in and out
|
||||||
// Press 'A' to reset allocated passive nodes
|
// Press 'A' to reset allocated passive nodes
|
||||||
|
|
||||||
class Missions extends Phaser.Scene {
|
class Zones extends Phaser.Scene {
|
||||||
constructor() {
|
constructor() {
|
||||||
super({ key: 'Missions' });
|
super({ key: 'Zones' });
|
||||||
}
|
}
|
||||||
|
|
||||||
preload() {
|
preload() {
|
||||||
@ -17,18 +17,14 @@ class Missions extends Phaser.Scene {
|
|||||||
|
|
||||||
create(zone) {
|
create(zone) {
|
||||||
if (!zone) return false;
|
if (!zone) return false;
|
||||||
console.log(zone);
|
this.scene.manager.add('ZoneControls', ZoneControls, true, zone.id);
|
||||||
|
|
||||||
this.scene.manager.add('MissionControls', MissionControls, true);
|
|
||||||
this.graphics = this.add.graphics();
|
this.graphics = this.add.graphics();
|
||||||
const nodeData = zone.graph.nodes;
|
|
||||||
this.edgeData = zone.graph.edges;
|
|
||||||
this.cameras.main.setViewport(COMBAT.width() * 0.2, COMBAT.y(),
|
this.cameras.main.setViewport(COMBAT.width() * 0.2, COMBAT.y(),
|
||||||
COMBAT.width() * 0.8, COMBAT.height());
|
COMBAT.width() * 0.8, COMBAT.height());
|
||||||
this.addNodes(nodeData);
|
this.addNodes(zone.graph.nodes);
|
||||||
this.drawEdges(nodeData);
|
this.drawEdges(zone.graph.edges);
|
||||||
this.addCameraControl();
|
this.addCameraControl();
|
||||||
this.addEvents();
|
this.addEvents(zone.id);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,18 +48,14 @@ class Missions extends Phaser.Scene {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addEvents() {
|
addEvents(zoneId) {
|
||||||
this.input.on('pointerover', (pointer, gameObjects) => {
|
this.input.on('pointerover', (pointer, gameObjects) => {
|
||||||
if (gameObjects[0] instanceof Node) {
|
if (gameObjects[0] instanceof Node) {
|
||||||
if (!gameObjects[0].alloc) {
|
|
||||||
gameObjects[0].setTint(0xffffff);
|
|
||||||
}
|
|
||||||
this.displayNodeText(gameObjects[0], pointer);
|
this.displayNodeText(gameObjects[0], pointer);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.input.on('pointerout', (pointer, gameObjects) => {
|
this.input.on('pointerout', (pointer, gameObjects) => {
|
||||||
if (gameObjects[0] instanceof Node) {
|
if (gameObjects[0] instanceof Node) {
|
||||||
if (!gameObjects[0].alloc) gameObjects[0].clearTint();
|
|
||||||
this.nodeText.destroy();
|
this.nodeText.destroy();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -75,12 +67,8 @@ class Missions extends Phaser.Scene {
|
|||||||
if (gameObjects[0] instanceof Node) {
|
if (gameObjects[0] instanceof Node) {
|
||||||
const team = this.registry.get('cryps').filter(c => c.active).map(c => c.id);
|
const team = this.registry.get('cryps').filter(c => c.active).map(c => c.id);
|
||||||
if (team.length === 0) return false;
|
if (team.length === 0) return false;
|
||||||
|
|
||||||
const zone = this.registry.get('zone');
|
|
||||||
// 'Boss' to be replaced with node id for RPC call
|
|
||||||
if (gameObjects[0].success) return false;
|
if (gameObjects[0].success) return false;
|
||||||
this.registry.get('ws').sendZoneJoin(zone.id, gameObjects[0].id, team);
|
this.registry.get('ws').sendZoneJoin(zoneId, gameObjects[0].id, team);
|
||||||
|
|
||||||
this.cleanUp();
|
this.cleanUp();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,24 +82,21 @@ class Missions extends Phaser.Scene {
|
|||||||
this.cameras.main.scrollY -= zoomFactor * (points[1].y - points[0].y);
|
this.cameras.main.scrollY -= zoomFactor * (points[1].y - points[0].y);
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
this.input.keyboard.on('keydown_G', () => {
|
|
||||||
this.scene.sleep();
|
|
||||||
}, 0, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
drawEdges() {
|
drawEdges(edgeData) {
|
||||||
this.graphics.clear();
|
this.graphics.clear();
|
||||||
this.edgeData.forEach((e) => {
|
edgeData.forEach((e) => {
|
||||||
const drawEdge = this.nodes.filter(n => (
|
const drawEdge = this.nodes.filter(n => (
|
||||||
e[0] === n.id || e[1] === n.id
|
e[0] === n.id || e[1] === n.id
|
||||||
));
|
));
|
||||||
if (drawEdge[0].success && drawEdge[1].success) {
|
const nodeA = this.nodes[drawEdge[0].id];
|
||||||
|
const nodeB = this.nodes[drawEdge[1].id];
|
||||||
|
if (nodeA.success && nodeB.success) {
|
||||||
this.graphics.lineStyle(10, 0xfff00f, 0.2);
|
this.graphics.lineStyle(10, 0xfff00f, 0.2);
|
||||||
} else {
|
} else {
|
||||||
this.graphics.lineStyle(2, 0xffffff, 0.2);
|
this.graphics.lineStyle(2, 0xffffff, 0.2);
|
||||||
}
|
}
|
||||||
const nodeA = this.nodes[drawEdge[0].id];
|
|
||||||
const nodeB = this.nodes[drawEdge[1].id];
|
|
||||||
this.graphics.lineBetween(nodeA.x, nodeA.y, nodeB.x, nodeB.y);
|
this.graphics.lineBetween(nodeA.x, nodeA.y, nodeB.x, nodeB.y);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@ -141,8 +126,9 @@ class Missions extends Phaser.Scene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanUp() {
|
cleanUp() {
|
||||||
|
this.scene.get('ZoneControls').cleanUp();
|
||||||
this.scene.remove();
|
this.scene.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Missions;
|
module.exports = Zones;
|
||||||
Loading…
x
Reference in New Issue
Block a user