Rename Missions -> Zones, cleaned up zone classes

This commit is contained in:
Mashy 2018-12-30 15:14:14 +10:00
parent c46c74cb7e
commit d041bcd9bb
6 changed files with 34 additions and 52 deletions

View File

@ -3,7 +3,7 @@ const Phaser = require('phaser');
const Header = require('./header');
const Menu = require('./menu');
const Combat = require('./combat');
const Missions = require('./missions');
const Zones = require('./zones');
function renderCryps() {
const config = {
@ -38,7 +38,7 @@ function renderCryps() {
}
if (key === 'zone') {
return game.scene.add('Missions', Missions, true, data);
return game.scene.add('Zones', Zones, true, data);
}
return true;

View File

@ -122,7 +122,7 @@ class MenuGameList extends Phaser.Scene {
});
zones.on('pointerdown', () => {
if (this.scene.get('Missions')) return false;
if (this.scene.get('Zones')) return false;
return ws.sendAccountZone();
});

View File

@ -44,7 +44,7 @@ class Menu extends Phaser.Scene {
this.registry.events.off('changedata', 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) => {
if (this.scene.get(sKey)) this.scene.get(sKey).cleanUp();
});

View File

@ -5,15 +5,12 @@ const {
POSITIONS: { GAME_LIST },
} = require('./constants');
class MissionsControls extends Phaser.Scene {
class ZoneControls extends Phaser.Scene {
constructor() {
super({ key: 'MissionsControls' });
super({ key: 'ZoneControls' });
}
create() {
this.ws = this.registry.get('ws');
this.zone = this.registry.get('zone');
console.log(this.registry.get('account'));
create(zoneId) {
const WIDTH = Math.floor(GAME_LIST.width() / 2);
const HEIGHT = GAME_LIST.height();
@ -27,8 +24,8 @@ class MissionsControls extends Phaser.Scene {
.setOrigin(0.5, 0.5);
menu.on('pointerdown', () => {
this.scene.get('Missions').cleanUp();
this.ws.sendZoneClose(this.zone.id);
this.scene.get('Zones').cleanUp();
this.registry.get('ws').sendZoneClose(zoneId);
this.cleanUp();
});
@ -41,4 +38,4 @@ class MissionsControls extends Phaser.Scene {
}
}
module.exports = MissionsControls;
module.exports = ZoneControls;

View File

@ -1,16 +1,16 @@
const Phaser = require('phaser');
class PassiveNode extends Phaser.GameObjects.Sprite {
constructor(scene, x, y, id, alloc, text) {
class ZoneNode extends Phaser.GameObjects.Sprite {
constructor(scene, x, y, id, success, tag) {
super(scene, x, y);
this.setTexture('eye');
this.scene = scene;
this.alloc = alloc;
this.success = success;
// this.text = (text.indexOf(',') > -1) ? text.split(',') : text;
this.id = id;
this.setPosition(x, y);
const nodeNoDigits = text.replace(/[0-9]/g, '');
const nodeNoDigits = tag.replace(/[0-9]/g, '');
switch (nodeNoDigits) {
case 'BOSS':
this.setScale(0.25);
@ -21,12 +21,11 @@ class PassiveNode extends Phaser.GameObjects.Sprite {
default:
this.setScale(0.05);
}
if (this.alloc) {
if (this.success) {
this.setTint(0xff0000);
}
this.text = `${text}: id = '${id}`;
this.text = tag;
}
}
module.exports = PassiveNode;
module.exports = ZoneNode;

View File

@ -1,14 +1,14 @@
const Phaser = require('phaser');
const Node = require('./missions.node');
const MissionControls = require('./missions.controls');
const Node = require('./zone.node');
const ZoneControls = require('./zone.controls');
const { POSITIONS: { COMBAT } } = require('./constants');
// Mouse click hold to move, Q + E to zoom in and out
// Press 'A' to reset allocated passive nodes
class Missions extends Phaser.Scene {
class Zones extends Phaser.Scene {
constructor() {
super({ key: 'Missions' });
super({ key: 'Zones' });
}
preload() {
@ -17,18 +17,14 @@ class Missions extends Phaser.Scene {
create(zone) {
if (!zone) return false;
console.log(zone);
this.scene.manager.add('MissionControls', MissionControls, true);
this.scene.manager.add('ZoneControls', ZoneControls, true, zone.id);
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(),
COMBAT.width() * 0.8, COMBAT.height());
this.addNodes(nodeData);
this.drawEdges(nodeData);
this.addNodes(zone.graph.nodes);
this.drawEdges(zone.graph.edges);
this.addCameraControl();
this.addEvents();
this.addEvents(zone.id);
return this;
}
@ -52,18 +48,14 @@ class Missions extends Phaser.Scene {
});
}
addEvents() {
addEvents(zoneId) {
this.input.on('pointerover', (pointer, gameObjects) => {
if (gameObjects[0] instanceof Node) {
if (!gameObjects[0].alloc) {
gameObjects[0].setTint(0xffffff);
}
this.displayNodeText(gameObjects[0], pointer);
}
});
this.input.on('pointerout', (pointer, gameObjects) => {
if (gameObjects[0] instanceof Node) {
if (!gameObjects[0].alloc) gameObjects[0].clearTint();
this.nodeText.destroy();
}
});
@ -75,12 +67,8 @@ class Missions extends Phaser.Scene {
if (gameObjects[0] instanceof Node) {
const team = this.registry.get('cryps').filter(c => c.active).map(c => c.id);
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;
this.registry.get('ws').sendZoneJoin(zone.id, gameObjects[0].id, team);
this.registry.get('ws').sendZoneJoin(zoneId, gameObjects[0].id, team);
this.cleanUp();
}
}
@ -94,24 +82,21 @@ class Missions extends Phaser.Scene {
this.cameras.main.scrollY -= zoomFactor * (points[1].y - points[0].y);
}
}, this);
this.input.keyboard.on('keydown_G', () => {
this.scene.sleep();
}, 0, this);
}
drawEdges() {
drawEdges(edgeData) {
this.graphics.clear();
this.edgeData.forEach((e) => {
edgeData.forEach((e) => {
const drawEdge = this.nodes.filter(n => (
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);
} else {
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);
return true;
});
@ -141,8 +126,9 @@ class Missions extends Phaser.Scene {
}
cleanUp() {
this.scene.get('ZoneControls').cleanUp();
this.scene.remove();
}
}
module.exports = Missions;
module.exports = Zones;