mirror of
https://github.com/simon987/Much-Assembly-Required-Frontend.git
synced 2025-04-10 14:26:44 +00:00
77 lines
36 KiB
JavaScript
77 lines
36 KiB
JavaScript
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(b,a,c){b!=Array.prototype&&b!=Object.prototype&&(b[a]=c.value)};$jscomp.getGlobal=function(b){return"undefined"!=typeof window&&window===b?b:"undefined"!=typeof global&&null!=global?global:b};$jscomp.global=$jscomp.getGlobal(this);
|
|
$jscomp.polyfill=function(b,a,c,d){if(a){c=$jscomp.global;b=b.split(".");for(d=0;d<b.length-1;d++){var e=b[d];e in c||(c[e]={});c=c[e]}b=b[b.length-1];d=c[b];a=a(d);a!=d&&null!=a&&$jscomp.defineProperty(c,b,{configurable:!0,writable:!0,value:a})}};$jscomp.underscoreProtoCanBeSet=function(){var b={a:!0},a={};try{return a.__proto__=b,a.a}catch(c){}return!1};
|
|
$jscomp.setPrototypeOf="function"==typeof Object.setPrototypeOf?Object.setPrototypeOf:$jscomp.underscoreProtoCanBeSet()?function(b,a){b.__proto__=a;if(b.__proto__!==a)throw new TypeError(b+" is not extensible");return b}:null;$jscomp.polyfill("Object.setPrototypeOf",function(b){return b||$jscomp.setPrototypeOf},"es6","es5");$jscomp.SYMBOL_PREFIX="jscomp_symbol_";$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};
|
|
$jscomp.Symbol=function(){var b=0;return function(a){return $jscomp.SYMBOL_PREFIX+(a||"")+b++}}();$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var b=$jscomp.global.Symbol.iterator;b||(b=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));"function"!=typeof Array.prototype[b]&&$jscomp.defineProperty(Array.prototype,b,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}});$jscomp.initSymbolIterator=function(){}};
|
|
$jscomp.arrayIterator=function(b){var a=0;return $jscomp.iteratorPrototype(function(){return a<b.length?{done:!1,value:b[a++]}:{done:!0}})};$jscomp.iteratorPrototype=function(b){$jscomp.initSymbolIterator();b={next:b};b[$jscomp.global.Symbol.iterator]=function(){return this};return b};
|
|
$jscomp.iteratorFromArray=function(b,a){$jscomp.initSymbolIterator();b instanceof String&&(b+="");var c=0,d={next:function(){if(c<b.length){var e=c++;return{value:a(e,b[e]),done:!1}}d.next=function(){return{done:!0,value:void 0}};return d.next()}};d[Symbol.iterator]=function(){return d};return d};$jscomp.polyfill("Array.prototype.keys",function(b){return b?b:function(){return $jscomp.iteratorFromArray(this,function(a){return a})}},"es6","es3");
|
|
var __extends=this&&this.__extends||function(){var b=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(a,c){a.__proto__=c}||function(a,c){for(var b in c)c.hasOwnProperty(b)&&(a[b]=c[b])};return function(a,c){function d(){this.constructor=a}b(a,c);a.prototype=null===c?Object.create(c):(d.prototype=c.prototype,new d)}}(),MarGame=function(){function b(){this.cursorPos=new Phaser.Plugin.Isometric.Point3;this.debugMessages=[];this.animationFrames={};var a=this;this.game=new Phaser.Game(RENDERER_WIDTH,
|
|
RENDERER_HEIGHT,Phaser.AUTO,"game",null,!0,!1);this.bootState={preload:function(){DEBUG&&console.log("[MAR]\u00a0Loading sprites.png as JSONHash");this.game.load.atlasJSONHash("sheet","./mar/sprites.png","./mar/sprites.json").onLoadComplete.add(function(){a.game.time.advancedTiming=!0;DEBUG&&console.log("[MAR]\u00a0Enabling isometric plugin");a.game.plugins.add(new Phaser.Plugin.Isometric(a.game));a.game.iso.anchor.setTo(.5,0);a.game.world.setBounds(0,0,2200,1100);a.game.camera.x=280;a.game.camera.y=
|
|
90;a.game.scale.scaleMode=Phaser.ScaleManager.RESIZE;a.game.scale.pageAlignHorizontally=!0;a.game.scale.pageAlignVertically=!0;a.game.stage.disableVisibilityChange=!0;a.client=new GameClient;a.game.input.onDown.add(function(){document.getElementById("game").focus();DEBUG&&console.log("Grabbed focus of #game")});a.isoGroup=mar.game.add.group();a.textGroup=mar.game.add.group();a.hudGroup=mar.game.add.group();a.hudGroup.fixedToCamera=!0})},create:function(){DEBUG&&console.log("[MAR] create");a.initialiseAnimations();
|
|
a.initialiseStaticHud()},update:function(){a.game.scale.refresh();a.game.iso.unproject(a.game.input.activePointer.position,a.cursorPos);a.isoGroup.forEach(function(c){if(c instanceof Tile){var b=c.isoBounds.containsXY(a.cursorPos.x,a.cursorPos.y);!c.selected&&b?(c.selected=!0,c.onHover(),a.isoGroup.forEach(function(a){if(a instanceof GameObject&&void 0!=a.onTileHover&&a.isAt(c.tileX,c.tileY))a.onTileHover()},1)):c.selected&&!b&&(c.selected=!1,c.onExit(),a.isoGroup.forEach(function(a){if(void 0!=a.onTileExit&&
|
|
a.isAt(c.tileX,c.tileY))a.onTileExit()},0))}},0);this.game.input.activePointer.isDown?(this.game.origDragPoint&&(this.game.camera.x+=this.game.origDragPoint.x-this.game.input.activePointer.position.x,this.game.camera.y+=this.game.origDragPoint.y-this.game.input.activePointer.position.y),this.game.origDragPoint=this.game.input.activePointer.position.clone()):this.game.origDragPoint=null;a.game.iso.topologicalSort(a.isoGroup)},render:function(){for(var c=0;c<a.debugMessages.length;c++)a.game.debug.text(a.debugMessages[c].getMessage(),
|
|
a.debugMessages[c].x,a.debugMessages[c].y)}};this.game.state.add("Boot",this.bootState);this.game.state.start("Boot")}b.prototype.addDebugMessage=function(a){this.debugMessages.push(a)};b.prototype.initialiseAnimations=function(){this.animationFrames.walk_e_start=[];for(var a=0;10>a;a++)this.animationFrames.walk_e_start.push("cubot/walk_e/"+("0000"+a).slice(-4));this.animationFrames.walk_e=[];for(a=10;30>a;a++)this.animationFrames.walk_e.push("cubot/walk_e/"+("0000"+a).slice(-4));this.animationFrames.harvester_walk_e_start=
|
|
[];for(a=0;10>a;a++)this.animationFrames.harvester_walk_e_start.push("harvester/walk_e/"+("0000"+a).slice(-4));this.animationFrames.harvester_walk_e=[];for(a=10;30>a;a++)this.animationFrames.harvester_walk_e.push("harvester/walk_e/"+("0000"+a).slice(-4));this.animationFrames.walk_n_start=[];for(a=0;10>a;a++)this.animationFrames.walk_n_start.push("cubot/walk_n/"+("0000"+a).slice(-4));this.animationFrames.walk_n=[];for(a=10;30>a;a++)this.animationFrames.walk_n.push("cubot/walk_n/"+("0000"+a).slice(-4));
|
|
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.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}};b.itemColor=function(a){switch(a){case 1:return config.biomassTint;case 3:return config.itemIron;case 4:return config.itemCopper}};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);
|
|
c.animations.add("walk_n",mar.animationFrames.walk_n);c.animations.add("dig_w",mar.animationFrames.dig_w);c.animations.add("dig_s",mar.animationFrames.dig_s);c.animations.add("dig_e",mar.animationFrames.dig_e);c.animations.add("dig_n",mar.animationFrames.dig_n);c.createUsername();c.updateDirection();c.tint=c.getTint();return c}__extends(a,b);a.prototype.onTileHover=function(){mar.game.add.tween(this).to({isoZ:45},200,Phaser.Easing.Quadratic.InOut,!0);mar.game.add.tween(this.scale).to({x:1.2,y:1.2},
|
|
200,Phaser.Easing.Linear.None,!0);this.tint=config.cubotHoverTint;void 0!==this.text&&(this.text.visible=!0);this.hovered=!0};a.prototype.onTileExit=function(){mar.game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,!0);mar.game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);void 0!==this.text&&(this.text.visible=!1);this.hovered=!1;this.tint=this.getTint()};a.prototype.getTint=function(){return this.hovered?config.cubotHoverTint:this.energy<=config.lowEnergy?config.lowEnergyTint:
|
|
config.cubotTint};a.prototype.updateObject=function(a){DEBUG&&console.log("Updating Cubot object");this.action=a.action;this.energy=a.energy;this.direction=a.direction;this.createInventory([a.heldItem]);this.heldItem=a.heldItem;this.tint=this.getTint();this.isAt(a.x,a.y)||this.action!=Action.WALKING||(this.tileX=a.x,this.tileY=a.y,this.walk());if(this.action==Action.DIGGING)switch(this.direction){case Direction.NORTH:this.animations.play("dig_n",60);break;case Direction.SOUTH:this.animations.play("dig_s",
|
|
60);break;case Direction.EAST:this.animations.play("dig_e",60);break;case Direction.WEST:this.animations.play("dig_w",60)}this.updateDirection();this.updateHologram(a.holoMode,a.holoC,a.holo,a.holoStr)};a.prototype.updateHologram=function(a,b,e,f){b=(b&16777215).toString(16);b="#"+("000000".substr(b.length)+b);void 0==this.hologram&&(this.hologram=mar.game.make.text(0,32,""),this.hologram.anchor.set(.5,0),this.addChild(this.hologram));this.hologram.setStyle(config.holoStyle(b));switch(a){case HologramMode.CLEARED:this.hologram.text=
|
|
"";break;case HologramMode.DEC:this.hologram.text=Number(e).toString();break;case HologramMode.HEX:this.hologram.text="0x"+("0000"+Number(e).toString(16).toUpperCase()).slice(-4);break;case HologramMode.STRING:this.hologram.text=f.replace(/[\n|\t]/g,"")}};a.prototype.updateDirection=function(){switch(this.direction){case Direction.NORTH:this.animations.frameName="cubot/walk_n/0001";break;case Direction.EAST:this.animations.frameName="cubot/walk_e/0001";break;case Direction.SOUTH:this.animations.frameName=
|
|
"cubot/walk_s/0001";break;case Direction.WEST:this.animations.frameName="cubot/walk_w/0001"}};a.prototype.walk=function(){var a=this,b=function(b){b=mar.game.add.tween(a).to({isoX:Util.getIsoX(a.tileX),isoY:Util.getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0);switch(a.direction){case Direction.NORTH:a.animations.play("walk_n",60,!0);break;case Direction.SOUTH:a.animations.play("walk_s",60,!0);break;case Direction.EAST:a.animations.play("walk_e",60,!0);break;case Direction.WEST:a.animations.play("walk_w",
|
|
60,!0)}b.onComplete.add(function(){a.animations.stop();a.updateDirection();a.isoX=Util.getIsoX(a.tileX);a.isoY=Util.getIsoY(a.tileY);a.onTileExit();for(var b=0;b<a.queuedAnimations.length;b++)a.queuedAnimations[b](config.walkDuration/2),a.queuedAnimations.splice(b,1)})};this.animations.currentAnim.isPlaying?this.queuedAnimations.push(b):b(config.walkDuration)};a.prototype.createUsername=function(){var a=mar.game.make.text(0,-24,this.username,{fontSize:22,fill:config.textFill,stroke:config.textStroke,
|
|
strokeThickness:2,font:"fixedsys"});a.alpha=.85;a.anchor.set(.5,0);this.username===mar.client.username?a.tint=config.selfUsernameColor:this.alpha=config.otherCubotAlpha;this.addChild(a)};a.prototype.createInventory=function(a){void 0!=this.inventory&&this.inventory.destroy();var b=mar.game.make.group();switch(a.length){case 0:this.inventory=b;this.addChild(b);break;case 1:if(0!==a[0]){var c=mar.game.make.sprite(0,0,"sheet","inventory/inv1x1");c.anchor.set(.5,.1);c.alpha=.5;var f=mar.game.make.sprite(0,
|
|
0,"sheet","inventory/item");f.anchor.set(.5,.1);f.tint=Util.itemColor(a[0]);b.addChild(c);b.addChild(f)}this.inventory=b;this.addChild(b)}};return a}(GameObject),HarvesterNPC=function(b){function a(a){a=b.call(this,a)||this;a.animations.add("walk_w",mar.animationFrames.harvester_walk_w);a.animations.add("walk_s",mar.animationFrames.harvester_walk_s);a.animations.add("walk_e",mar.animationFrames.harvester_walk_e);a.animations.add("walk_n",mar.animationFrames.harvester_walk_n);a.updateDirection();a.setText("Harvester NPC");
|
|
a.text.visible=!1;return a}__extends(a,b);a.prototype.getTint=function(){return config.cubotTint};a.prototype.updateDirection=function(){switch(this.direction){case Direction.NORTH:this.animations.frameName="harvester/walk_n/0001";break;case Direction.EAST:this.animations.frameName="harvester/walk_e/0001";break;case Direction.SOUTH:this.animations.frameName="harvester/walk_s/0001";break;case Direction.WEST:this.animations.frameName="harvester/walk_w/0001"}};a.prototype.updateObject=function(a){DEBUG&&
|
|
console.log("Updating Harvester NPC object");this.action=a.action;this.direction=a.direction;this.isAt(a.x,a.y)||this.action!=Action.WALKING||(this.tileX=a.x,this.tileY=a.y,this.walk());this.updateDirection()};a.prototype.createUsername=function(){};return a}(Cubot),BiomassBlob=function(b){function a(a){var c=b.call(this,Util.getIsoX(a.x),Util.getIsoY(a.y),10,"sheet",1)||this;DEBUG&&console.log("Creating Biomass object");c.anchor.set(.5,0);c.id=a.i;c.tileX=a.x;c.tileY=a.y;c.tint=config.biomassTint;
|
|
c.animations.add("idle",mar.animationFrames.biomassIdle);c.animations.play("idle",45,!0);c.setText("Biomass");c.text.visible=!1;return c}__extends(a,b);a.prototype.onTileHover=function(){mar.game.tweens.removeFrom(this);mar.game.add.tween(this).to({isoZ:45},200,Phaser.Easing.Quadratic.InOut,!0);this.tint=config.biomassHoverTint;mar.game.add.tween(this.scale).to({x:1.2,y:1.2},200,Phaser.Easing.Linear.None,!0);this.text.visible=!0};a.prototype.onTileExit=function(){mar.game.tweens.removeFrom(this);
|
|
mar.game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,!0);mar.game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=config.biomassTint;this.text.visible=!1};a.prototype.updateObject=function(a){DEBUG&&console.log("Updating Biomass object")};return a}(GameObject),Factory=function(b){function a(a){var c=b.call(this,Util.getIsoX(a.x),Util.getIsoY(a.y),15,"sheet","objects/factory")||this;c.anchor.set(.5,.25);c.setText("Factory");c.text.visible=!1;c.id=a.i;c.tileX=
|
|
a.x;c.tileY=a.y;return c}__extends(a,b);a.prototype.onTileHover=function(){mar.game.tweens.removeFrom(this);mar.game.add.tween(this).to({isoZ:25},200,Phaser.Easing.Quadratic.InOut,!0);mar.game.add.tween(this.scale).to({x:1.06,y:1.06},200,Phaser.Easing.Linear.None,!0);this.tint=config.cubotHoverTint;this.text.visible=!0};a.prototype.onTileExit=function(){mar.game.tweens.removeFrom(this);mar.game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,!0);mar.game.add.tween(this.scale).to({x:1,y:1},
|
|
200,Phaser.Easing.Linear.None,!0);this.tint=config.cubotTint;this.text.visible=!1};a.prototype.updateObject=function(a){};a.prototype.isAt=function(a,b){return(this.tileX===a||this.tileX+1===a)&&(this.tileY+1===b||this.tileY===b)};return a}(GameObject),RadioTower=function(b){function a(a){var c=b.call(this,Util.getIsoX(a.x),Util.getIsoY(a.y),15,"sheet","objects/RadioTower")||this;c.anchor.set(.48,.65);c.setText("Radio Tower");c.text.visible=!1;c.id=a.i;c.tileX=a.x;c.tileY=a.y;return c}__extends(a,
|
|
b);a.prototype.onTileHover=function(){mar.game.tweens.removeFrom(this);mar.game.add.tween(this).to({isoZ:25},200,Phaser.Easing.Quadratic.InOut,!0);mar.game.add.tween(this.scale).to({x:1.06,y:1.06},200,Phaser.Easing.Linear.None,!0);this.tint=config.cubotHoverTint;this.text.visible=!0};a.prototype.onTileExit=function(){mar.game.tweens.removeFrom(this);mar.game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,!0);mar.game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);
|
|
this.tint=config.cubotTint;this.text.visible=!1};a.prototype.updateObject=function(a){};return a}(GameObject),VaultDoor=function(b){function a(a){var c=b.call(this,Util.getIsoX(a.x),Util.getIsoY(a.y),15,"sheet","objects/VaultDoor")||this;c.anchor.set(myVarX,myVarY);c.setText("Vault");c.text.visible=!1;c.id=a.i;c.tileX=a.x;c.tileY=a.y;return c}__extends(a,b);a.prototype.onTileHover=function(){mar.game.tweens.removeFrom(this);mar.game.add.tween(this).to({isoZ:25},200,Phaser.Easing.Quadratic.InOut,!0);
|
|
mar.game.add.tween(this.scale).to({x:1.06,y:1.06},200,Phaser.Easing.Linear.None,!0);this.tint=config.cubotHoverTint;this.text.visible=!0};a.prototype.onTileExit=function(){mar.game.tweens.removeFrom(this);mar.game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,!0);mar.game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=config.cubotTint;this.text.visible=!1};a.prototype.updateObject=function(a){};return a}(GameObject),Direction;
|
|
(function(b){b[b.NORTH=0]="NORTH";b[b.EAST=1]="EAST";b[b.SOUTH=2]="SOUTH";b[b.WEST=3]="WEST"})(Direction||(Direction={}));var TileType;(function(b){b[b.PLAIN=0]="PLAIN";b[b.WALL=1]="WALL";b[b.IRON=2]="IRON";b[b.COPPER=3]="COPPER"})(TileType||(TileType={}));
|
|
var Tile=function(b){function a(a,d,e,f){e=b.call(this,mar.game,Util.getIsoX(a),Util.getIsoY(d),0,"sheet",e)||this;e.baseZ=0;e.tileX=a;e.tileY=d;e.anchor.set(.5,f);return e}__extends(a,b);a.createTile=function(a,b,e){switch(a){case TileType.WALL:return new WallTile(b,e);case TileType.IRON:return new IronTile(b,e);case TileType.COPPER:return new CopperTile(b,e);default:return new PlainTile(b,e)}};a.prototype.onHover=function(){this.tint=config.tileHoverTint;mar.game.add.tween(this).to({isoZ:this.baseZ+
|
|
8},200,Phaser.Easing.Quadratic.InOut,!0);mar.tileIndicator.tileX=this.tileX;mar.tileIndicator.tileY=this.tileY;mar.tileIndicator.tileType=this.tileType};a.prototype.onExit=function(){this.tint=this.baseTint;mar.game.add.tween(this).to({isoZ:this.baseZ},200,Phaser.Easing.Quadratic.InOut,!0)};a.prototype.setText=function(a,b){void 0!==this.textSprite&&this.textSprite.destroy();this.textSprite=mar.game.make.text(0,16,a,{fontSize:22,fill:b,stroke:"#FFFFFF",strokeThickness:1,font:"fixedsys"});this.textSprite.alpha=
|
|
.6;this.textSprite.anchor.set(.5,0);this.addChild(this.textSprite)};return a}(Phaser.Plugin.Isometric.IsoSprite),PlainTile=function(b){function a(a,d){a=b.call(this,a,d,config.plainSprite,0)||this;a.baseTint=config.tileTint;a.tint=a.baseTint;a.tileType="plain";return a}__extends(a,b);return a}(Tile),WallTile=function(b){function a(a,d){a=b.call(this,a,d,config.wallSprite,.2)||this;a.baseTint=config.wallTint;a.tint=a.baseTint;a.tileType="wall";return a}__extends(a,b);return a}(Tile),IronTile=function(b){function a(a,
|
|
d){a=b.call(this,a,d,config.plainSprite,0)||this;a.baseTint=config.oreTint;a.tint=a.baseTint;a.setText("Iron",config.textIron);a.tileType="iron";return a}__extends(a,b);return a}(Tile),CopperTile=function(b){function a(a,d){a=b.call(this,a,d,config.plainSprite,0)||this;a.baseTint=config.oreTint;a.tint=a.baseTint;a.setText("Copper",config.textCopper);a.tileType="copper";return a}__extends(a,b);return a}(Tile),World=function(){function b(a,b){this.tiles=[];this.objects=[];this.northArrow=new WorldArrow(528,
|
|
-10,"ui/arrow_north",Direction.NORTH);mar.isoGroup.add(this.northArrow);this.eastArrow=new WorldArrow(1115,587,"ui/arrow_east",Direction.EAST);mar.isoGroup.add(this.eastArrow);this.southArrow=new WorldArrow(0,0,"ui/arrow_south",Direction.SOUTH);mar.isoGroup.add(this.southArrow);this.westArrow=new WorldArrow(-60,587,"ui/arrow_west",Direction.WEST);mar.isoGroup.add(this.westArrow);this.setTerrain(a,b)}b.prototype.setTerrain=function(a,b){DEBUG&&console.log("[MAR] Creating tilemap of size "+b);for(var c=
|
|
0;c<b;c++)for(var e=0;e<b;e++){var f=Tile.createTile(a[e*b+c],c,e);this.tiles.push(f);mar.isoGroup.add(f)}this.eastArrow.isoY=32*(b+2);this.eastArrow.isoX=72.5*b-20;this.southArrow.isoX=32*(b+1);this.southArrow.isoY=72.5*b+20;mar.game.world.width=128*(b+2);mar.game.world.height=64*(b+2)};b.prototype.setBigMessage=function(a){this.bigMessage=mar.game.add.text(908,450,a,{fontSize:46,fill:config.bigMessageFill,stroke:config.textStroke,strokeThickness:2,font:"fixedsys"},mar.textGroup)};b.prototype.removeBigMessage=
|
|
function(){void 0!=this.bigMessage&&(this.bigMessage.destroy(),DEBUG&&console.log("[MAR] Destroyed big message"))};b.prototype.getObject=function(a){for(var b=0;b<this.objects.length;b++)if(this.objects[b].id===a)return this.objects[b];return null};b.prototype.handleObjectsUpdate=function(a){for(var b=0;b<this.objects.length;b++)this.objects[b].updated=!1;for(b=0;b<a.length;b++){var d=this.getObject(a[b].i);null!==d?(d.updated=!0,d.updateObject(a[b])):(d=GameObject.createObject(a[b]),null!=d?(d.updated=
|
|
!0,this.objects.push(d),mar.isoGroup.add(d)):DEBUG&&console.log("Couldn't create object with objType "+a[b].t))}for(b=0;b<this.objects.length;b++)this.objects[b].updated||("guest"!==mar.client.username&&this.objects[b]instanceof Cubot&&this.objects[b].username===mar.client.username&&(mar.client.findMyRobot(),DEBUG&&console.log("[MAR] Following Cubot "+mar.client.username)),this.objects[b].destroy(),this.objects.splice(b,1))};b.prototype.updateTerrain=function(a,b){for(var c=0;c<this.objects.length;c++)this.objects[c].destroy();
|
|
for(c=0;c<this.tiles.length;c++)this.tiles[c].destroy();this.objects=[];this.tiles=[];this.setTerrain(a,b);mar.game.iso.topologicalSort(mar.isoGroup)};return b}(),WorldArrow=function(b){function a(a,d,e,f){var c=b.call(this,mar.game,a,d,10,"sheet",e)||this;c.hoverText=mar.game.make.text(10,10,Direction[f],config.arrowTextStyle);c.addChild(c.hoverText);c.hoverText.visible=!1;c.hoverText.anchor.set(0,0);c.inputEnabled=!0;c.events.onInputDown.add(function(){var a=mar.client.worldX+Util.getDeltaX(f),
|
|
b=mar.client.worldY+Util.getDeltaY(f);mar.client.worldX=a%mar.client.maxWidth;mar.client.worldY=b%mar.client.maxWidth;mar.client.requestTerrain()});c.events.onInputOver.add(function(){c.tint=config.arrowHoverTint;c.hoverText.visible=!0;document.body.style.cursor="pointer"});c.events.onInputOut.add(function(){c.tint=config.arrowTint;c.hoverText.visible=!1;document.body.style.cursor="default"});return c}__extends(a,b);return a}(Phaser.Plugin.Isometric.IsoSprite),defaultText=" _______ __ __\n| _ |.-----.---.-.----.| |--.|__|.----.-----.----.-----.\n| || _ | _ | __|| || || __| _ | _| _ |\n|___|___|| __|___._|____||__|__||__||____|_____|__| | __|\n |__| |__|\n\nVersion 1.3A, 1985-05-17\nInitialising Universal Communication Port connection...Done\nCurrent date is 2790-01-14\nCubot Status: Much Assembly Required",
|
|
ConsoleMode;(function(b){b[b.CLEAR=0]="CLEAR";b[b.NORMAL=1]="NORMAL"})(ConsoleMode||(ConsoleMode={}));
|
|
var PlainTextConsoleMode=function(){return function(b,a){this.width=b;this.dialImage=a}}(),PlainTextConsole=function(){function b(a,c,d,e,f,h){this.colorToggled=!1;this.autoScroll=!0;this.modes=[];this.lastLineLength=0;this.txtDiv=document.getElementById(c);this.colorButton=document.getElementById(d);this.scrollButton=document.getElementById(e);this.resetButton=document.getElementById(f);this.widthDial=document.getElementById(h);var g=this;this.colorButton.onclick=function(){g.toggleColor(g)};this.scrollButton.onclick=
|
|
function(){g.toggleScrolling(g)};this.resetButton.onclick=function(){g.reset(g)};this.widthDial.onclick=function(){b.widthDialClick(g)};this.consoleText=this.txtDiv.innerHTML=a;this.modes.push(new PlainTextConsoleMode(16,"./images/knob-170.png"));this.modes.push(new PlainTextConsoleMode(24,"./images/knob-123.png"));this.modes.push(new PlainTextConsoleMode(40,"./images/knob-90.png"));this.modes.push(new PlainTextConsoleMode(56,"./images/knob-65.png"));this.modes.push(new PlainTextConsoleMode(64,"./images/knob-10.png"));
|
|
this.mode=3}b.prototype.toggleColor=function(a){a.colorToggled?(a.colorToggled=!1,a.colorButton.src="./images/pdp8ion.png",a.txtDiv.classList.remove("ctr-selection-inverted"),a.txtDiv.classList.remove("ctr-text-inverted"),a.txtDiv.classList.add("ctr-selection"),a.txtDiv.classList.add("ctr-text")):(a.colorToggled=!0,a.colorButton.src="./images/pdp8ioff.png",a.txtDiv.classList.add("ctr-selection-inverted"),a.txtDiv.classList.add("ctr-text-inverted"),a.txtDiv.classList.remove("ctr-selection"),a.txtDiv.classList.remove("ctr-text"))};
|
|
b.prototype.toggleScrolling=function(a){a.autoScroll?(a.autoScroll=!1,a.scrollButton.src="./images/pdp8ion.png"):(a.autoScroll=!0,a.scrollButton.src="./images/pdp8ioff.png",a.txtDiv.scrollTop=a.txtDiv.scrollHeight)};b.prototype.reset=function(a){a.txtDiv.innerHTML="";a.consoleText="";a.lastLineLength=0;a.resetButton.src="./images/pdp8ioff.png";window.setTimeout(function(){a.resetButton.src="./images/pdp8ion.png"},150)};b.widthDialClick=function(a){a.mode<a.modes.length-1?a.mode++:a.mode=0;a.widthDial.src=
|
|
a.modes[a.mode].dialImage};b.prototype.handleConsoleBufferUpdate=function(a,b){b==ConsoleMode.CLEAR&&this.reset(this);for(b=0;b<a.length;b++){var c=a[b].indexOf("\x00");c=a[b].substring(0,-1==c?void 0:c);for(var e=0;e<c.length;e++)"\n"==c[e]?(this.consoleText+="\n",this.lastLineLength=0):this.lastLineLength<this.modes[this.mode].width?(this.consoleText+=c[e],this.lastLineLength++):(this.consoleText+="\n",this.consoleText+=c[e],this.lastLineLength=1)}this.txtDiv.innerText=this.consoleText;this.autoScroll&&
|
|
(this.txtDiv.scrollTop=this.txtDiv.scrollHeight)};return b}();
|