Temporary fix for compass showing wrong Y axis direction

This commit is contained in:
simon 2018-01-20 10:56:40 -05:00
parent 3ce8fba3cd
commit 859ba0237f
4 changed files with 63 additions and 72 deletions

View File

@ -259,7 +259,8 @@ class MarGame {
private initialiseStaticHud() {
this.game.add.sprite(0, this.game.camera.height - 150, "sheet", "ui/compass", this.hudGroup);
//todo fix the compass sprite so the Y axis is facing the other way
//this.game.add.sprite(0, this.game.camera.height - 150, "sheet", "ui/compass", this.hudGroup);
this.addDebugMessage(new WorldIndicator(10, 20));

View File

@ -1,17 +1,10 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({__proto__: []} instanceof Array && function (d, b) {
d.__proto__ = b;
}) ||
function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
};
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() {
this.constructor = d;
}
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
@ -219,7 +212,8 @@ var MarGame = /** @class */ (function () {
}
};
MarGame.prototype.initialiseStaticHud = function () {
this.game.add.sprite(0, this.game.camera.height - 150, "sheet", "ui/compass", this.hudGroup);
//todo fix the compass sprite so the Y axis is facing the other way
//this.game.add.sprite(0, this.game.camera.height - 150, "sheet", "ui/compass", this.hudGroup);
this.addDebugMessage(new WorldIndicator(10, 20));
this.tileIndicator = new TileIndicator(10, 40);
this.addDebugMessage(this.tileIndicator);
@ -349,9 +343,9 @@ var Util = /** @class */ (function () {
case Direction.WEST:
return 0;
case Direction.NORTH:
return 1;
case Direction.SOUTH:
return -1;
case Direction.SOUTH:
return 1;
}
};
return Util;
@ -560,33 +554,33 @@ var GameClient = /** @class */ (function () {
if (DEBUG) {
console.log("[MAR] Requesting user info");
}
this.socket.send(JSON.stringify({t: "userInfo"}));
this.socket.send(JSON.stringify({ t: "userInfo" }));
};
GameClient.prototype.requestTerrain = function () {
if (DEBUG) {
console.log("[MAR] Requesting terrain for world (" + this.worldX + ", " + this.worldY + ")");
}
this.socket.send(JSON.stringify({t: "terrain", x: this.worldX, y: this.worldY}));
this.socket.send(JSON.stringify({ t: "terrain", x: this.worldX, y: this.worldY }));
this.requestObjects();
};
GameClient.prototype.uploadCode = function (code) {
if (DEBUG) {
console.log("[MAR] Uploaded code");
}
this.socket.send(JSON.stringify({t: "uploadCode", code: code}));
this.socket.send(JSON.stringify({ t: "uploadCode", code: code }));
};
GameClient.prototype.reloadCode = function () {
if (DEBUG) {
console.log("[MAR] Reloading code");
}
this.socket.send(JSON.stringify({t: "codeRequest"}));
this.socket.send(JSON.stringify({ t: "codeRequest" }));
};
GameClient.prototype.sendKeyPress = function (key) {
if (DEBUG) {
console.log("[MAR] Sent KeyPress: " + key);
}
if (key !== 0) {
this.socket.send(JSON.stringify({t: "k", k: key}));
this.socket.send(JSON.stringify({ t: "k", k: key }));
}
};
GameClient.prototype.requestFloppy = function () {
@ -595,19 +589,19 @@ var GameClient = /** @class */ (function () {
if (DEBUG) {
console.log("[MAR] Requesting floppy");
}
this.socket.send(JSON.stringify({t: "floppyDown"}));
this.socket.send(JSON.stringify({ t: "floppyDown" }));
};
GameClient.prototype.notifyFloppyUp = function () {
if (DEBUG) {
console.log("[MAR] Notifying the game server of floppy upload");
}
this.socket.send(JSON.stringify({t: "floppyUp"}));
this.socket.send(JSON.stringify({ t: "floppyUp" }));
};
GameClient.prototype.requestObjects = function () {
if (DEBUG) {
console.log("[MAR] Requesting game objects");
}
this.socket.send(JSON.stringify({t: "object", x: this.worldX, y: this.worldY}));
this.socket.send(JSON.stringify({ t: "object", x: this.worldX, y: this.worldY }));
};
/**
* Get server info from game website
@ -673,7 +667,7 @@ var GameClient = /** @class */ (function () {
if (DEBUG) {
console.log("[MAR] Received invalid message, assuming floppy data");
document.getElementById("floppyDown").innerHTML = "<i class=\"fa fa-long-arrow-down\" aria-hidden=\"true\"></i> <i class=\"fa fa-floppy-o\" aria-hidden=\"true\"></i>";
var blob = new Blob([received.data], {type: "application/octet-stream"});
var blob = new Blob([received.data], { type: "application/octet-stream" });
saveAs(blob, "floppy.bin");
}
}
@ -844,8 +838,8 @@ var Cubot = /** @class */ (function (_super) {
return _this;
}
Cubot.prototype.onTileHover = function () {
mar.game.add.tween(this).to({isoZ: 45}, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this.scale).to({x: 1.2, y: 1.2}, 200, Phaser.Easing.Linear.None, true);
mar.game.add.tween(this).to({ isoZ: 45 }, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this.scale).to({ x: 1.2, y: 1.2 }, 200, Phaser.Easing.Linear.None, true);
this.tint = config.cubotHoverTint;
if (this.text !== undefined) {
this.text.visible = true;
@ -853,8 +847,8 @@ var Cubot = /** @class */ (function (_super) {
this.hovered = true;
};
Cubot.prototype.onTileExit = function () {
mar.game.add.tween(this).to({isoZ: 15}, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({x: 1, y: 1}, 200, Phaser.Easing.Linear.None, true);
mar.game.add.tween(this).to({ isoZ: 15 }, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({ x: 1, y: 1 }, 200, Phaser.Easing.Linear.None, true);
if (this.text !== undefined) {
this.text.visible = false;
}
@ -968,10 +962,7 @@ var Cubot = /** @class */ (function (_super) {
var self = this;
var walkAnimation = function (duration) {
//Move the Cubot to desired tile
var tween = mar.game.add.tween(self).to({
isoX: Util.getIsoX(self.tileX),
isoY: Util.getIsoY(self.tileY)
}, duration, Phaser.Easing.Linear.None, true);
var tween = mar.game.add.tween(self).to({ isoX: Util.getIsoX(self.tileX), isoY: Util.getIsoY(self.tileY) }, duration, Phaser.Easing.Linear.None, true);
//Play appropriate animation
switch (self.direction) {
case Direction.NORTH:
@ -1116,15 +1107,15 @@ var BiomassBlob = /** @class */ (function (_super) {
}
BiomassBlob.prototype.onTileHover = function () {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 45}, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this).to({ isoZ: 45 }, 200, Phaser.Easing.Quadratic.InOut, true);
this.tint = config.biomassHoverTint;
mar.game.add.tween(this.scale).to({x: 1.2, y: 1.2}, 200, Phaser.Easing.Linear.None, true);
mar.game.add.tween(this.scale).to({ x: 1.2, y: 1.2 }, 200, Phaser.Easing.Linear.None, true);
this.text.visible = true;
};
BiomassBlob.prototype.onTileExit = function () {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 15}, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({x: 1, y: 1}, 200, Phaser.Easing.Linear.None, true);
mar.game.add.tween(this).to({ isoZ: 15 }, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({ x: 1, y: 1 }, 200, Phaser.Easing.Linear.None, true);
this.tint = config.biomassTint;
this.text.visible = false;
};
@ -1149,15 +1140,15 @@ var Factory = /** @class */ (function (_super) {
}
Factory.prototype.onTileHover = function () {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 25}, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this.scale).to({x: 1.06, y: 1.06}, 200, Phaser.Easing.Linear.None, true);
mar.game.add.tween(this).to({ isoZ: 25 }, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this.scale).to({ x: 1.06, y: 1.06 }, 200, Phaser.Easing.Linear.None, true);
this.tint = config.cubotHoverTint;
this.text.visible = true;
};
Factory.prototype.onTileExit = function () {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 15}, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({x: 1, y: 1}, 200, Phaser.Easing.Linear.None, true);
mar.game.add.tween(this).to({ isoZ: 15 }, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({ x: 1, y: 1 }, 200, Phaser.Easing.Linear.None, true);
this.tint = config.cubotTint;
this.text.visible = false;
};
@ -1185,15 +1176,15 @@ var RadioTower = /** @class */ (function (_super) {
}
RadioTower.prototype.onTileHover = function () {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 25}, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this.scale).to({x: 1.06, y: 1.06}, 200, Phaser.Easing.Linear.None, true);
mar.game.add.tween(this).to({ isoZ: 25 }, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this.scale).to({ x: 1.06, y: 1.06 }, 200, Phaser.Easing.Linear.None, true);
this.tint = config.cubotHoverTint;
this.text.visible = true;
};
RadioTower.prototype.onTileExit = function () {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 15}, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({x: 1, y: 1}, 200, Phaser.Easing.Linear.None, true);
mar.game.add.tween(this).to({ isoZ: 15 }, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({ x: 1, y: 1 }, 200, Phaser.Easing.Linear.None, true);
this.tint = config.cubotTint;
this.text.visible = false;
};
@ -1216,15 +1207,15 @@ var VaultDoor = /** @class */ (function (_super) {
}
VaultDoor.prototype.onTileHover = function () {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 25}, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this.scale).to({x: 1.06, y: 1.06}, 200, Phaser.Easing.Linear.None, true);
mar.game.add.tween(this).to({ isoZ: 25 }, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this.scale).to({ x: 1.06, y: 1.06 }, 200, Phaser.Easing.Linear.None, true);
this.tint = config.cubotHoverTint;
this.text.visible = true;
};
VaultDoor.prototype.onTileExit = function () {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 15}, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({x: 1, y: 1}, 200, Phaser.Easing.Linear.None, true);
mar.game.add.tween(this).to({ isoZ: 15 }, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({ x: 1, y: 1 }, 200, Phaser.Easing.Linear.None, true);
this.tint = config.cubotTint;
this.text.visible = false;
};
@ -1277,14 +1268,14 @@ var Tile = /** @class */ (function (_super) {
};
Tile.prototype.onHover = function () {
this.tint = config.tileHoverTint;
mar.game.add.tween(this).to({isoZ: this.baseZ + 8}, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this).to({ isoZ: this.baseZ + 8 }, 200, Phaser.Easing.Quadratic.InOut, true);
mar.tileIndicator.tileX = this.tileX;
mar.tileIndicator.tileY = this.tileY;
mar.tileIndicator.tileType = this.tileType;
};
Tile.prototype.onExit = function () {
this.tint = this.baseTint;
mar.game.add.tween(this).to({isoZ: this.baseZ}, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this).to({ isoZ: this.baseZ }, 200, Phaser.Easing.Quadratic.InOut, true);
};
Tile.prototype.setText = function (text, fillColor) {
//Remove previous text

41
mar/app.min.js vendored
View File

@ -14,27 +14,26 @@ a.debugMessages[c].x,a.debugMessages[c].y)}};this.game.state.add("Boot",this.boo
this.animationFrames.harvester_walk_n_start=[];for(a=0;10>a;a++)this.animationFrames.harvester_walk_n_start.push("harvester/walk_n/"+("0000"+a).slice(-4));this.animationFrames.harvester_walk_n=[];for(a=10;30>a;a++)this.animationFrames.harvester_walk_n.push("harvester/walk_n/"+("0000"+a).slice(-4));this.animationFrames.walk_s_start=[];for(a=0;10>a;a++)this.animationFrames.walk_s_start.push("cubot/walk_s/"+("0000"+a).slice(-4));this.animationFrames.walk_s=[];for(a=10;30>a;a++)this.animationFrames.walk_s.push("cubot/walk_s/"+
("0000"+a).slice(-4));this.animationFrames.harvester_walk_s_start=[];for(a=0;10>a;a++)this.animationFrames.harvester_walk_s_start.push("harvester/walk_s/"+("0000"+a).slice(-4));this.animationFrames.harvester_walk_s=[];for(a=10;30>a;a++)this.animationFrames.harvester_walk_s.push("harvester/walk_s/"+("0000"+a).slice(-4));this.animationFrames.walk_w_start=[];for(a=0;10>a;a++)this.animationFrames.walk_w_start.push("cubot/walk_w/"+("0000"+a).slice(-4));this.animationFrames.walk_w=[];for(a=10;30>a;a++)this.animationFrames.walk_w.push("cubot/walk_w/"+
("0000"+a).slice(-4));this.animationFrames.harvester_walk_w_start=[];for(a=0;10>a;a++)this.animationFrames.harvester_walk_w_start.push("harvester/walk_w/"+("0000"+a).slice(-4));this.animationFrames.harvester_walk_w=[];for(a=10;30>a;a++)this.animationFrames.harvester_walk_w.push("harvester/walk_w/"+("0000"+a).slice(-4));this.animationFrames.dig_e=[];for(a=1;41>=a;a++)this.animationFrames.dig_e.push("cubot/dig_e/"+("0000"+a).slice(-4));this.animationFrames.dig_n=[];for(a=1;41>=a;a++)this.animationFrames.dig_n.push("cubot/dig_n/"+
("0000"+a).slice(-4));this.animationFrames.dig_s=[];for(a=1;41>=a;a++)this.animationFrames.dig_s.push("cubot/dig_s/"+("0000"+a).slice(-4));this.animationFrames.dig_w=[];for(a=1;41>=a;a++)this.animationFrames.dig_w.push("cubot/dig_w/"+("0000"+a).slice(-4));this.animationFrames.biomassIdle=[];for(a=1;60>a;a++)this.animationFrames.biomassIdle.push("objects/biomass/idle/"+("0000"+a).slice(-4))};b.prototype.initialiseStaticHud=function(){this.game.add.sprite(0,this.game.camera.height-150,"sheet","ui/compass",
this.hudGroup);this.addDebugMessage(new WorldIndicator(10,20));this.tileIndicator=new TileIndicator(10,40);this.addDebugMessage(this.tileIndicator)};return b}(),DebugMessage=function(){return function(b,a){this.x=b;this.y=a}}(),TileIndicator=function(b){function a(){return null!==b&&b.apply(this,arguments)||this}__extends(a,b);a.prototype.getMessage=function(){return void 0!=this.tileType?this.tileX+", "+this.tileY+" : "+this.tileType:""};return a}(DebugMessage),WorldIndicator=function(b){function a(){return null!==
b&&b.apply(this,arguments)||this}__extends(a,b);a.prototype.getMessage=function(){return void 0!=mar.world?"World: ("+Number(mar.client.worldX).toString(16).toUpperCase()+", "+Number(mar.client.worldY).toString(16).toUpperCase()+")":"Loading..."};return a}(DebugMessage),RENDERER_WIDTH=document.getElementById("game").clientWidth*window.devicePixelRatio,RENDERER_HEIGHT=window.innerHeight/1.4*window.devicePixelRatio,DEBUG=!0,config={tileTint:16777215,wallTint:14540253,oreTint:15987699,cubotHoverTint:65280,
cubotTint:16777215,textFill:"#FFFFFF",textStroke:"#9298a8",biomassTint:6535263,biomassHoverTint:65280,tileHoverTint:65280,itemIron:4408129,textIron:"#434341",itemCopper:13139256,textCopper:"#C87D38",hologramFill:"#0aced6",hologramStroke:"#12FFB0",copperFill:"#C87D38",plainSprite:"tiles/tile",wallSprite:"tiles/bigTile",walkDuration:800,holoStyle:function(b){return{fontSize:32,fill:b?b:config.hologramFill,stroke:config.hologramStroke,strokeThickness:1,font:"fixedsys"}},kbBufferX:225,kbBufferY:20,arrowTextStyle:{fontSize:32,
fill:"#ffffff",stroke:"#9298a8",strokeThickness:1,font:"fixedsys"},lowEnergy:100,lowEnergyTint:13369344,bigMessageFill:"#ff803d",arrowTint:16777215,arrowHoverTint:65280,selfUsernameColor:16469258,otherCubotAlpha:.6,defaultWorldSize:16},Util=function(){function b(){}b.getIsoY=function(a){return b.getIsoX(a)};b.getIsoX=function(a){return 71.5*a};b.getDeltaX=function(a){switch(a){case Direction.NORTH:case Direction.SOUTH:return 0;case Direction.EAST:return 1;case Direction.WEST:return-1}};b.getDeltaY=
function(a){switch(a){case Direction.EAST:case Direction.WEST:return 0;case Direction.NORTH:return 1;case Direction.SOUTH:return-1}};return b}(),mar=new MarGame,myVarX=.46,myVarY=.46,KeyboardBuffer=function(b){function a(){var a=null!==b&&b.apply(this,arguments)||this;a.keys=[];return a}__extends(a,b);a.prototype.getMessage=function(){for(var a="KB: ",b=0;16>b;b++)a=void 0!==this.keys[b]?a+(this.keys[b].toString(16).toUpperCase()+" "):a+"__ ";return a};return a}(DebugMessage),ObjectsListener=function(){function b(){}
b.prototype.getListenedMessageType=function(){return"object"};b.prototype.handle=function(a){DEBUG&&console.log("[MAR] Received "+a.objects.length+" objects");void 0!=mar.world&&mar.world.handleObjectsUpdate(a.objects)};return b}(),TickListener=function(){function b(){}b.prototype.getListenedMessageType=function(){return"tick"};b.prototype.handle=function(a){mar.client.requestObjects();void 0!==a.keys&&(mar.client.keyboardBuffer.keys=a.keys);void 0!=a.c&&(mar.client.consoleScreen.handleConsoleBufferUpdate(a.c,
a.cm),DEBUG&&console.log("[MAR] Received "+a.c.length+" console message(s)"))};return b}(),UserInfoListener=function(){function b(){}b.prototype.getListenedMessageType=function(){return"userInfo"};b.prototype.handle=function(a){DEBUG&&console.log("[MAR] Received user info message");mar.client.worldX=a.worldX;mar.client.worldY=a.worldY;mar.client.maxWidth=a.maxWidth;mar.client.requestTerrain()};return b}(),AuthListener=function(){function b(){}b.prototype.getListenedMessageType=function(){return"auth"};
b.prototype.handle=function(a){DEBUG&&console.log("[MAR] Received auth response");"ok"===a.m?(DEBUG&&console.log("[MAR] Auth successful"),mar.client.requestUserInfo()):alert("Authentication failed. Please make sure you are logged in and reload the page.")};return b}(),TerrainListener=function(){function b(){}b.prototype.getListenedMessageType=function(){return"terrain"};b.prototype.handle=function(a){DEBUG&&console.log("[MAR] Received terrain");mar.world&&mar.world.removeBigMessage();if(a.ok){var c=
a.size;void 0==c&&(c=config.defaultWorldSize);DEBUG&&console.log("[MAR] World is available");null!=mar.world?(DEBUG&&console.log("[MAR] Updating World terrain"),mar.world.updateTerrain(a.terrain,c)):(DEBUG&&console.log("[MAR] Creating new World"),mar.world=new World(a.terrain,c))}else DEBUG&&console.log("[MAR] World is not available"),null!=mar.world?(DEBUG&&console.log("[MAR] Updating World terrain"),mar.world.updateTerrain([],config.defaultWorldSize)):(DEBUG&&console.log("[MAR] Creating new World"),
mar.world=new World([],config.defaultWorldSize)),mar.world&&mar.world.setBigMessage("[Uncharted World]")};return b}(),CodeListener=function(){function b(){}b.prototype.getListenedMessageType=function(){return"code"};b.prototype.handle=function(a){ace.edit("editor").setValue(a.code)};return b}(),CodeResponseListener=function(){function b(){}b.prototype.getListenedMessageType=function(){return"codeResponse"};b.prototype.handle=function(a){alert("Uploaded and assembled "+a.bytes+" bytes ("+a.exceptions+
" errors)")};return b}(),GameClient=function(){function b(){this.listeners=[];this.getServerInfo();this.consoleScreen=new PlainTextConsole(defaultText,"consoleText","colorButton","scrollButton","resetButton","widthDial")}b.prototype.requestUserInfo=function(){DEBUG&&console.log("[MAR] Requesting user info");this.socket.send(JSON.stringify({t:"userInfo"}))};b.prototype.requestTerrain=function(){DEBUG&&console.log("[MAR] Requesting terrain for world ("+this.worldX+", "+this.worldY+")");this.socket.send(JSON.stringify({t:"terrain",
x:this.worldX,y:this.worldY}));this.requestObjects()};b.prototype.uploadCode=function(a){DEBUG&&console.log("[MAR] Uploaded code");this.socket.send(JSON.stringify({t:"uploadCode",code:a}))};b.prototype.reloadCode=function(){DEBUG&&console.log("[MAR] Reloading code");this.socket.send(JSON.stringify({t:"codeRequest"}))};b.prototype.sendKeyPress=function(a){DEBUG&&console.log("[MAR] Sent KeyPress: "+a);0!==a&&this.socket.send(JSON.stringify({t:"k",k:a}))};b.prototype.requestFloppy=function(){document.getElementById("floppyDown").innerHTML=
'<i class="fa fa-cog fa-spin fa-fw"></i>';DEBUG&&console.log("[MAR] Requesting floppy");this.socket.send(JSON.stringify({t:"floppyDown"}))};b.prototype.notifyFloppyUp=function(){DEBUG&&console.log("[MAR] Notifying the game server of floppy upload");this.socket.send(JSON.stringify({t:"floppyUp"}))};b.prototype.requestObjects=function(){DEBUG&&console.log("[MAR] Requesting game objects");this.socket.send(JSON.stringify({t:"object",x:this.worldX,y:this.worldY}))};b.prototype.getServerInfo=function(){var a=
this;DEBUG&&console.log("[MAR] Getting server info... ");var c=new XMLHttpRequest;c.open("GET","./getServerInfo.php",!0);c.onreadystatechange=function(){4===c.readyState&&200===c.status&&(DEBUG&&console.log("[MAR] Received server info "+c.responseText),setTimeout(a.connectToGameServer(JSON.parse(c.responseText)),100))};c.send(null)};b.prototype.connectToGameServer=function(a){var c=this;DEBUG&&console.log("[MAR] Connecting to "+a.address);this.socket=new WebSocket(a.address);this.username=a.username;
this.tickLength=a.tickLength;this.serverName=a.serverName;this.socket.binaryType="arraybuffer";this.socket.onopen=function(){DEBUG&&console.log("[MAR] Connected. Sent auth request");c.socket.send(a.token);c.listeners.push(new UserInfoListener);c.listeners.push(new AuthListener);c.listeners.push(new TickListener);c.listeners.push(new TerrainListener);c.listeners.push(new ObjectsListener);c.listeners.push(new CodeResponseListener);c.listeners.push(new CodeListener);c.socket.onmessage=function(a){try{var b=
JSON.parse(a.data);DEBUG&&console.log("[MAR] Received: "+a.data);for(var d=0;d<c.listeners.length;d++)c.listeners[d].getListenedMessageType()===b.t&&c.listeners[d].handle(b)}catch(h){DEBUG&&(console.log("[MAR] Received invalid message, assuming floppy data"),document.getElementById("floppyDown").innerHTML='<i class="fa fa-long-arrow-down" aria-hidden="true"></i> <i class="fa fa-floppy-o" aria-hidden="true"></i>',a=new Blob([a.data],{type:"application/octet-stream"}),saveAs(a,"floppy.bin"))}};c.reloadCode()};
this.socket.onerror=function(c){alert("Can't connect to game server at address "+a.address);console.log(c)};this.socket.onclose=function(a){mar.world.setBigMessage("Disconnected from server :(");console.log(a)};this.initGame()};b.prototype.initGame=function(){if("guest"!=this.username){var a=this;this.keyboardBuffer=new KeyboardBuffer(config.kbBufferX,config.kbBufferY);mar.addDebugMessage(this.keyboardBuffer);mar.game.input.keyboard.onDownCallback=function(c){document.activeElement===document.getElementById("game")&&
((37<=c.keyCode&&40>=c.keyCode||116===c.keyCode||32===c.keyCode)&&c.preventDefault(),"guest"!==a.username&&16>=a.keyboardBuffer.keys.length&&(a.sendKeyPress(c.keyCode),a.keyboardBuffer.keys.push(c.keyCode)))}}};b.prototype.findMyRobot=function(){"guest"==this.username?alert("You are not logged in!"):this.requestUserInfo()};return b}(),ObjectType;
(function(b){b[b.CUBOT=1]="CUBOT";b[b.BIOMASS=2]="BIOMASS";b[b.HARVESTER_NPC=10]="HARVESTER_NPC";b[b.FACTORY=3]="FACTORY";b[b.RADIO_TOWER=4]="RADIO_TOWER";b[b.VAULT_DOOR=5]="VAULT_DOOR"})(ObjectType||(ObjectType={}));var ItemType;(function(b){b[b.BIOMASS=1]="BIOMASS";b[b.IRON=3]="IRON";b[b.COPPER=4]="COPPER"})(ItemType||(ItemType={}));var Action;
(function(b){b[b.IDLE=0]="IDLE";b[b.DIGGING=1]="DIGGING";b[b.WALKING=2]="WALKING";b[b.WITHDRAWING=3]="WITHDRAWING";b[b.DEPOSITING=4]="DEPOSITING";b[b.LISTENING=5]="LISTENING";b[b.JUMPING=6]="JUMPING"})(Action||(Action={}));
("0000"+a).slice(-4));this.animationFrames.dig_s=[];for(a=1;41>=a;a++)this.animationFrames.dig_s.push("cubot/dig_s/"+("0000"+a).slice(-4));this.animationFrames.dig_w=[];for(a=1;41>=a;a++)this.animationFrames.dig_w.push("cubot/dig_w/"+("0000"+a).slice(-4));this.animationFrames.biomassIdle=[];for(a=1;60>a;a++)this.animationFrames.biomassIdle.push("objects/biomass/idle/"+("0000"+a).slice(-4))};b.prototype.initialiseStaticHud=function(){this.addDebugMessage(new WorldIndicator(10,20));this.tileIndicator=
new TileIndicator(10,40);this.addDebugMessage(this.tileIndicator)};return b}(),DebugMessage=function(){return function(b,a){this.x=b;this.y=a}}(),TileIndicator=function(b){function a(){return null!==b&&b.apply(this,arguments)||this}__extends(a,b);a.prototype.getMessage=function(){return void 0!=this.tileType?this.tileX+", "+this.tileY+" : "+this.tileType:""};return a}(DebugMessage),WorldIndicator=function(b){function a(){return null!==b&&b.apply(this,arguments)||this}__extends(a,b);a.prototype.getMessage=
function(){return void 0!=mar.world?"World: ("+Number(mar.client.worldX).toString(16).toUpperCase()+", "+Number(mar.client.worldY).toString(16).toUpperCase()+")":"Loading..."};return a}(DebugMessage),RENDERER_WIDTH=document.getElementById("game").clientWidth*window.devicePixelRatio,RENDERER_HEIGHT=window.innerHeight/1.4*window.devicePixelRatio,DEBUG=!0,config={tileTint:16777215,wallTint:14540253,oreTint:15987699,cubotHoverTint:65280,cubotTint:16777215,textFill:"#FFFFFF",textStroke:"#9298a8",biomassTint:6535263,
biomassHoverTint:65280,tileHoverTint:65280,itemIron:4408129,textIron:"#434341",itemCopper:13139256,textCopper:"#C87D38",hologramFill:"#0aced6",hologramStroke:"#12FFB0",copperFill:"#C87D38",plainSprite:"tiles/tile",wallSprite:"tiles/bigTile",walkDuration:800,holoStyle:function(b){return{fontSize:32,fill:b?b:config.hologramFill,stroke:config.hologramStroke,strokeThickness:1,font:"fixedsys"}},kbBufferX:225,kbBufferY:20,arrowTextStyle:{fontSize:32,fill:"#ffffff",stroke:"#9298a8",strokeThickness:1,font:"fixedsys"},
lowEnergy:100,lowEnergyTint:13369344,bigMessageFill:"#ff803d",arrowTint:16777215,arrowHoverTint:65280,selfUsernameColor:16469258,otherCubotAlpha:.6,defaultWorldSize:16},Util=function(){function b(){}b.getIsoY=function(a){return b.getIsoX(a)};b.getIsoX=function(a){return 71.5*a};b.getDeltaX=function(a){switch(a){case Direction.NORTH:case Direction.SOUTH:return 0;case Direction.EAST:return 1;case Direction.WEST:return-1}};b.getDeltaY=function(a){switch(a){case Direction.EAST:case Direction.WEST:return 0;
case Direction.NORTH:return-1;case Direction.SOUTH:return 1}};return b}(),mar=new MarGame,myVarX=.46,myVarY=.46,KeyboardBuffer=function(b){function a(){var a=null!==b&&b.apply(this,arguments)||this;a.keys=[];return a}__extends(a,b);a.prototype.getMessage=function(){for(var a="KB: ",b=0;16>b;b++)a=void 0!==this.keys[b]?a+(this.keys[b].toString(16).toUpperCase()+" "):a+"__ ";return a};return a}(DebugMessage),ObjectsListener=function(){function b(){}b.prototype.getListenedMessageType=function(){return"object"};
b.prototype.handle=function(a){DEBUG&&console.log("[MAR] Received "+a.objects.length+" objects");void 0!=mar.world&&mar.world.handleObjectsUpdate(a.objects)};return b}(),TickListener=function(){function b(){}b.prototype.getListenedMessageType=function(){return"tick"};b.prototype.handle=function(a){mar.client.requestObjects();void 0!==a.keys&&(mar.client.keyboardBuffer.keys=a.keys);void 0!=a.c&&(mar.client.consoleScreen.handleConsoleBufferUpdate(a.c,a.cm),DEBUG&&console.log("[MAR] Received "+a.c.length+
" console message(s)"))};return b}(),UserInfoListener=function(){function b(){}b.prototype.getListenedMessageType=function(){return"userInfo"};b.prototype.handle=function(a){DEBUG&&console.log("[MAR] Received user info message");mar.client.worldX=a.worldX;mar.client.worldY=a.worldY;mar.client.maxWidth=a.maxWidth;mar.client.requestTerrain()};return b}(),AuthListener=function(){function b(){}b.prototype.getListenedMessageType=function(){return"auth"};b.prototype.handle=function(a){DEBUG&&console.log("[MAR] Received auth response");
"ok"===a.m?(DEBUG&&console.log("[MAR] Auth successful"),mar.client.requestUserInfo()):alert("Authentication failed. Please make sure you are logged in and reload the page.")};return b}(),TerrainListener=function(){function b(){}b.prototype.getListenedMessageType=function(){return"terrain"};b.prototype.handle=function(a){DEBUG&&console.log("[MAR] Received terrain");mar.world&&mar.world.removeBigMessage();if(a.ok){var c=a.size;void 0==c&&(c=config.defaultWorldSize);DEBUG&&console.log("[MAR] World is available");
null!=mar.world?(DEBUG&&console.log("[MAR] Updating World terrain"),mar.world.updateTerrain(a.terrain,c)):(DEBUG&&console.log("[MAR] Creating new World"),mar.world=new World(a.terrain,c))}else DEBUG&&console.log("[MAR] World is not available"),null!=mar.world?(DEBUG&&console.log("[MAR] Updating World terrain"),mar.world.updateTerrain([],config.defaultWorldSize)):(DEBUG&&console.log("[MAR] Creating new World"),mar.world=new World([],config.defaultWorldSize)),mar.world&&mar.world.setBigMessage("[Uncharted World]")};
return b}(),CodeListener=function(){function b(){}b.prototype.getListenedMessageType=function(){return"code"};b.prototype.handle=function(a){ace.edit("editor").setValue(a.code)};return b}(),CodeResponseListener=function(){function b(){}b.prototype.getListenedMessageType=function(){return"codeResponse"};b.prototype.handle=function(a){alert("Uploaded and assembled "+a.bytes+" bytes ("+a.exceptions+" errors)")};return b}(),GameClient=function(){function b(){this.listeners=[];this.getServerInfo();this.consoleScreen=
new PlainTextConsole(defaultText,"consoleText","colorButton","scrollButton","resetButton","widthDial")}b.prototype.requestUserInfo=function(){DEBUG&&console.log("[MAR] Requesting user info");this.socket.send(JSON.stringify({t:"userInfo"}))};b.prototype.requestTerrain=function(){DEBUG&&console.log("[MAR] Requesting terrain for world ("+this.worldX+", "+this.worldY+")");this.socket.send(JSON.stringify({t:"terrain",x:this.worldX,y:this.worldY}));this.requestObjects()};b.prototype.uploadCode=function(a){DEBUG&&
console.log("[MAR] Uploaded code");this.socket.send(JSON.stringify({t:"uploadCode",code:a}))};b.prototype.reloadCode=function(){DEBUG&&console.log("[MAR] Reloading code");this.socket.send(JSON.stringify({t:"codeRequest"}))};b.prototype.sendKeyPress=function(a){DEBUG&&console.log("[MAR] Sent KeyPress: "+a);0!==a&&this.socket.send(JSON.stringify({t:"k",k:a}))};b.prototype.requestFloppy=function(){document.getElementById("floppyDown").innerHTML='<i class="fa fa-cog fa-spin fa-fw"></i>';DEBUG&&console.log("[MAR] Requesting floppy");
this.socket.send(JSON.stringify({t:"floppyDown"}))};b.prototype.notifyFloppyUp=function(){DEBUG&&console.log("[MAR] Notifying the game server of floppy upload");this.socket.send(JSON.stringify({t:"floppyUp"}))};b.prototype.requestObjects=function(){DEBUG&&console.log("[MAR] Requesting game objects");this.socket.send(JSON.stringify({t:"object",x:this.worldX,y:this.worldY}))};b.prototype.getServerInfo=function(){var a=this;DEBUG&&console.log("[MAR] Getting server info... ");var c=new XMLHttpRequest;
c.open("GET","./getServerInfo.php",!0);c.onreadystatechange=function(){4===c.readyState&&200===c.status&&(DEBUG&&console.log("[MAR] Received server info "+c.responseText),setTimeout(a.connectToGameServer(JSON.parse(c.responseText)),100))};c.send(null)};b.prototype.connectToGameServer=function(a){var c=this;DEBUG&&console.log("[MAR] Connecting to "+a.address);this.socket=new WebSocket(a.address);this.username=a.username;this.tickLength=a.tickLength;this.serverName=a.serverName;this.socket.binaryType=
"arraybuffer";this.socket.onopen=function(){DEBUG&&console.log("[MAR] Connected. Sent auth request");c.socket.send(a.token);c.listeners.push(new UserInfoListener);c.listeners.push(new AuthListener);c.listeners.push(new TickListener);c.listeners.push(new TerrainListener);c.listeners.push(new ObjectsListener);c.listeners.push(new CodeResponseListener);c.listeners.push(new CodeListener);c.socket.onmessage=function(a){try{var b=JSON.parse(a.data);DEBUG&&console.log("[MAR] Received: "+a.data);for(var d=
0;d<c.listeners.length;d++)c.listeners[d].getListenedMessageType()===b.t&&c.listeners[d].handle(b)}catch(h){DEBUG&&(console.log("[MAR] Received invalid message, assuming floppy data"),document.getElementById("floppyDown").innerHTML='<i class="fa fa-long-arrow-down" aria-hidden="true"></i> <i class="fa fa-floppy-o" aria-hidden="true"></i>',a=new Blob([a.data],{type:"application/octet-stream"}),saveAs(a,"floppy.bin"))}};c.reloadCode()};this.socket.onerror=function(c){alert("Can't connect to game server at address "+
a.address);console.log(c)};this.socket.onclose=function(a){mar.world.setBigMessage("Disconnected from server :(");console.log(a)};this.initGame()};b.prototype.initGame=function(){if("guest"!=this.username){var a=this;this.keyboardBuffer=new KeyboardBuffer(config.kbBufferX,config.kbBufferY);mar.addDebugMessage(this.keyboardBuffer);mar.game.input.keyboard.onDownCallback=function(c){document.activeElement===document.getElementById("game")&&((37<=c.keyCode&&40>=c.keyCode||116===c.keyCode||32===c.keyCode)&&
c.preventDefault(),"guest"!==a.username&&16>=a.keyboardBuffer.keys.length&&(a.sendKeyPress(c.keyCode),a.keyboardBuffer.keys.push(c.keyCode)))}}};b.prototype.findMyRobot=function(){"guest"==this.username?alert("You are not logged in!"):this.requestUserInfo()};return b}(),ObjectType;(function(b){b[b.CUBOT=1]="CUBOT";b[b.BIOMASS=2]="BIOMASS";b[b.HARVESTER_NPC=10]="HARVESTER_NPC";b[b.FACTORY=3]="FACTORY";b[b.RADIO_TOWER=4]="RADIO_TOWER";b[b.VAULT_DOOR=5]="VAULT_DOOR"})(ObjectType||(ObjectType={}));var ItemType;
(function(b){b[b.BIOMASS=1]="BIOMASS";b[b.IRON=3]="IRON";b[b.COPPER=4]="COPPER"})(ItemType||(ItemType={}));var Action;(function(b){b[b.IDLE=0]="IDLE";b[b.DIGGING=1]="DIGGING";b[b.WALKING=2]="WALKING";b[b.WITHDRAWING=3]="WITHDRAWING";b[b.DEPOSITING=4]="DEPOSITING";b[b.LISTENING=5]="LISTENING";b[b.JUMPING=6]="JUMPING"})(Action||(Action={}));
var GameObject=function(b){function a(a,d,e,f,h){return b.call(this,mar.game,a,d,e,f,h)||this}__extends(a,b);a.createObject=function(a){switch(a.t){case ObjectType.CUBOT:return new Cubot(a);case ObjectType.BIOMASS:return new BiomassBlob(a);case ObjectType.HARVESTER_NPC:return new HarvesterNPC(a);case ObjectType.FACTORY:return new Factory(a);case ObjectType.RADIO_TOWER:return new RadioTower(a);case ObjectType.VAULT_DOOR:return new VaultDoor(a);default:return null}};a.prototype.setText=function(a){this.text=
mar.game.make.text(0,0,a,{fontSize:22,fill:config.textFill,stroke:config.textStroke,strokeThickness:2,font:"fixedsys"});this.text.anchor.set(.5,0);this.addChild(this.text)};a.prototype.isAt=function(a,b){return a==this.tileX&&b==this.tileY};return a}(Phaser.Plugin.Isometric.IsoSprite),HologramMode;(function(b){b[b.CLEARED=0]="CLEARED";b[b.HEX=1]="HEX";b[b.STRING=2]="STRING";b[b.DEC=3]="DEC"})(HologramMode||(HologramMode={}));
var Cubot=function(b){function a(a){var c=b.call(this,Util.getIsoX(a.x),Util.getIsoY(a.y),15,"sheet",null)||this;c.queuedAnimations=[];c.hovered=!1;DEBUG&&console.log("Creating Cubot object");c.anchor.set(.5,0);c.id=a.i;c.tileX=a.x;c.tileY=a.y;c.username=a.parent;c.heldItem=a.heldItem;c.direction=a.direction;c.action=a.action;c.energy=a.energy;c.animations.add("walk_w",mar.animationFrames.walk_w);c.animations.add("walk_s",mar.animationFrames.walk_s);c.animations.add("walk_e",mar.animationFrames.walk_e);

View File

@ -86,9 +86,9 @@ class Util {
case Direction.WEST:
return 0;
case Direction.NORTH:
return 1;
case Direction.SOUTH:
return -1;
case Direction.SOUTH:
return 1;
}
}