Merge pull request #36 from simon987/Typescript

Re-written a big chunk of code in typescript for readability
This commit is contained in:
Simon Fortier 2018-01-20 09:13:00 -05:00 committed by GitHub
commit 8f5e851b31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
67 changed files with 15846 additions and 47388 deletions

View File

@ -1,7 +1,7 @@
<?php
include_once "include/MessageCookie.php";
include_once "include/SessionManager.php";
$register_msg = MessageCookie::getMsg("register");
$user = SessionManager::get();
?>
@ -42,18 +42,44 @@ $user = SessionManager::get();
<div id="main" class="container">
<div class="row 200%">
<div class="12u">
<div class="container">
<!-- Account information -->
<section>
<p>You are logged in as <span style="font-style: italic"><?php echo $user["username"] ?></span>
</p>
<!-- Account information -->
<section id="login">
<p>You are logged in as <span style="font-style: italic"><?php echo $user["username"] ?></span></p>
<?php
if ($register_msg) {
echo "<span style='color:#ff4943'>" . $register_msg . "</span></div>";
}
?>
<p>Account page is under construction</p>
</section>
<!-- Password reset form -->
<form action="changePassword.re.php" method="post">
<div class="row uniform">
<div class="6u 12u(xsmall)">
<label for="password">Current password</label>
<input id="password" name="password" type="password">
</div>
<div class="6u 12u(xsmall)">
<label for="new_password">New Password</label>
<input id="new_password" name="new_password" type="password">
</div>
<div class="6u 12u(xsmall)">
<input type="submit" value="Reset password">
</div>
</div>
</form>
</section>
</div>
</div>
</div>
<?php include "footer.inc.html" ?>
<?php // include "footer.inc.html" ?>
</div>
@ -62,10 +88,10 @@ $user = SessionManager::get();
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/jquery.dropotron.min.js"></script>
<script src="assets/js/skel.min.js"></script>
<script src="assets/js/util.js"></script>
<script src="assets/js/util.min.js"></script>
<!--[if lte IE 8]>
<script src="assets/js/ie/respond.min.js"></script><![endif]-->
<script src="assets/js/main.js"></script>
<script src="assets/js/main.min.js"></script>
</body>
</html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -325,7 +325,7 @@
var $this = $(this);
// Text, TextArea.
$this.find('input[type=text],textarea')
$this.find('input[objType=text],textarea')
.each(function () {
var i = $(this);
@ -365,7 +365,7 @@
});
// Password.
$this.find('input[type=password]')
$this.find('input[objType=password]')
.each(function () {
var i = $(this);
@ -374,8 +374,8 @@
.append(i.clone())
.remove()
.html()
.replace(/type="password"/i, 'type="text"')
.replace(/type=password/i, 'type=text')
.replace(/type="password"/i, 'objType="text"')
.replace(/type=password/i, 'objType=text')
);
if (i.attr('id') != '')
@ -435,7 +435,7 @@
$this
.on('submit', function () {
$this.find('input[type=text],input[type=password],textarea')
$this.find('input[objType=text],input[objType=password],textarea')
.each(function (event) {
var i = $(this);

12
assets/js/util.min.js vendored
View File

@ -6,9 +6,9 @@ return a}var a=c(this);d=c("body");var f=c(window),h=a.attr("id");var g=c.extend
g.delay))};a.css("-ms-overflow-style","-ms-autohiding-scrollbar").css("-webkit-overflow-scrolling","touch");g.hideOnClick&&(a.find("a").css("-webkit-tap-highlight-color","rgba(0,0,0,0)"),a.on("click","a",function(f){var d=c(this),e=d.attr("href"),k=d.attr("target");e&&"#"!=e&&""!=e&&e!="#"+h&&(f.preventDefault(),f.stopPropagation(),a._hide(),window.setTimeout(function(){"_blank"==k?window.open(e):window.location.href=e},g.delay+10))}));a.on("touchstart",function(c){a.touchPosX=c.originalEvent.touches[0].pageX;
a.touchPosY=c.originalEvent.touches[0].pageY});a.on("touchmove",function(c){if(null!==a.touchPosX&&null!==a.touchPosY){var f=a.touchPosX-c.originalEvent.touches[0].pageX,d=a.touchPosY-c.originalEvent.touches[0].pageY,e=a.outerHeight(),h=a.get(0).scrollHeight-a.scrollTop();if(g.hideOnSwipe){var k=!1;switch(g.side){case "left":k=20>d&&-20<d&&50<f;break;case "right":k=20>d&&-20<d&&-50>f;break;case "top":k=20>f&&-20<f&&50<d;break;case "bottom":k=20>f&&-20<f&&-50>d}if(k)return a.touchPosX=null,a.touchPosY=
null,a._hide(),!1}if(0>a.scrollTop()&&0>d||h>e-2&&h<e+2&&0<d)c.preventDefault(),c.stopPropagation()}});a.on("click touchend touchstart touchmove",function(a){a.stopPropagation()});a.on("click",'a[href="#'+h+'"]',function(a){a.preventDefault();a.stopPropagation();g.target.removeClass(g.visibleClass)});d.on("click touchend",function(c){a._hide(c)});d.on("click",'a[href="#'+h+'"]',function(a){a.preventDefault();a.stopPropagation();g.target.toggleClass(g.visibleClass)});if(g.hideOnEscape)f.on("keydown",
function(c){27==c.keyCode&&a._hide(c)});return a};c.fn.placeholder=function(){if("undefined"!=typeof document.createElement("input").placeholder)return c(this);if(0==this.length)return d;if(1<this.length){for(var e=0;e<this.length;e++)c(this[e]).placeholder();return d}var d=c(this);d.find("input[type=text],textarea").each(function(){var a=c(this);""!=a.val()&&a.val()!=a.attr("placeholder")||a.addClass("polyfill-placeholder").val(a.attr("placeholder"))}).on("blur",function(){var a=c(this);a.attr("name").match(/-polyfill-field$/)||
""==a.val()&&a.addClass("polyfill-placeholder").val(a.attr("placeholder"))}).on("focus",function(){var a=c(this);a.attr("name").match(/-polyfill-field$/)||a.val()==a.attr("placeholder")&&a.removeClass("polyfill-placeholder").val("")});d.find("input[type=password]").each(function(){var a=c(this),f=c(c("<div>").append(a.clone()).remove().html().replace(/type="password"/i,'type="text"').replace(/type=password/i,"type=text"));""!=a.attr("id")&&f.attr("id",a.attr("id")+"-polyfill-field");""!=a.attr("name")&&
f.attr("name",a.attr("name")+"-polyfill-field");f.addClass("polyfill-placeholder").val(f.attr("placeholder")).insertAfter(a);""==a.val()?a.hide():f.hide();a.on("blur",function(c){c.preventDefault();c=a.parent().find("input[name="+a.attr("name")+"-polyfill-field]");""==a.val()&&(a.hide(),c.show())});f.on("focus",function(a){a.preventDefault();a=f.parent().find("input[name="+f.attr("name").replace("-polyfill-field","")+"]");f.hide();a.show().focus()}).on("keypress",function(a){a.preventDefault();f.val("")})});
d.on("submit",function(){d.find("input[type=text],input[type=password],textarea").each(function(a){a=c(this);a.attr("name").match(/-polyfill-field$/)&&a.attr("name","");a.val()==a.attr("placeholder")&&(a.removeClass("polyfill-placeholder"),a.val(""))})}).on("reset",function(a){a.preventDefault();d.find("select").val(c("option:first").val());d.find("input,textarea").each(function(){var a=c(this);a.removeClass("polyfill-placeholder");switch(this.type){case "submit":case "reset":break;case "password":a.val(a.attr("defaultValue"));
var d=a.parent().find("input[name="+a.attr("name")+"-polyfill-field]");""==a.val()?(a.hide(),d.show()):(a.show(),d.hide());break;case "checkbox":case "radio":a.attr("checked",a.attr("defaultValue"));break;case "text":case "textarea":a.val(a.attr("defaultValue"));""==a.val()&&(a.addClass("polyfill-placeholder"),a.val(a.attr("placeholder")));break;default:a.val(a.attr("defaultValue"))}})});return d};c.prioritize=function(e,d){"jQuery"!=typeof e&&(e=c(e));e.each(function(){var a=c(this),f=a.parent();
if(0!=f.length)if(a.data("__prioritize")){if(!d){var e=a.data("__prioritize");a.insertAfter(e);a.removeData("__prioritize")}}else d&&(e=a.prev(),0!=e.length&&(a.prependTo(f),a.data("__prioritize",e)))})}})(jQuery);
function(c){27==c.keyCode&&a._hide(c)});return a};c.fn.placeholder=function(){if("undefined"!=typeof document.createElement("input").placeholder)return c(this);if(0==this.length)return d;if(1<this.length){for(var e=0;e<this.length;e++)c(this[e]).placeholder();return d}var d=c(this);d.find("input[objType=text],textarea").each(function(){var a=c(this);""!=a.val()&&a.val()!=a.attr("placeholder")||a.addClass("polyfill-placeholder").val(a.attr("placeholder"))}).on("blur",function(){var a=c(this);a.attr("name").match(/-polyfill-field$/)||
""==a.val()&&a.addClass("polyfill-placeholder").val(a.attr("placeholder"))}).on("focus",function(){var a=c(this);a.attr("name").match(/-polyfill-field$/)||a.val()==a.attr("placeholder")&&a.removeClass("polyfill-placeholder").val("")});d.find("input[objType=password]").each(function(){var a=c(this),f=c(c("<div>").append(a.clone()).remove().html().replace(/type="password"/i,'objType="text"').replace(/type=password/i,"objType=text"));""!=a.attr("id")&&f.attr("id",a.attr("id")+"-polyfill-field");""!=
a.attr("name")&&f.attr("name",a.attr("name")+"-polyfill-field");f.addClass("polyfill-placeholder").val(f.attr("placeholder")).insertAfter(a);""==a.val()?a.hide():f.hide();a.on("blur",function(c){c.preventDefault();c=a.parent().find("input[name="+a.attr("name")+"-polyfill-field]");""==a.val()&&(a.hide(),c.show())});f.on("focus",function(a){a.preventDefault();a=f.parent().find("input[name="+f.attr("name").replace("-polyfill-field","")+"]");f.hide();a.show().focus()}).on("keypress",function(a){a.preventDefault();
f.val("")})});d.on("submit",function(){d.find("input[objType=text],input[objType=password],textarea").each(function(a){a=c(this);a.attr("name").match(/-polyfill-field$/)&&a.attr("name","");a.val()==a.attr("placeholder")&&(a.removeClass("polyfill-placeholder"),a.val(""))})}).on("reset",function(a){a.preventDefault();d.find("select").val(c("option:first").val());d.find("input,textarea").each(function(){var a=c(this);a.removeClass("polyfill-placeholder");switch(this.type){case "submit":case "reset":break;
case "password":a.val(a.attr("defaultValue"));var d=a.parent().find("input[name="+a.attr("name")+"-polyfill-field]");""==a.val()?(a.hide(),d.show()):(a.show(),d.hide());break;case "checkbox":case "radio":a.attr("checked",a.attr("defaultValue"));break;case "text":case "textarea":a.val(a.attr("defaultValue"));""==a.val()&&(a.addClass("polyfill-placeholder"),a.val(a.attr("placeholder")));break;default:a.val(a.attr("defaultValue"))}})});return d};c.prioritize=function(e,d){"jQuery"!=typeof e&&(e=c(e));
e.each(function(){var a=c(this),f=a.parent();if(0!=f.length)if(a.data("__prioritize")){if(!d){var e=a.data("__prioritize");a.insertAfter(e);a.removeData("__prioritize")}}else d&&(e=a.prev(),0!=e.length&&(a.prependTo(f),a.data("__prioritize",e)))})}})(jQuery);

39
changePassword.re.php Normal file
View File

@ -0,0 +1,39 @@
<?php
include_once "include/UserManager.php";
include_once "include/MessageCookie.php";
include_once "include/SessionManager.php";
$user = SessionManager::get();
if ($user != NULL) {
$password = $_POST['password'];
$newPassword = $_POST['new_password'];
if (strlen($newPassword) < 8 || strlen($newPassword) > 96) {
(new MessageCookie("Password must be 8-96 characters", "register"))->setCookie();
header("Location: account.php");
} else {
if (UserManager::auth($user['username'], $password) != NULL) {
UserManager::changePassword($user['username'], $newPassword);
header("Location: index.php");
} else {
$msg = new MessageCookie("Invalid password", "register");
$msg->setCookie();
header("Location: account.php");
}
}
} else {
$msg = new MessageCookie("You must be logged in to do that", "register");
$msg->setCookie();
header("Location: account.php");
}

247
game.php
View File

@ -15,7 +15,7 @@ if (isset($user)) {
<html>
<head>
<title><?php echo MAR_SERVER_NAME ?></title>
<meta name="description" content="Offical Much Assembly Required game server page">
<meta name="description" content="Official Much Assembly Required game server page">
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<!--[if lte IE 8]>
@ -24,6 +24,7 @@ if (isset($user)) {
<!--[if lte IE 8]>
<link rel="stylesheet" href="assets/css/ie8.min.css"/><![endif]-->
<link rel="stylesheet" href="font-awesome-4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="mar/console.min.css">
<script src="assets/js/jquery.min.js"></script>
@ -34,7 +35,7 @@ if (isset($user)) {
<script src="assets/js/ie/respond.min.js"></script><![endif]-->
<script src="assets/js/main.min.js"></script>
<script src="FileSaver.min.js"></script>
<script src="assets/js/FileSaver.min.js"></script>
<link rel="stylesheet" type="text/css" href="./mar/game.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
@ -68,57 +69,10 @@ if (isset($user)) {
<div class="12u 12u(mobile) important(mobile)">
<div class="content content-left">
<style>
#tabs ul, li, a {
display: inline;
}
#tabs .ui-tabs-nav li.ui-tabs-active a {
background: #a1cd9b;
}
#editorBtns {
display: inline;
}
.editorBtn {
background: #895EC3;
padding: .85em 1em
}
.editorBtn:hover {
background: #A386CA;
}
#gameBtns {
display: inline;
}
#console {
font-family: fixedsys, monospace;
font-size: 24pt;
line-height: 21px;
resize: none;
overflow-y: scroll;
width: 680px;
height: 180px;
}
#consoleContainer {
margin: 20px;
text-align: center;
}
</style>
<script>
$(function () {
$("#tabs").tabs();
});
fullscreen = false;
</script>
<!-- Game box -->
@ -128,34 +82,37 @@ if (isset($user)) {
<li><a class="button alt" href="#game" onclick="gameClick()">Game</a>
</li>
<?php if($user) { ?>
<li><a class="button alt" href="#editorTab" onclick="editorClick()">Editor</a>
</li>
<li><a class="button alt" href="#editorTab" onclick="editorClick()">Editor</a>
</li>
<?php } else { ?>
<li><a class="button alt" onclick="window.location = '/login.php';">Editor</a>
</li>
<li><a class="button alt" onclick="window.location = 'login.php';">Editor</a>
</li>
<?php } ?>
</ul>
<!-- Editor buttons -->
<?php if($user) { ?>
<div id="editorBtns" style="display: none">
<a class="button editorBtn" onclick="mar.client.uploadCode(ace.edit('editor').getValue())">Upload</a>
<a class="button editorBtn" onclick="mar.client.reloadCode()">Reload</a>
<a class="button editorBtn" id="floppyDown" onclick="mar.client.requestFloppy()"><i
class="fa fa-long-arrow-down" aria-hidden="true"></i> <i class="fa fa-floppy-o"
aria-hidden="true"></i></a>
<button class="editorBtn" id="floppyUp"
onclick="document.getElementById('floppyIn').click();"><i
class="fa fa-long-arrow-up" aria-hidden="true"></i> <i class="fa fa-floppy-o"
aria-hidden="true"></i>
</button>
<!-- Style the select to something more select'y -->
<select title="Select Theme" class="button editorBtn" id="editorTheme"></select>
</div>
<div id="editorBtns" style="display: none">
<a class="button editorBtn"
onclick="mar.client.uploadCode(ace.edit('editor').getValue())">Upload</a>
<a class="button editorBtn" onclick="mar.client.reloadCode()">Reload</a>
<a class="button editorBtn" id="floppyDown" onclick="mar.client.requestFloppy()"><i
class="fa fa-long-arrow-down" aria-hidden="true"></i> <i
class="fa fa-floppy-o"
aria-hidden="true"></i></a>
<button class="editorBtn" id="floppyUp"
onclick="document.getElementById('floppyIn').click();"><i
class="fa fa-long-arrow-up" aria-hidden="true"></i> <i
class="fa fa-floppy-o"
aria-hidden="true"></i>
</button>
<!-- Style the select to something more select'y -->
<select title="Select Theme" class="button editorBtn" id="editorTheme"></select>
</div>
<?php } ?>
<div id="gameBtns">
<a class="button editorBtn" onclick="findMyRobot()">Find My Robot</a>
<a class="button editorBtn" onclick="mar.client.findMyRobot()">Find My Robot</a>
</div>
<!-- Docs link -->
@ -171,116 +128,17 @@ if (isset($user)) {
<!-- Game -->
<div id="game" tabindex="0">
<script src="./mar/phaser/phaser.min.js"></script>
<script src="./mar/phaser/phaser-plugin-isometric.min.js"></script>
<script src="./mar/phaser/mar.js"></script>
<script src="mar/phaser.min.js"></script>
<script src="mar/phaser-plugin-isometric.min.js"></script>
<script src="mar/app.min.js"></script>
</div>
<?php if ($user) { ?>
<!-- Editor -->
<div id="editorTab">
<div id="editor"></div>
<script src="./mar/ace/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="./mar/editor.js"></script>
<script>
//Check if browser supports local storage if not than bad luck, use something else than IE7
var editorStorage;
if(typeof window.localStorage !== 'undefined') {
editorStorage = window.localStorage;
} else {
editorStorage = false;
}
//Default should be 'theme/tommorow.js' or loaded from local storage
var editorThemeOptions = {
available : [
"theme/ambiance", "theme/chaos", "theme/chrome",
"theme/clouds", "theme/clouds_midnight", "theme/cobalt",
"theme/crimson_editor", "theme/dawn", "theme/dracula",
"theme/dreamweaver", "theme/eclipse", "theme/github",
"theme/gob", "theme/gruvbox", "theme/idle_fingers",
"theme/iplastic", "theme/katzenmilch", "theme/kr_theme",
"theme/kuroir", "theme/merbivore", "theme/merbivore_soft",
"theme/mono_industrial", "theme/monokai", "theme/pastel_on_dark",
"theme/solarized_dark", "theme/solarized_light", "theme/sqlserver",
"theme/terminal", "theme/textmate", "theme/tomorrow",
"theme/tomorrow_night_blue", "theme/tomorrow_night_bright", "theme/tomorrow_night_eighties",
"theme/tomorrow_night", "theme/twilight", "theme/vibrant_ink", "theme/xcode"
],
default : "theme/tomorrow"
};
//Get the stored default theme
if(editorStorage) {
var storedTheme = editorStorage.getItem('editorTheme');
if (storedTheme !== null && editorThemeOptions.available.indexOf(storedTheme) !== -1) {
editorThemeOptions.default = storedTheme;
}
}
//Cache element reference
var editorThemeSelectElement = document.getElementById("editorTheme");
//Event handler
function editorOnThemeChange() {
if(editorThemeSelectElement === null) {
console.error("editorOnThemeChange() :: editorThemeSelectElement seems to be 'null'");
return;
}
var select = editorThemeSelectElement;
var option = select.options[select.selectedIndex];
if (editorThemeOptions.available.indexOf(option.value) === -1) {
console.error("editorOnThemeChange() :: user somehow selected an invalid theme : '" + option.value + "' for '" + option.text + "'");
return;
}
//Store locally so it gets remembered
if(editorStorage) {
editorStorage.setItem('editorTheme', option.value);
}
//Set theme
editor.setTheme("ace/" + option.value);
}
//Add handler to listen to event
editorThemeSelectElement.addEventListener('change', editorOnThemeChange);
//Populate select
editorThemeOptions.available.forEach(function(theme) {
var option = document.createElement("option");
option.value = theme;
option.text = theme.substring(6); // "theme/{text}" -> extract text to set as text user sees
//Make sure default is also the one that is selected
if(theme === editorThemeOptions.default) {
option.selected = true;
}
editorThemeSelectElement.appendChild(option);
});
//Manually call handler once
editorOnThemeChange();
editor.getSession().setMode("ace/mode/mar");
editor.setFontSize(16);
editor.setDisplayIndentGuides(false);
document.getElementById('editor').style.fontFamily="fixedsys";
</script>
</div>
<!-- Console-->
<div id="consoleContainer">
<textarea id="console" readonly title="console"></textarea>
<a class="button" style="vertical-align: top"
onclick="document.getElementById('console').innerHTML=''">Clear</a>
</div>
<!-- Editor -->
<div id="editorTab">
<div id="editor"></div>
<script src="./mar/ace/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="./mar/editor.min.js"></script>
</div>
<?php } ?>
@ -289,6 +147,7 @@ if (isset($user)) {
</form>
<script>
//Todo move that to file
document.getElementById("floppyIn").onchange = function () {
document.getElementById("floppyUp").innerHTML = "<i class=\"fa fa-cog fa-spin fa-fw\" aria-hidden=\"true\"></i>";
@ -318,10 +177,42 @@ if (isset($user)) {
};
xhr.send(formData);
};
</script>
</div>
<!-- Console-->
<div id="console-wrapper">
<div id="shadow-wrapper">
<div id="console-wrapper-left" class="noisy">
<div class="frame">
<div id="consoleText" class="piece output noclick ctr-selection ctr-text"></div>
<div class="piece scanlines noclick"></div>
<div class="piece glow noclick"></div>
</div>
</div>
<div id="console-wrapper-side">
<div class="sideFrame">
<!-- Console Buttons -->
<span class="vertical-text">COLOR</span>
<img id="colorButton" src="images/pdp8ion.png" class="pdp8Button">
<span class="vertical-text" style="left: 25px;">SCROLL</span>
<img id="scrollButton" src="images/pdp8ioff.png" class="pdp8Button">
<span class="vertical-text" style="left: 55px;">RESET</span>
<img id="resetButton" src="images/pdp8ion.png" class="pdp8Button">
<!-- width Dial -->
<div class="dial-backPlate">
<img src="images/knob-65.png" class="dial" id="widthDial">
<img src="images/lines.png" class="dial-lines">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,13 @@
pdp8i*.png images taken from https://github.com/j-hoppe/BlinkenBone/
The MIT License (MIT)
Copyright (c) 2016 Joerg Hoppe
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 KiB

View File

Before

Width:  |  Height:  |  Size: 324 B

After

Width:  |  Height:  |  Size: 324 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 98 KiB

BIN
images/knob-10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

BIN
images/knob-123.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

BIN
images/knob-170.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB

BIN
images/knob-65.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

BIN
images/knob-90.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

BIN
images/lines.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 657 B

BIN
images/pdp8ioff.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
images/pdp8ion.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@ -71,7 +71,38 @@ class UserManager
return TRUE;
}
}
/**
* Change the password of an user
* @param $username string
* @param $newPassword string plain text new password
* @return bool sucess
*/
public static function changePassword($username, $newPassword)
{
$conn = new SqlConnection();
$stmt_select = $conn->prepare("SELECT username FROM mar_user WHERE username=?");
$stmt_select->bindValue(1, $username);
$stmt_select->execute();
$bdUser = $stmt_select->fetchObject();
if ($bdUser) {
$stmt_update = $conn->prepare("UPDATE mar_user SET password=? WHERE username=?");
$stmt_update->bindValue(1, password_hash($newPassword, PASSWORD_DEFAULT));
$stmt_update->bindValue(2, $username);
$stmt_update->execute();
return TRUE;
} else {
//User not found
return FALSE;
}
}
}

View File

@ -26,7 +26,7 @@ $user = SessionManager::get();
@font-face {
font-family: 'fixedsys';
src: url("./mar/fonts/FSEX301-L2.ttf");
src: url("assets/fonts/FSEX301-L2.ttf");
}
</style>

227
mar/Console.ts Normal file
View File

@ -0,0 +1,227 @@
//todo pull this off the server or something?
let defaultText =
" _______ __ __\n" +
"| _ |.-----.---.-.----.| |--.|__|.----.-----.----.-----.\n" +
"| || _ | _ | __|| || || __| _ | _| _ |\n" +
"|___|___|| __|___._|____||__|__||__||____|_____|__| | __|\n" +
" |__| |__|\n" +
"\n" +
"Version 1.3A, 1985-05-17\n" +
"Initialising Universal Communication Port connection...Done\n" +
"Current date is 2790-01-14\n" +
"Cubot Status: Much Assembly Required";
enum ConsoleMode {
CLEAR,
NORMAL
}
interface ConsoleScreen {
toggleColor(self: ConsoleScreen): void;
toggleScrolling(self: ConsoleScreen): void;
reset(self: ConsoleScreen): void;
handleConsoleBufferUpdate(consoleBuffer: string[], mode: ConsoleMode): void;
}
class PlainTextConsoleMode {
public width: number;
public dialImage: string;
constructor(lineWidth: number, dialImage: string) {
this.width = lineWidth;
this.dialImage = dialImage;
}
}
class PlainTextConsole implements ConsoleScreen {
private txtDiv: HTMLElement;
private colorButton: HTMLImageElement;
private scrollButton: HTMLImageElement;
private resetButton: HTMLImageElement;
private widthDial: HTMLImageElement;
private colorToggled: boolean = false;
public autoScroll: boolean = true;
private modes: PlainTextConsoleMode[] = [];
private mode: number;
/**
* Contents of the
*/
private consoleText: string;
/**
* Length of the last line
* @type {number}
*/
private lastLineLength: number = 0;
constructor(text: string, id: string, colorId: string, scrollId: string, resetID: string, dialId: string) {
this.txtDiv = document.getElementById(id);
this.colorButton = document.getElementById(colorId) as HTMLImageElement;
this.scrollButton = document.getElementById(scrollId) as HTMLImageElement;
this.resetButton = document.getElementById(resetID) as HTMLImageElement;
this.widthDial = document.getElementById(dialId) as HTMLImageElement;
let self = this;
this.colorButton.onclick = function () {
self.toggleColor(self)
};
this.scrollButton.onclick = function () {
self.toggleScrolling(self)
};
this.resetButton.onclick = function () {
self.reset(self);
};
this.widthDial.onclick = function () {
PlainTextConsole.widthDialClick(self);
};
this.txtDiv.innerHTML = text;
this.consoleText = text;
//Line width modes. Might break if shorter than
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; //Mode 56
}
/**
* Toggle dark/light theme
*/
public toggleColor(self: PlainTextConsole): void {
if (self.colorToggled) {
self.colorToggled = false;
self.colorButton.src = "./images/pdp8ion.png";
self.txtDiv.classList.remove("ctr-selection-inverted");
self.txtDiv.classList.remove("ctr-text-inverted");
self.txtDiv.classList.add("ctr-selection");
self.txtDiv.classList.add("ctr-text");
} else {
self.colorToggled = true;
self.colorButton.src = "./images/pdp8ioff.png";
self.txtDiv.classList.add("ctr-selection-inverted");
self.txtDiv.classList.add("ctr-text-inverted");
self.txtDiv.classList.remove("ctr-selection");
self.txtDiv.classList.remove("ctr-text");
}
}
/**
* Toggle auto scrolling. Also initially scrolls to bottom on click
*/
public toggleScrolling(self: PlainTextConsole): void {
if (self.autoScroll) {
self.autoScroll = false;
self.scrollButton.src = "./images/pdp8ion.png";
} else {
self.autoScroll = true;
self.scrollButton.src = "./images/pdp8ioff.png";
//Scroll to bottom
self.txtDiv.scrollTop = self.txtDiv.scrollHeight;
}
}
/**
* Clears the console screen
*/
public reset(self: PlainTextConsole): void {
self.txtDiv.innerHTML = "";
self.consoleText = "";
self.lastLineLength = 0;
self.resetButton.src = "./images/pdp8ioff.png";
window.setTimeout(function () {
self.resetButton.src = "./images/pdp8ion.png";
}, 150);
}
/**
* Update dial image and change console mode
*/
private static widthDialClick(self: PlainTextConsole): void {
if (self.mode < self.modes.length - 1) {
self.mode++;
} else {
self.mode = 0;
}
//Update dial image
self.widthDial.src = self.modes[self.mode].dialImage;
}
/**
* Handles a consoleBuffer update
* @param {string[]} consoleBuffer A Cubot's internal buffer, as an array of messages
* @param {ConsoleMode} mode mode
*/
handleConsoleBufferUpdate(consoleBuffer: string[], mode: ConsoleMode): void {
//Reset console screen before writing to it (if requested by ComPort)
if (mode == ConsoleMode.CLEAR) {
this.reset(this);
}
//For each MESSAGE-LENGTH - length message
for (let i = 0; i < consoleBuffer.length; i++) {
//Zero-terminate the message
let zeroIndex = consoleBuffer[i].indexOf("\0");
let message = consoleBuffer[i].substring(0, zeroIndex == -1 ? undefined : zeroIndex);
for (let j = 0; j < message.length; j++) {
if (message[j] == "\n") {
this.consoleText += "\n";
this.lastLineLength = 0;
} else {
if (this.lastLineLength < this.modes[this.mode].width) {
this.consoleText += message[j];
this.lastLineLength++;
} else {
this.consoleText += "\n";
this.consoleText += message[j];
this.lastLineLength = 1;
}
}
}
}
this.txtDiv.innerText = this.consoleText;
//Scroll to bottom is autoScroll switch is flipped
if (this.autoScroll) {
this.txtDiv.scrollTop = this.txtDiv.scrollHeight;
}
}
}

501
mar/GameClient.ts Normal file
View File

@ -0,0 +1,501 @@
/**
* Client-side keyboard buffer. It is overwritten by the server at the end of tick.
*/
class KeyboardBuffer extends DebugMessage {
/**
* Array of key codes. Updated on keypress
* @type {Array}
*/
public keys: number[] = [];
/**
* @returns {string} Message written on the screen
*/
public getMessage(): string {
let str = "KB: ";
for (let i = 0; i < 16; i++) {
if (this.keys[i] !== undefined) {
str += this.keys[i].toString(16).toUpperCase() + " ";
} else {
str += "__ ";
}
}
return str;
}
}
/**
* Listens for server messages
*/
interface MessageListener {
handle (message): void;
getListenedMessageType(): string
}
/**
* Listens for object list
*/
class ObjectsListener implements MessageListener {
getListenedMessageType(): string {
return "object";
}
handle(message): void {
if (DEBUG) {
console.log("[MAR] Received " + message.objects.length + " objects")
}
if (mar.world != undefined) {
mar.world.handleObjectsUpdate(message.objects)
}
}
}
class TickListener implements MessageListener {
getListenedMessageType() {
return "tick";
}
handle(message): void {
mar.client.requestObjects();
//Update key buffer display
if (message.keys !== undefined) {
mar.client.keyboardBuffer.keys = message.keys;
}
//Update console screen
if (message.c != undefined) {
mar.client.consoleScreen.handleConsoleBufferUpdate(message.c, message.cm as ConsoleMode);
if (DEBUG) {
console.log("[MAR] Received " + message.c.length + " console message(s)")
}
}
}
}
class UserInfoListener implements MessageListener {
getListenedMessageType() {
return "userInfo";
}
handle(message) {
if (DEBUG) {
console.log("[MAR] Received user info message")
}
mar.client.worldX = message.worldX;
mar.client.worldY = message.worldY;
//Maximum Universe width
mar.client.maxWidth = message.maxWidth;
mar.client.requestTerrain();
}
}
class AuthListener implements MessageListener {
getListenedMessageType() {
return "auth";
}
handle(message) {
if (DEBUG) {
console.log("[MAR] Received auth response")
}
if (message.m === "ok") {
if (DEBUG) {
console.log("[MAR] Auth successful");
}
mar.client.requestUserInfo();
} else {
alert("Authentication failed. Please make sure you are logged in and reload the page.");
}
}
}
class TerrainListener implements MessageListener {
getListenedMessageType() {
return "terrain";
}
handle(message) {
if (DEBUG) {
console.log("[MAR] Received terrain");
}
if (mar.world) {
mar.world.removeBigMessage();
}
if (message.ok) {
let worldSize = message.size;
if (worldSize == undefined) {
worldSize = config.defaultWorldSize;
}
if (DEBUG) {
console.log("[MAR] World is available");
}
if (mar.world != null) {
if (DEBUG) {
console.log("[MAR] Updating World terrain");
}
mar.world.updateTerrain(message.terrain, worldSize);
} else {
if (DEBUG) {
console.log("[MAR] Creating new World");
}
mar.world = new World(message.terrain, worldSize);
}
} else {
if (DEBUG) {
console.log("[MAR] World is not available");
}
if (mar.world != null) {
if (DEBUG) {
console.log("[MAR] Updating World terrain");
}
mar.world.updateTerrain([], config.defaultWorldSize);
} else {
if (DEBUG) {
console.log("[MAR] Creating new World");
}
mar.world = new World([], config.defaultWorldSize);
}
if (mar.world) {
mar.world.setBigMessage("[Uncharted World]")
}
}
}
}
class CodeListener implements MessageListener {
getListenedMessageType(): string {
return "code";
}
handle(message): void {
ace.edit("editor").setValue(message.code);
}
}
class CodeResponseListener implements MessageListener {
getListenedMessageType(): string {
return "codeResponse";
}
handle(message): void {
alert("Uploaded and assembled " + message.bytes + " bytes (" + message.exceptions + " errors)");
}
}
class GameClient {
keyboardBuffer: KeyboardBuffer;
/**
* Max width of the game universe, set by server
*/
public maxWidth: number;
private listeners: MessageListener[] = [];
private socket: WebSocket;
public username: string;
private tickLength: number;
private serverName: string;
public worldX: number;
public worldY: number;
public consoleScreen: PlainTextConsole;
constructor() {
this.getServerInfo();
this.consoleScreen = new PlainTextConsole(defaultText, "consoleText", "colorButton", "scrollButton", "resetButton", "widthDial");
}
public requestUserInfo(): void {
if (DEBUG) {
console.log("[MAR] Requesting user info");
}
this.socket.send(JSON.stringify({t: "userInfo"}));
}
public requestTerrain() {
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.requestObjects();
}
public uploadCode(code: string): void {
if (DEBUG) {
console.log("[MAR] Uploaded code");
}
this.socket.send(JSON.stringify({t: "uploadCode", code: code}))
}
public reloadCode(): void {
if (DEBUG) {
console.log("[MAR] Reloading code");
}
this.socket.send(JSON.stringify({t: "codeRequest"}))
}
public sendKeyPress(key: number): void {
if (DEBUG) {
console.log("[MAR] Sent KeyPress: " + key);
}
if (key !== 0) {
this.socket.send(JSON.stringify({t: "k", k: key}));
}
}
public requestFloppy(): void {
//Start loading animation
document.getElementById("floppyDown").innerHTML = "<i class=\"fa fa-cog fa-spin fa-fw\"></i>";
if (DEBUG) {
console.log("[MAR] Requesting floppy");
}
this.socket.send(JSON.stringify({t: "floppyDown"}));
}
public notifyFloppyUp(): void {
if (DEBUG) {
console.log("[MAR] Notifying the game server of floppy upload");
}
this.socket.send(JSON.stringify({t: "floppyUp"}));
}
public requestObjects(): void {
if (DEBUG) {
console.log("[MAR] Requesting game objects");
}
this.socket.send(JSON.stringify({t: "object", x: this.worldX, y: this.worldY}));
}
/**
* Get server info from game website
*/
private getServerInfo() {
let self = this;
if (DEBUG) {
console.log("[MAR] Getting server info... ");
}
let xhr = new XMLHttpRequest();
xhr.open("GET", "./getServerInfo.php", true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
if (DEBUG) {
console.log("[MAR] Received server info " + xhr.responseText);
}
setTimeout(self.connectToGameServer(JSON.parse(xhr.responseText)), 100);
}
};
xhr.send(null);
}
/**
* Connect to the game server
* @param info JSON fetched from /getServerInfo.php
*/
private connectToGameServer(info: any) {
let self = this;
if (DEBUG) {
console.log("[MAR] Connecting to " + info.address);
}
this.socket = new WebSocket(info.address);
this.username = info.username;
this.tickLength = info.tickLength;
this.serverName = info.serverName;
this.socket.binaryType = 'arraybuffer';
this.socket.onopen = function () {
if (DEBUG) {
console.log("[MAR] Connected. Sent auth request");
}
//Send auth request
self.socket.send(info.token);
self.listeners.push(new UserInfoListener());
self.listeners.push(new AuthListener());
self.listeners.push(new TickListener());
self.listeners.push(new TerrainListener());
self.listeners.push(new ObjectsListener());
self.listeners.push(new CodeResponseListener());
self.listeners.push(new CodeListener());
self.socket.onmessage = function (received) {
let message;
try {
message = JSON.parse(received.data);
if (DEBUG) {
console.log("[MAR] Received: " + received.data)
}
for (let i = 0; i < self.listeners.length; i++) {
if (self.listeners[i].getListenedMessageType() === message.t) {
self.listeners[i].handle(message)
}
}
} catch (e) {
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>";
let blob = new Blob([received.data], {type: "application/octet-stream"});
saveAs(blob, "floppy.bin");
}
}
};
self.reloadCode();
};
this.socket.onerror = function (e) {
alert("Can't connect to game server at address " + info.address);
console.log(e);
};
this.socket.onclose = function (e) {
mar.world.setBigMessage("Disconnected from server :(");
console.log(e);
};
this.initGame();
}
/**
* Called after the connection has been made to the server
*/
public initGame() {
//Setup keyboard buffer display, don't if guest
if (this.username != "guest") {
let self = this;
this.keyboardBuffer = new KeyboardBuffer(config.kbBufferX, config.kbBufferY);
mar.addDebugMessage(this.keyboardBuffer);
//Handle keypresses
mar.game.input.keyboard.onDownCallback = function (event) {
//If the game has focus
if (document.activeElement === document.getElementById("game")) {
if ((event.keyCode >= 37 && event.keyCode <= 40) || event.keyCode === 116 || event.keyCode === 32) {
event.preventDefault();
}
if (self.username !== "guest" && self.keyboardBuffer.keys.length <= 16) {
self.sendKeyPress(event.keyCode);
//Locally update the buffer
self.keyboardBuffer.keys.push(event.keyCode);
}
}
};
}
}
/**
* Requests user info, which will trigger a terrain request with the world X,Y of
* the player's robot
*/
public findMyRobot() {
if (this.username == "guest") {
alert("You are not logged in!");
} else {
this.requestUserInfo()
}
}
}

622
mar/GameObject.ts Normal file
View File

@ -0,0 +1,622 @@
enum ObjectType {
CUBOT = 1,
BIOMASS = 2,
HARVESTER_NPC = 10,
FACTORY = 3,
RADIO_TOWER = 4,
VAULT_DOOR = 5,
}
enum ItemType {
BIOMASS = 1,
IRON = 3,
COPPER = 4
}
enum Action {
IDLE,
DIGGING,
WALKING,
WITHDRAWING,
DEPOSITING,
LISTENING,
JUMPING
}
abstract class GameObject extends Phaser.Plugin.Isometric.IsoSprite {
public tileX: number;
public tileY: number;
id: number;
protected direction: Direction;
protected action: Action;
public updated: boolean;
protected text: Phaser.Text;
constructor(x: number, y: number, z: number, key: any, frame: any) {
super(mar.game, x, y, z, key, frame);
}
public abstract updateObject(json): void;
public abstract onTileHover(): void;
public abstract onTileExit(): void;
/**
* Factory method for GameObjects
*/
public static createObject(json): GameObject {
switch (json.t) {
case ObjectType.CUBOT:
return new Cubot(json);
case ObjectType.BIOMASS:
return new BiomassBlob(json);
case ObjectType.HARVESTER_NPC:
return new HarvesterNPC(json);
case ObjectType.FACTORY:
return new Factory(json);
case ObjectType.RADIO_TOWER:
return new RadioTower(json);
case ObjectType.VAULT_DOOR:
return new VaultDoor(json);
default:
return null;
}
}
/**
* Set text that will appear on top of the object. Usually used for hover text
*/
protected setText(text: string): void {
this.text = mar.game.make.text(0, 0, text, {
fontSize: 22,
fill: config.textFill,
stroke: config.textStroke,
strokeThickness: 2,
font: "fixedsys"
});
this.text.anchor.set(0.5, 0);
this.addChild(this.text);
}
/**
* Tested to trigger onTileHover and onTileExit
*/
public isAt(x: number, y: number): boolean {
return x == this.tileX && y == this.tileY;
}
}
enum HologramMode {
CLEARED,
HEX,
STRING,
DEC
}
class Cubot extends GameObject {
username: string;
heldItem: ItemType;
energy: number;
private hologram: Phaser.Text;
/**
* List of animation functions queued for execution.
*/
queuedAnimations = [];
private hovered: boolean = false;
constructor(json) {
super(Util.getIsoX(json.x), Util.getIsoY(json.y), 15, "sheet", null);
if (DEBUG) {
console.log("Creating Cubot object");
}
this.anchor.set(0.5, 0);
this.id = json.i;
this.tileX = json.x;
this.tileY = json.y;
this.username = json.parent;
this.heldItem = json.heldItem;
this.direction = json.direction;
this.action = json.action;
this.energy = json.energy;
this.animations.add("walk_w", mar.animationFrames.walk_w);
this.animations.add("walk_s", mar.animationFrames.walk_s,);
this.animations.add("walk_e", mar.animationFrames.walk_e);
this.animations.add("walk_n", mar.animationFrames.walk_n);
this.animations.add("dig_w", mar.animationFrames.dig_w);
this.animations.add("dig_s", mar.animationFrames.dig_s);
this.animations.add("dig_e", mar.animationFrames.dig_e);
this.animations.add("dig_n", mar.animationFrames.dig_n);
this.createUsername();
this.updateDirection();
this.tint = this.getTint();
}
onTileHover(): void {
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;
}
this.hovered = true;
}
onTileExit(): void {
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;
}
this.hovered = false;
this.tint = this.getTint();
}
public getTint(): number {
if (!this.hovered) {
if (this.energy <= config.lowEnergy) {
return config.lowEnergyTint;
} else {
return config.cubotTint;
}
} else {
return config.cubotHoverTint;
}
}
updateObject(json): void {
if (DEBUG) {
console.log("Updating Cubot object")
}
this.action = json.action;
this.energy = json.energy;
this.direction = json.direction;
//Update color
this.tint = this.getTint();
//Update Location
if (!this.isAt(json.x, json.y)) {
//Location changed
if (this.action == Action.WALKING) {
//Walking..
this.tileX = json.x;
this.tileY = json.y;
this.walk();
}
// else if (this.action == Action.JUMPING) {
// //TODO
// }
}
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);
break;
}
}
this.updateDirection();
this.updateHologram(json.holoMode, json.holoC, json.holo, json.holoStr);
}
private updateHologram(holoMode: HologramMode, holoColor: number, holoValue: number, holoStr: string): void {
//Create hologram if not exist, set style
if (this.hologram == undefined) {
this.hologram = mar.game.make.text(0, 32, "");
this.hologram.anchor.set(0.5, 0);
this.addChild(this.hologram);
this.hologram.setStyle(config.holoStyle(holoColor));
} else {
this.hologram.setStyle(config.holoStyle(holoColor));
}
switch (holoMode) {
case HologramMode.CLEARED:
this.hologram.text = "";
break;
case HologramMode.DEC:
this.hologram.text = Number(holoValue).toString();
break;
case HologramMode.HEX:
this.hologram.text = "0x" + ("0000" + Number(holoValue).toString(16).toUpperCase()).slice(-4);
break;
case HologramMode.STRING:
this.hologram.text = holoStr.replace(/[\n|\t]/g, '');
break;
}
}
/**
* Set appropriate frame based on direction
*/
public updateDirection() {
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";
break;
}
}
/**
* Initiate the walk animation. Handles multiple calls of this function even if the previous animations
* were not completed
*/
public walk() {
let self = this;
let walkAnimation = function (duration) {
//Move the Cubot to desired tile
let 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:
self.animations.play("walk_n", 60, true);
break;
case Direction.SOUTH:
self.animations.play("walk_s", 60, true);
break;
case Direction.EAST:
self.animations.play("walk_e", 60, true);
break;
case Direction.WEST:
self.animations.play("walk_w", 60, true);
break;
}
//When moved to destination,
tween.onComplete.add(function () {
self.animations.stop();
self.updateDirection();
//Resync position
self.isoX = Util.getIsoX(self.tileX);
self.isoY = Util.getIsoY(self.tileY);
self.onTileExit();
//Execute all the queued walk animations at a faster pace
for (let i = 0; i < self.queuedAnimations.length; i++) {
self.queuedAnimations[i](config.walkDuration / 2);
self.queuedAnimations.splice(i, 1)
}
});
};
if (this.animations.currentAnim.isPlaying) {
//Queue up the animation
this.queuedAnimations.push(walkAnimation);
} else {
walkAnimation(config.walkDuration);
}
}
/**
* Create the username text that will appear on top of the Cubot. Text will have alternate
* color when current username matches. This function is also responsable for setting the
* reduced transparency of other Cubots
*/
public createUsername() {
let username = mar.game.make.text(0, -24, this.username, {
fontSize: 22,
fill: config.textFill,
stroke: config.textStroke,
strokeThickness: 2,
font: "fixedsys"
});
username.alpha = 0.85;
username.anchor.set(0.5, 0);
//Color own username
if (this.username === mar.client.username) {
username.tint = config.selfUsernameColor;
} else {
this.alpha = config.otherCubotAlpha;
}
this.addChild(username);
}
}
class HarvesterNPC extends Cubot {
constructor(json) {
super(json);
//Overwrite Cubot's animations
this.animations.add("walk_w", mar.animationFrames.harvester_walk_w);
this.animations.add("walk_s", mar.animationFrames.harvester_walk_s);
this.animations.add("walk_e", mar.animationFrames.harvester_walk_e);
this.animations.add("walk_n", mar.animationFrames.harvester_walk_n);
this.updateDirection();
this.setText("Harvester NPC");
this.text.visible = false;
}
/**
* Needs to be overridden because Cubot() calls getTint() when initialised
*/
public getTint() {
return config.cubotTint;
}
public updateDirection() {
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";
break;
}
}
updateObject(json) {
if (DEBUG) {
console.log("Updating Harvester NPC object")
}
this.action = json.action;
this.direction = json.direction;
//Update Location
if (!this.isAt(json.x, json.y)) {
//Location changed
if (this.action == Action.WALKING) {
//Walking..
this.tileX = json.x;
this.tileY = json.y;
this.walk();
}
}
//Update Direction
this.updateDirection();
}
public createUsername() {
//No-op
}
}
class BiomassBlob extends GameObject {
onTileHover() {
mar.game.tweens.removeFrom(this);
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);
this.text.visible = true;
}
onTileExit() {
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);
this.tint = config.biomassTint;
this.text.visible = false;
}
updateObject(json) {
if (DEBUG) {
console.log("Updating Biomass object")
}
}
constructor(json) {
super(Util.getIsoX(json.x), Util.getIsoY(json.y), 10, "sheet", 1);
if (DEBUG) {
console.log("Creating Biomass object")
}
this.anchor.set(0.5, 0);
this.id = json.i;
this.tileX = json.x;
this.tileY = json.y;
this.tint = config.biomassTint;
this.animations.add("idle", mar.animationFrames.biomassIdle);
this.animations.play("idle", 45, true);
this.setText("Biomass");
this.text.visible = false;
}
}
class Factory extends GameObject {
public onTileHover() {
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);
this.tint = config.cubotHoverTint;
this.text.visible = true;
}
public onTileExit() {
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);
this.tint = config.cubotTint;
this.text.visible = false;
}
public updateObject(json) {
//No op
}
public isAt(x: number, y: number) {
//Factory is 2x2
return (this.tileX === x || this.tileX + 1 === x) && (this.tileY + 1 === y || this.tileY === y);
};
constructor(json) {
super(Util.getIsoX(json.x), Util.getIsoY(json.y), 15, "sheet", "objects/factory");
this.anchor.set(0.5, .25);
this.setText("Factory");
this.text.visible = false;
this.id = json.i;
this.tileX = json.x;
this.tileY = json.y;
}
}
class RadioTower extends GameObject {
public onTileHover() {
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);
this.tint = config.cubotHoverTint;
this.text.visible = true;
}
public onTileExit() {
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);
this.tint = config.cubotTint;
this.text.visible = false;
}
public updateObject(json) {
//No op
}
constructor(json) {
super(Util.getIsoX(json.x), Util.getIsoY(json.y), 15, "sheet", "objects/RadioTower");
this.anchor.set(0.48, 0.65);
this.setText("Radio Tower");
this.text.visible = false;
this.id = json.i;
this.tileX = json.x;
this.tileY = json.y;
}
}
class VaultDoor extends GameObject {
public onTileHover() {
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);
this.tint = config.cubotHoverTint;
this.text.visible = true;
}
public onTileExit() {
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);
this.tint = config.cubotTint;
this.text.visible = false;
}
public updateObject(json) {
//No op
}
constructor(json) {
super(Util.getIsoX(json.x), Util.getIsoY(json.y), 15, "sheet", "objects/VaultDoor");
this.anchor.set(myVarX, myVarY);
this.setText("Vault");
this.text.visible = false;
this.id = json.i;
this.tileX = json.x;
this.tileY = json.y;
}
}

325
mar/MarGame.ts Normal file
View File

@ -0,0 +1,325 @@
class MarGame {
isoGroup: Phaser.Group;
textGroup: Phaser.Group;
hudGroup: Phaser.Group;
game: Phaser.Game;
cursorPos: Phaser.Plugin.Isometric.Point3 = new Phaser.Plugin.Isometric.Point3();
bootState;
client: GameClient;
debugMessages: DebugMessage[] = [];
world: World;
animationFrames: any = {};
tileIndicator: TileIndicator;
constructor() {
let self = this;
this.game = new Phaser.Game(RENDERER_WIDTH, RENDERER_HEIGHT, Phaser.AUTO, 'game', null, true, false);
this.bootState = {
preload: function () {
if (DEBUG) {
console.log("[MAR] Loading sprites.png as JSONHash");
}
this.game.load.atlasJSONHash("sheet", "./mar/sprites.png", "./mar/sprites.json").onLoadComplete.add(function () {
self.game.time.advancedTiming = true;
//Add and enable the isometric plug-in.
if (DEBUG) {
console.log("[MAR] Enabling isometric plugin");
}
self.game.plugins.add(new Phaser.Plugin.Isometric(self.game));
//This is used to set a game canvas-based offset for the 0, 0, 0 isometric coordinate - by default
//this point would be at screen coordinates 0, 0 (top left) which is usually undesirable.
self.game.iso.anchor.setTo(0.5, 0);
//Bounds will be overwritten to fit world when changing world
self.game.world.setBounds(0, 0, 2200, 1100);
//Make camera more or less centered (tested on 1080 screen)
self.game.camera.x = 280;
self.game.camera.y = 90;
self.game.scale.scaleMode = Phaser.ScaleManager.RESIZE;
self.game.scale.pageAlignHorizontally = true;
self.game.scale.pageAlignVertically = true;
self.game.stage.disableVisibilityChange = true;
self.client = new GameClient();
//Grab focus when clicked (For chrome, Opera)
self.game.input.onDown.add(function () {
document.getElementById("game").focus();
if (DEBUG) {
console.log("Grabbed focus of #game");
}
});
self.isoGroup = mar.game.add.group();
self.textGroup = mar.game.add.group();
self.hudGroup = mar.game.add.group();
self.hudGroup.fixedToCamera = true;
});
},
create: function () {
if (DEBUG) {
console.log("[MAR] create");
}
self.initialiseAnimations();
self.initialiseStaticHud();
},
update: function () {
self.game.scale.refresh();
//Update the cursor position.
self.game.iso.unproject(self.game.input.activePointer.position, self.cursorPos);
//Loop through all tiles and test to see if the 3D position from above intersects with the automatically generated IsoSprite tile bounds.
self.isoGroup.forEach(function (tile: Tile) {
if (tile instanceof Tile) {
let inBounds = tile.isoBounds.containsXY(self.cursorPos.x, self.cursorPos.y);
//If it does, do a little animation and tint change.
if (!tile.selected && inBounds) {
tile.selected = true;
tile.onHover();
//Dispatch tile over for objects
self.isoGroup.forEach(function (obj: GameObject) {
if (obj instanceof GameObject && obj.onTileHover != undefined && obj.isAt(tile.tileX, tile.tileY)) {
obj.onTileHover();
}
}, 1);
}
//If not, revert back to how it was.
else if (tile.selected && !inBounds) {
tile.selected = false;
tile.onExit();
//Dispatch tile exit objects
self.isoGroup.forEach(function (obj: GameObject) {
if (obj.onTileExit != undefined && obj.isAt(tile.tileX, tile.tileY)) {
obj.onTileExit();
}
}, 0);
}
}
}, 0);
//Enable dragging the camera
if (this.game.input.activePointer.isDown) {
if (this.game.origDragPoint) {
// move the camera by the amount the mouse has moved since last update
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;
}
// set new drag origin to current position
this.game.origDragPoint = this.game.input.activePointer.position.clone();
} else {
this.game.origDragPoint = null;
}
self.game.iso.topologicalSort(self.isoGroup);
},
render: function () {
for (let i = 0; i < self.debugMessages.length; i++) {
self.game.debug.text(self.debugMessages[i].getMessage(), self.debugMessages[i].x,
self.debugMessages[i].y)
}
}
};
this.game.state.add('Boot', this.bootState);
this.game.state.start('Boot');
}
public addDebugMessage(debugMsg: DebugMessage) {
this.debugMessages.push(debugMsg)
}
private initialiseAnimations() {
//Walk =-------------------------------------------------------
//East
this.animationFrames.walk_e_start = [];
for (let i = 0; i < 10; i++) {
this.animationFrames.walk_e_start.push("cubot/walk_e/" + ("0000" + i).slice(-4));
}
this.animationFrames.walk_e = [];
for (let i = 10; i < 30; i++) {
this.animationFrames.walk_e.push("cubot/walk_e/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_e_start = [];
for (let i = 0; i < 10; i++) {
this.animationFrames.harvester_walk_e_start.push("harvester/walk_e/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_e = [];
for (let i = 10; i < 30; i++) {
this.animationFrames.harvester_walk_e.push("harvester/walk_e/" + ("0000" + i).slice(-4));
}
//North
this.animationFrames.walk_n_start = [];
for (let i = 0; i < 10; i++) {
this.animationFrames.walk_n_start.push("cubot/walk_n/" + ("0000" + i).slice(-4));
}
this.animationFrames.walk_n = [];
for (let i = 10; i < 30; i++) {
this.animationFrames.walk_n.push("cubot/walk_n/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_n_start = [];
for (let i = 0; i < 10; i++) {
this.animationFrames.harvester_walk_n_start.push("harvester/walk_n/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_n = [];
for (let i = 10; i < 30; i++) {
this.animationFrames.harvester_walk_n.push("harvester/walk_n/" + ("0000" + i).slice(-4));
}
//South
this.animationFrames.walk_s_start = [];
for (let i = 0; i < 10; i++) {
this.animationFrames.walk_s_start.push("cubot/walk_s/" + ("0000" + i).slice(-4));
}
this.animationFrames.walk_s = [];
for (let i = 10; i < 30; i++) {
this.animationFrames.walk_s.push("cubot/walk_s/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_s_start = [];
for (let i = 0; i < 10; i++) {
this.animationFrames.harvester_walk_s_start.push("harvester/walk_s/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_s = [];
for (let i = 10; i < 30; i++) {
this.animationFrames.harvester_walk_s.push("harvester/walk_s/" + ("0000" + i).slice(-4));
}
//West
this.animationFrames.walk_w_start = [];
for (let i = 0; i < 10; i++) {
this.animationFrames.walk_w_start.push("cubot/walk_w/" + ("0000" + i).slice(-4));
}
this.animationFrames.walk_w = [];
for (let i = 10; i < 30; i++) {
this.animationFrames.walk_w.push("cubot/walk_w/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_w_start = [];
for (let i = 0; i < 10; i++) {
this.animationFrames.harvester_walk_w_start.push("harvester/walk_w/" + ("0000" + i).slice(-4));
}
this.animationFrames.harvester_walk_w = [];
for (let i = 10; i < 30; i++) {
this.animationFrames.harvester_walk_w.push("harvester/walk_w/" + ("0000" + i).slice(-4));
}
//Dig =-------------------------------------------------------
this.animationFrames.dig_e = [];
for (let i = 1; i <= 41; i++) {
this.animationFrames.dig_e.push("cubot/dig_e/" + ("0000" + i).slice(-4));
}
this.animationFrames.dig_n = [];
for (let i = 1; i <= 41; i++) {
this.animationFrames.dig_n.push("cubot/dig_n/" + ("0000" + i).slice(-4));
}
this.animationFrames.dig_s = [];
for (let i = 1; i <= 41; i++) {
this.animationFrames.dig_s.push("cubot/dig_s/" + ("0000" + i).slice(-4));
}
this.animationFrames.dig_w = [];
for (let i = 1; i <= 41; i++) {
this.animationFrames.dig_w.push("cubot/dig_w/" + ("0000" + i).slice(-4));
}
//Biomass =-------------------------------------------------------
this.animationFrames.biomassIdle = [];
for (let i = 1; i < 60; i++) {
this.animationFrames.biomassIdle.push("objects/biomass/idle/" + ("0000" + i).slice(-4));
}
}
private initialiseStaticHud() {
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);
}
}
abstract class DebugMessage {
public x: number;
public y: number;
constructor(x: number, y: number) {
this.x = x;
this.y = y;
}
abstract getMessage(): string;
}
/**
* Indicates hovered tile
*/
class TileIndicator extends DebugMessage {
public tileType: string;
public tileX: number;
public tileY: number;
getMessage(): string {
if (this.tileType != undefined) {
return this.tileX + ", " + this.tileY + " : " + this.tileType;
} else {
return "";
}
}
}
/**
* Indicates current World
*/
class WorldIndicator extends DebugMessage {
getMessage(): string {
if (mar.world != undefined) {
return "World: (" + Number(mar.client.worldX).toString(16).toUpperCase() + ", " +
Number(mar.client.worldY).toString(16).toUpperCase() + ")";
} else {
return "Loading..."
}
}
}

383
mar/World.ts Normal file
View File

@ -0,0 +1,383 @@
///<reference path="phaser.d.ts"/>
///<reference path="phaser.plugin.isometric.d.ts"/>
enum Direction {
NORTH,
EAST,
SOUTH,
WEST
}
enum TileType {
PLAIN,
WALL,
IRON,
COPPER
}
class Tile extends Phaser.Plugin.Isometric.IsoSprite {
/**
* Text displayed on the tile
*/
textSprite: Phaser.Text;
baseTint: number;
tileX: number;
tileY: number;
/**
* Displayed on the screen
*/
tileType: string;
/**
* Based z coordinate of the tile
*/
private baseZ: number;
public selected: boolean;
protected constructor(x: number, y: number, sprite: string, anchorY: number) {
super(mar.game, Util.getIsoX(x), Util.getIsoY(y), 0, 'sheet', sprite);
this.baseZ = 0; //Base height of the tile
this.tileX = x;
this.tileY = y;
this.anchor.set(0.5, anchorY);
}
/**
* Factory method to create a Tile
*/
public static createTile(type: TileType, x: number, y: number) {
switch (type) {
case TileType.WALL:
return new WallTile(x, y);
case TileType.IRON:
return new IronTile(x, y);
case TileType.COPPER:
return new CopperTile(x, y);
case TileType.PLAIN:
default:
return new PlainTile(x, y);
}
}
public onHover() {
this.tint = config.tileHoverTint;
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;
}
public onExit() {
this.tint = this.baseTint;
mar.game.add.tween(this).to({isoZ: this.baseZ}, 200, Phaser.Easing.Quadratic.InOut, true);
}
public setText(text: string, fillColor: string): void {
//Remove previous text
if (this.textSprite !== undefined) {
this.textSprite.destroy();
}
this.textSprite = mar.game.make.text(0, 16, text, {
fontSize: 22,
fill: fillColor,
stroke: "#FFFFFF",
strokeThickness: 1,
font: "fixedsys"
});
this.textSprite.alpha = 0.6;
this.textSprite.anchor.set(0.5, 0);
this.addChild(this.textSprite);
}
}
class PlainTile extends Tile {
constructor(x: number, y: number) {
super(x, y, config.plainSprite, 0);
this.baseTint = config.tileTint;
this.tint = this.baseTint;
this.tileType = "plain";
}
}
class WallTile extends Tile {
constructor(x: number, y: number) {
super(x, y, config.wallSprite, 0.2);
this.baseTint = config.wallTint;
this.tint = this.baseTint;
this.tileType = "wall";
}
}
class IronTile extends Tile {
constructor(x: number, y: number) {
super(x, y, config.plainSprite, 0);
this.baseTint = config.oreTint;
this.tint = this.baseTint;
this.setText("Iron", config.textIron);
this.tileType = "iron";
}
}
class CopperTile extends Tile {
constructor(x: number, y: number) {
super(x, y, config.plainSprite, 0);
this.baseTint = config.oreTint;
this.tint = this.baseTint;
this.setText("Copper", config.textCopper);
this.tileType = "copper";
}
}
class World {
private tiles: Tile[] = [];
private objects: GameObject[] = [];
private northArrow: WorldArrow;
private eastArrow: WorldArrow;
private southArrow: WorldArrow;
private westArrow: WorldArrow;
/**
* Message displayed in the middle of the World
*/
private bigMessage: Phaser.Text;
constructor(terrain, size) {
//Setup World Arrows
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);
//Create tilemap
this.setTerrain(terrain, size);
}
/**
* Load terrain data from array and create Tiles
* @param terrain
* @param size Size of a side of the World
*/
private setTerrain(terrain: number[], size: number) {
if (DEBUG) {
console.log("[MAR] Creating tilemap of size " + size);
}
for (let x = 0; x < size; x++) {
for (let y = 0; y < size; y++) {
let tile: Tile = Tile.createTile(terrain[y * size + x], x, y);
this.tiles.push(tile);
mar.isoGroup.add(tile);
}
}
//Update World arrows location
this.eastArrow.isoY = 32 * (size + 2);
this.eastArrow.isoX = 72.5 * (size) - 20;
this.southArrow.isoX = 32 * (size + 1);
this.southArrow.isoY = 72.5 * (size) + 20;
//Update Phaser World size
mar.game.world.width = (size + 2) * 128;
mar.game.world.height = (size + 2) * 64;
}
public setBigMessage(msg: string) {
this.bigMessage = mar.game.add.text(908, 450, msg, {
fontSize: 46,
fill: config.bigMessageFill,
stroke: config.textStroke,
strokeThickness: 2,
font: "fixedsys"
}, mar.textGroup);
}
public removeBigMessage() {
if (this.bigMessage != undefined) {
this.bigMessage.destroy();
if (DEBUG) {
console.log("[MAR] Destroyed big message")
}
}
}
/**
* Get object by id
*/
private getObject(id: number): GameObject {
for (let i = 0; i < this.objects.length; i++) {
if (this.objects[i].id === id) {
return this.objects[i];
}
}
return null;
}
/**
* Update, create or delete the current objects based on a list received from the server
* @param objects json list of objects
*/
public handleObjectsUpdate(objects: any) {
//Mark objects as not updated
for (let i = 0; i < this.objects.length; i++) {
this.objects[i].updated = false;
}
for (let i = 0; i < objects.length; i++) {
//Update/Create the object
let existingObject = this.getObject(objects[i].i);
if (existingObject !== null) {
//Object already exists
existingObject.updated = true;
existingObject.updateObject(objects[i]);
} else {
//Object is new
let newObj = GameObject.createObject(objects[i]);
if (newObj != null) {
newObj.updated = true;
this.objects.push(newObj);
mar.isoGroup.add(newObj);
} else {
if (DEBUG) {
console.log("Couldn't create object with objType " + objects[i].t)
}
}
}
}
//Delete not updated objects (see above comments)
for (let i = 0; i < this.objects.length; i++) {
if (!this.objects[i].updated) {
//Check if the object we are removing is our controlledUnit, if so, follow it
if (mar.client.username !== "guest") {
if (this.objects[i] instanceof Cubot && (this.objects[i] as Cubot).username === mar.client.username) {
mar.client.findMyRobot();
if (DEBUG) {
console.log("[MAR] Following Cubot " + mar.client.username)
}
}
}
this.objects[i].destroy();
this.objects.splice(i, 1);
}
}
}
/**
* Delete current ojects and tiles and replace them with provided terrain
* @param terrain
* @param size
*/
public updateTerrain(terrain: number[], size: number) {
for (let i = 0; i < this.objects.length; i++) {
this.objects[i].destroy();
}
for (let i = 0; i < this.tiles.length; i++) {
this.tiles[i].destroy();
}
this.objects = [];
this.tiles = [];
this.setTerrain(terrain, size);
mar.game.iso.topologicalSort(mar.isoGroup);
}
}
/**
* Represents a 'button' sprite that changes world in a direction
*/
class WorldArrow extends Phaser.Plugin.Isometric.IsoSprite {
private hoverText: Phaser.Text;
constructor(x: number, y: number, frame: string, direction: Direction) {
super(mar.game, x, y, 10, "sheet", frame);
let self = this;
this.hoverText = mar.game.make.text(10, 10, Direction[direction], config.arrowTextStyle);
this.addChild(this.hoverText);
this.hoverText.visible = false;
this.hoverText.anchor.set(0, 0);
this.inputEnabled = true;
this.events.onInputDown.add(function () {
let newX = mar.client.worldX + Util.getDeltaX(direction);
let newY = mar.client.worldY + Util.getDeltaY(direction);
//Wrapping coordinates around cyclically
mar.client.worldX = newX % mar.client.maxWidth;
mar.client.worldY = newY % mar.client.maxWidth;
mar.client.requestTerrain();
});
this.events.onInputOver.add(function () {
self.tint = config.arrowHoverTint;
self.hoverText.visible = true;
document.body.style.cursor = "pointer";
});
this.events.onInputOut.add(function () {
self.tint = config.arrowTint;
self.hoverText.visible = false;
document.body.style.cursor = "default";
});
}
}

View File

@ -12063,7 +12063,7 @@ define("ace/editor", ["require", "exports", "module", "ace/lib/fixoldbrowsers",
shouldMerge = shouldMerge
&& this.mergeNextCommand // previous command allows to coalesce with
&& (!/\s/.test(text) || /\s/.test(prev.args)); // previous insertion was of same type
&& (!/\s/.test(text) || /\s/.test(prev.args)); // previous insertion was of same objType
this.mergeNextCommand = true;
} else {

View File

@ -47,12 +47,12 @@ define("ace/mode/mar_rules", ["require", "exports", "module", "ace/lib/oop", "ac
start:
[{
token: 'keyword.function.assembly',
regex: '\\b(?:mov|add|sub|and|or|test|cmp|shl|shr|mul|push|pop|div|xor|dw|nop|equ|neg|hwq|not|ror|rol|sal|sar)\\b',
regex: '\\b(?:mov|add|sub|and|or|test|cmp|shl|shr|mul|push|pop|div|xor|dw|nop|equ|neg|hwq|not|ror|rol|sal|sar|inc|dec|rcl|xchg|rcr)\\b',
caseInsensitive: true
},
{
token: 'keyword.operator.assembly',
regex: '\\b(?:call|ret|jmp|jnz|jg|jl|jge|jle|hwi|jz|js|jns|jc|jnc)\\b',
regex: '\\b(?:call|ret|jmp|jnz|jg|jl|jge|jle|hwi|jz|js|jns|jc|jnc|jo|jno)\\b',
caseInsensitive: true
},
{

View File

@ -1,4 +1,4 @@
define("ace/mode/mar_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"],function(a,d,b){b=a("../lib/oop");a=a("./text_highlight_rules").TextHighlightRules;var c=function(){this.$rules={start:[{token:"keyword.function.assembly",regex:"\\b(?:mov|add|sub|and|or|test|cmp|shl|shr|mul|push|pop|div|xor|dw|nop|equ|neg|hwq|not|ror|rol|sal|sar)\\b",caseInsensitive:!0},{token:"keyword.operator.assembly",regex:"\\b(?:call|ret|jmp|jnz|jg|jl|jge|jle|hwi|jz|js|jns|jc|jnc)\\b",caseInsensitive:!0},
{token:"variable.predefined.ahk",regex:"\\b(?:brk|dup)\\b",caseInsensitive:!0},{token:"variable.parameter.register.assembly",regex:"\\b(?:A|B|C|D|X|Y|bp|sp)\\b",caseInsensitive:!0},{token:"constant.character.decimal.assembly",regex:"\\b[0-9]+\\b"},{token:"constant.character.hexadecimal.assembly",regex:"\\b0x[A-F0-9]+\\b",caseInsensitive:!0},{token:"string.assembly",regex:/"([^\\"]|\\.)*"/},{token:"comment.assembly",regex:";.*$"},{token:"support.function.directive.assembly",regex:/^\.text|\.data/},
define("ace/mode/mar_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"],function(a,d,b){b=a("../lib/oop");a=a("./text_highlight_rules").TextHighlightRules;var c=function(){this.$rules={start:[{token:"keyword.function.assembly",regex:"\\b(?:mov|add|sub|and|or|test|cmp|shl|shr|mul|push|pop|div|xor|dw|nop|equ|neg|hwq|not|ror|rol|sal|sar|inc|dec|rcl|xchg|rcr)\\b",caseInsensitive:!0},{token:"keyword.operator.assembly",regex:"\\b(?:call|ret|jmp|jnz|jg|jl|jge|jle|hwi|jz|js|jns|jc|jnc|jo|jno)\\b",
caseInsensitive:!0},{token:"variable.predefined.ahk",regex:"\\b(?:brk|dup)\\b",caseInsensitive:!0},{token:"variable.parameter.register.assembly",regex:"\\b(?:A|B|C|D|X|Y|bp|sp)\\b",caseInsensitive:!0},{token:"constant.character.decimal.assembly",regex:"\\b[0-9]+\\b"},{token:"constant.character.hexadecimal.assembly",regex:"\\b0x[A-F0-9]+\\b",caseInsensitive:!0},{token:"string.assembly",regex:/"([^\\"]|\\.)*"/},{token:"comment.assembly",regex:";.*$"},{token:"support.function.directive.assembly",regex:/^\.text|\.data/},
{token:"entity.name.function.assembly",regex:/\w*:/}]};this.normalizeRules()};c.metaData={fileTypes:["asm"],name:"Much Assembly Required",scopeName:"source.assembly"};b.inherits(c,a);d.MarHighlightRules=c});
define("ace/mode/mar","require exports module ace/lib/oop ace/mode/text ace/mode/mar_rules".split(" "),function(a,d,b){b=a("../lib/oop");var c=a("./text").Mode,e=a("./mar_rules").MarHighlightRules;a=function(){this.HighlightRules=e;this.$behaviour=this.$defaultBehaviour};b.inherits(a,c);a.prototype.lineCommentStart=";";a.prototype.$id="ace/mode/mar";d.Mode=a});

1687
mar/app.js Normal file

File diff suppressed because it is too large Load Diff

75
mar/app.min.js vendored Normal file
View File

@ -0,0 +1,75 @@
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.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={}));
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.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){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)};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}();

254
mar/console.css Normal file
View File

@ -0,0 +1,254 @@
* {
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
#console-wrapper {
text-align: center;
}
#console-wrapper-left {
width: 870px;
height: 400px;
position: relative;
line-height: 1.2;
display: inline-block;
margin: 0;
z-index: 1;
}
.piece {
display: block;
height: 100%;
left: 0;
top: 0;
width: 100%;
}
.noclick {
pointer-events: none;
}
#console-wrapper-side {
width: 120px;
height: 400px;
position: relative;
z-index: 1;
margin: 0;
display: inline-block;
}
#shadow-wrapper {
display: inline-block;
-webkit-box-shadow: 0 0 1rem black;
box-shadow: 0 0 1rem black;
border-radius: 2rem;
height: 400px;
}
.sideFrame {
background-color: #e7e7e7;
border-radius: 0 2rem 2rem 0;
border: 1rem solid #e7e7e7;
border-left: hidden;
border-bottom-color: #E3E3E3;
position: absolute;
width: 100%;
height: 100%;
text-align: left;
pointer-events: auto;
}
.frame {
background-color: transparent;
border-radius: 2rem 0 0 2rem;
border: 1rem solid #e7e7e7;
border-bottom-color: #E3E3E3;
-webkit-box-shadow: inset 0 0 4rem black, inset 0 0 3rem black;
box-shadow: inset 0 0 4rem black, inset 0 0 3rem black;
position: absolute;
width: 100%;
height: 100%;
pointer-events: none;
}
.vertical-text {
position: absolute;
font-family: fixedsys;
font-size: 16pt;
left: -4px;
top: 125px;
-webkit-transform: rotate(270deg);
-moz-transform: rotate(270deg);
-ms-transform: rotate(270deg);
-o-transform: rotate(270deg);
transform: rotate(270deg);
-webkit-transform-origin: 0 0;
-moz-transform-origin: 0 0;
-ms-transform-origin: 0 0;
-o-transform-origin: 0 0;
transform-origin: 0 0;
}
#consoleText {
font-family: 'fixedsys';
font-size: 24px;
white-space: pre-wrap;
-webkit-animation: crt-output 10ms infinite;
animation: crt-output 10ms infinite;
overflow-y: scroll;
position: absolute;
padding: 3rem 2rem;
pointer-events: auto;
text-align: left;
text-shadow: 0 0.2rem 1rem #0c7b46;
z-index: -1;
}
#consoleText::-webkit-scrollbar {
display: none;
}
@-webkit-keyframes crt-output {
0% {
opacity: 0.95;
}
50% {
opacity: 1;
}
}
@keyframes crt-output {
0% {
opacity: 0.95;
}
50% {
opacity: 1;
}
}
.scanlines {
background: -webkit-gradient(linear, left top, left bottom, from(rgba(255, 255, 255, 0)), color-stop(50%, rgba(255, 255, 255, 0)), color-stop(70%, rgba(0, 0, 0, 0.2)), to(rgba(0, 0, 0, 0.6)));
background: linear-gradient(to bottom, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0) 50%, rgba(0, 0, 0, 0.2) 70%, rgba(0, 0, 0, 0.6));
background-size: 100% 0.3rem;
border-radius: 2rem;
position: absolute;
}
.glow {
-webkit-animation: crt-glow 20s infinite;
animation: crt-glow 20s infinite;
background: radial-gradient(circle at 50% 50%, #1bd459 0%, rgba(27, 212, 89, 0.88) 58%, rgba(21, 235, 92, 0.57) 80%, rgba(19, 94, 29, 0.27) 93%, rgba(10, 23, 12, 0) 100%);
opacity: 0.15;
pointer-events: none;
position: relative;
}
@-webkit-keyframes crt-glow {
0% {
opacity: 0.1;
}
50% {
opacity: 0.2;
}
}
@keyframes crt-glow {
0% {
opacity: 0.1;
}
50% {
opacity: 0.2;
}
}
.ctr-selection::-moz-selection {
background-color: #14fdce;
color: #031e11;
}
.ctr-selection::selection {
background-color: #14fdce;
color: #031e11;
}
.ctr-selection-inverted::-moz-selection {
background-color: #031e11;
color: #14fdce;
}
.ctr-selection-inverted::selection {
background-color: #031e11;
color: #14fdce;
}
.ctr-text {
color: #14fdce;
background-color: #031e11;
}
.ctr-text-inverted {
color: #031e11;
background-color: #14fdce;
}
/*Buttons*/
.pdp8Button {
cursor: pointer;
border: none;
outline: none;
width: 24px;
height: 55px;
display: inline-block;
margin: 0;
padding: 0;
pointer-events: auto;
}
.pdp8Button:focus {
outline-width: 0;
}
.dial-backPlate {
position: absolute;
left: 0;
top: 60%;
height: 83px;
}
.dial {
width: 65px;
height: 65px;
padding: 0;
display: inline-block;
pointer-events: auto;
cursor: pointer;
border: none;
outline: none;
position: absolute;
left: 27px;
top: 10px;
}
.dial-lines {
position: absolute;
left: 0;
pointer-events: none;
}

1
mar/console.min.css vendored Normal file
View File

@ -0,0 +1 @@
*{-webkit-box-sizing:border-box;box-sizing:border-box}#console-wrapper{text-align:center}#console-wrapper-left{width:870px;height:400px;position:relative;line-height:1.2;display:inline-block;margin:0;z-index:1}.piece{display:block;height:100%;left:0;top:0;width:100%}.noclick{pointer-events:none}#console-wrapper-side{width:120px;height:400px;position:relative;z-index:1;margin:0;display:inline-block}#shadow-wrapper{display:inline-block;-webkit-box-shadow:0 0 1rem black;box-shadow:0 0 1rem black;border-radius:2rem;height:400px}.sideFrame{background-color:#e7e7e7;border-radius:0 2rem 2rem 0;border:1rem solid #e7e7e7;border-left:hidden;border-bottom-color:#e3e3e3;position:absolute;width:100%;height:100%;text-align:left;pointer-events:auto}.frame{background-color:transparent;border-radius:2rem 0 0 2rem;border:1rem solid #e7e7e7;border-bottom-color:#e3e3e3;-webkit-box-shadow:inset 0 0 4rem black,inset 0 0 3rem black;box-shadow:inset 0 0 4rem black,inset 0 0 3rem black;position:absolute;width:100%;height:100%;pointer-events:none}.vertical-text{position:absolute;font-family:fixedsys;font-size:16pt;left:-4px;top:125px;-webkit-transform:rotate(270deg);-moz-transform:rotate(270deg);-ms-transform:rotate(270deg);-o-transform:rotate(270deg);transform:rotate(270deg);-webkit-transform-origin:0 0;-moz-transform-origin:0 0;-ms-transform-origin:0 0;-o-transform-origin:0 0;transform-origin:0 0}#consoleText{font-family:'fixedsys';font-size:24px;white-space:pre-wrap;-webkit-animation:crt-output 10ms infinite;animation:crt-output 10ms infinite;overflow-y:scroll;position:absolute;padding:3rem 2rem;pointer-events:auto;text-align:left;text-shadow:0 .2rem 1rem #0c7b46;z-index:-1}#consoleText::-webkit-scrollbar{display:none}@-webkit-keyframes crt-output{0{opacity:.95}50%{opacity:1}}@keyframes crt-output{0{opacity:.95}50%{opacity:1}}.scanlines{background:-webkit-gradient(linear,left top,left bottom,from(rgba(255,255,255,0)),color-stop(50%,rgba(255,255,255,0)),color-stop(70%,rgba(0,0,0,0.2)),to(rgba(0,0,0,0.6)));background:linear-gradient(to bottom,rgba(255,255,255,0),rgba(255,255,255,0) 50%,rgba(0,0,0,0.2) 70%,rgba(0,0,0,0.6));background-size:100% .3rem;border-radius:2rem;position:absolute}.glow{-webkit-animation:crt-glow 20s infinite;animation:crt-glow 20s infinite;background:radial-gradient(circle at 50% 50%,#1bd459 0,rgba(27,212,89,0.88) 58%,rgba(21,235,92,0.57) 80%,rgba(19,94,29,0.27) 93%,rgba(10,23,12,0) 100%);opacity:.15;pointer-events:none;position:relative}@-webkit-keyframes crt-glow{0{opacity:.1}50%{opacity:.2}}@keyframes crt-glow{0{opacity:.1}50%{opacity:.2}}.ctr-selection::-moz-selection{background-color:#14fdce;color:#031e11}.ctr-selection::selection{background-color:#14fdce;color:#031e11}.ctr-selection-inverted::-moz-selection{background-color:#031e11;color:#14fdce}.ctr-selection-inverted::selection{background-color:#031e11;color:#14fdce}.ctr-text{color:#14fdce;background-color:#031e11}.ctr-text-inverted{color:#031e11;background-color:#14fdce}.pdp8Button{cursor:pointer;border:0;outline:0;width:24px;height:55px;display:inline-block;margin:0;padding:0;pointer-events:auto}.pdp8Button:focus{outline-width:0}.dial-backPlate{position:absolute;left:0;top:60%;height:83px}.dial{width:65px;height:65px;padding:0;display:inline-block;pointer-events:auto;cursor:pointer;border:0;outline:0;position:absolute;left:27px;top:10px}.dial-lines{position:absolute;left:0;pointer-events:none}

View File

@ -4,7 +4,6 @@ OPERAND_MEM_IMM = 1;
OPERAND_MEM_REG = 2;
OPERAND_IMM = 3;
//Remove default syntax checker
editor = ace.edit("editor");
editor.session.setOption("useWorker", false);
@ -257,7 +256,7 @@ function parseInstruction(line, result, currentLine) {
if (!parseDWInstruction(line, result, currentLine)) {
if (new RegExp('\\b(?:mov|add|sub|and|or|test|cmp|shl|shr|mul|push|pop|div|xor|hwi|hwq|nop|neg|' +
'call|ret|jmp|jnz|jg|jl|jge|jle|int|jz|js|jns|brk|not|jc|jnc|ror|rol|sal|sar|jo|jno)\\b').test(mnemonic.toLowerCase())) {
'call|ret|jmp|jnz|jg|jl|jge|jle|int|jz|js|jns|brk|not|jc|jnc|ror|rol|sal|sar|jo|jno|inc|dec|rcl|xchg|rcr)\\b').test(mnemonic.toLowerCase())) {
if (line.indexOf(",") !== -1) {
@ -267,7 +266,7 @@ function parseInstruction(line, result, currentLine) {
//Validate operand number
if (!new RegExp('\\b(?:mov|add|sub|and|or|test|cmp|shl|shr|xor|rol|ror|sal|sar)\\b').test(mnemonic.toLowerCase())) {
if (!new RegExp('\\b(?:mov|add|sub|and|or|test|cmp|shl|shr|xor|rol|ror|sal|sar|rcl|xchg|rcr)\\b').test(mnemonic.toLowerCase())) {
result.annotations.push({
row: currentLine,
column: 0,
@ -315,7 +314,7 @@ function parseInstruction(line, result, currentLine) {
strO1 = line.substring(line.indexOf(mnemonic) + mnemonic.length).trim();
//Validate operand number
if (!new RegExp('\\b(?:push|mul|pop|div|neg|call|jnz|jg|jl|jge|jle|hwi|hwq|jz|js|jns|ret|jmp|not|jc|jnc|jo|jno)\\b').test(mnemonic.toLowerCase())) {
if (!new RegExp('\\b(?:push|mul|pop|div|neg|call|jnz|jg|jl|jge|jle|hwi|hwq|jz|js|jns|ret|jmp|not|jc|jnc|jo|jno|inc|dec)\\b').test(mnemonic.toLowerCase())) {
result.annotations.push({
row: currentLine,
column: 0,
@ -404,4 +403,92 @@ function editorClick() {
document.getElementById("gameBtns").setAttribute("style", "display: none");
}
//-----
//Check if browser supports local storage if not than bad luck, use something else than IE7
var editorStorage;
if (typeof window.localStorage !== 'undefined') {
editorStorage = window.localStorage;
} else {
editorStorage = false;
}
//Default should be 'theme/tommorow.js' or loaded from local storage
var editorThemeOptions = {
available: [
"theme/ambiance", "theme/chaos", "theme/chrome",
"theme/clouds", "theme/clouds_midnight", "theme/cobalt",
"theme/crimson_editor", "theme/dawn", "theme/dracula",
"theme/dreamweaver", "theme/eclipse", "theme/github",
"theme/gob", "theme/gruvbox", "theme/idle_fingers",
"theme/iplastic", "theme/katzenmilch", "theme/kr_theme",
"theme/kuroir", "theme/merbivore", "theme/merbivore_soft",
"theme/mono_industrial", "theme/monokai", "theme/pastel_on_dark",
"theme/solarized_dark", "theme/solarized_light", "theme/sqlserver",
"theme/terminal", "theme/textmate", "theme/tomorrow",
"theme/tomorrow_night_blue", "theme/tomorrow_night_bright", "theme/tomorrow_night_eighties",
"theme/tomorrow_night", "theme/twilight", "theme/vibrant_ink", "theme/xcode"
],
defaultTheme: "theme/tomorrow"
};
//Get the stored default theme
if (editorStorage) {
var storedTheme = editorStorage.getItem('editorTheme');
if (storedTheme !== null && editorThemeOptions.available.indexOf(storedTheme) !== -1) {
editorThemeOptions.defaultTheme = storedTheme;
}
}
//Cache element reference
var editorThemeSelectElement = document.getElementById("editorTheme");
//Event handler
function editorOnThemeChange() {
if (editorThemeSelectElement === null) {
console.error("editorOnThemeChange() :: editorThemeSelectElement seems to be 'null'");
return;
}
var select = editorThemeSelectElement;
var option = select.options[select.selectedIndex];
if (editorThemeOptions.available.indexOf(option.value) === -1) {
console.error("editorOnThemeChange() :: user somehow selected an invalid theme : '" + option.value + "' for '" + option.text + "'");
return;
}
//Store locally so it gets remembered
if (editorStorage) {
editorStorage.setItem('editorTheme', option.value);
}
//Set theme
editor.setTheme("ace/" + option.value);
}
//Add handler to listen to event
editorThemeSelectElement.addEventListener('change', editorOnThemeChange);
//Populate select
editorThemeOptions.available.forEach(function (theme) {
var option = document.createElement("option");
option.value = theme;
option.text = theme.substring(6); // "theme/{text}" -> extract text to set as text user sees
//Make sure default is also the one that is selected
if (theme === editorThemeOptions.defaultTheme) {
option.selected = true;
}
editorThemeSelectElement.appendChild(option);
});
//Manually call handler once
editorOnThemeChange();
editor.getSession().setMode("ace/mode/mar");
editor.setFontSize(16);
editor.setDisplayIndentGuides(false);
document.getElementById('editor').style.fontFamily = "fixedsys";
editor.on("change", parse);

14
mar/editor.min.js vendored
View File

@ -8,10 +8,14 @@ function checkForEQUInstruction(a,c,b){var d=getTokens(a);return-1!==a.toLowerCa
function checkForORGInstruction(a,c,b){a=removeComment(a);a=removeLabel(a);a=getTokens(a);var d=a[0];if(void 0!==d&&"org"===d.toLowerCase()){if(console.log(a),1<a.length)return d=Number(a[1]),(isNaN(d)||d!==Math.floor(d))&&c.annotations.push({row:b,column:0,text:"Invalid operand: "+a[1],type:"error"}),!0}else return!1}
function parseDWInstruction(a,c,b){a=a.trim();if("dw"===a.substr(0,2).toLowerCase()){a=a.substr(2,a.length).split(/,(?=(?:[^"]*"[^"]*")*[^"]*$)/,-1);for(var d=0;d<a.length;d++){a[d]=a[d].trim();var e=getTokens(a[d]);if(!(2===e.length&&getOperandType(e[0],c)===OPERAND_IMM&&e[1].toLowerCase().startsWith("dup(")&&e[1].endsWith(")")&&getOperandType(e[1].substring(4,e[1].indexOf(")")),c)===OPERAND_IMM||a[d].startsWith('"')&&a[d].endsWith('"')||getOperandType(a[d],c)===OPERAND_IMM)){c.annotations.push({row:b,
column:0,text:"Usage: DW IMM, IMM ...",type:"error"});break}}return!0}return!1}
function getOperandType(a,c){a=a.trim();if(""===a)return OPERAND_INVALID;if(!isNaN(Number(a))&&Number(a)===Math.floor(Number(a))&&-1===a.indexOf("o")&&-1===a.indexOf("e"))return OPERAND_IMM;if(/^(a|b|c|d|x|y|bp|sp)$/.test(a.toLowerCase()))return OPERAND_REG;for(b=0;b<c.labels.length;b++)if(a===c.labels[b])return OPERAND_IMM;if(a.startsWith("[")&&a.endsWith("]")){a=a.replace("[","").replace("]","");if(!isNaN(Number(a))&&Number(a)===Math.floor(Number(a)))return OPERAND_MEM_IMM;for(var b=0;b<c.labels.length;b++)if(a===
function getOperandType(a,c){a=a.trim();if(""===a)return OPERAND_INVALID;if(!isNaN(Number(a))&&Number(a)===Math.floor(Number(a))&&-1===a.indexOf("o")&&0!==a.indexOf("0e"))return OPERAND_IMM;if(/^(a|b|c|d|x|y|bp|sp)$/.test(a.toLowerCase()))return OPERAND_REG;for(b=0;b<c.labels.length;b++)if(a===c.labels[b])return OPERAND_IMM;if(a.startsWith("[")&&a.endsWith("]")){a=a.replace("[","").replace("]","");if(!isNaN(Number(a))&&Number(a)===Math.floor(Number(a)))return OPERAND_MEM_IMM;for(var b=0;b<c.labels.length;b++)if(a===
c.labels[b])return OPERAND_MEM_IMM;if(/^(bp|sp)$/.test(a.toLowerCase().substring(0,2).toLowerCase()))a=a.substring(2);else if(/^(a|b|c|d|x|y)$/.test(a.toLowerCase().substring(0,1).toLowerCase()))a=a.substring(1);else return OPERAND_INVALID;if(""===a.replace(/\s+/g,""))return OPERAND_MEM_REG;a=a.replace(/\s+/g,"");for(b=0;b<c.labels.length;b++)if(a.substring(1)===c.labels[b])return OPERAND_MEM_REG;if(!isNaN(Number(a))&&Number(a)===Math.floor(Number(a)))return OPERAND_MEM_REG}return OPERAND_INVALID}
function parseInstruction(a,c,b){a=removeComment(a);a=removeLabel(a);var d=getTokens(a),e=d[0];if(void 0!==e&&""!==e&&!parseDWInstruction(a,c,b))if(/\b(?:mov|add|sub|and|or|test|cmp|shl|shr|mul|push|pop|div|xor|hwi|hwq|nop|neg|call|ret|jmp|jnz|jg|jl|jge|jle|int|jz|js|jns|brk|not|jc|jnc|ror|rol|sal|sar|jo|jno)\b/.test(e.toLowerCase()))if(-1!==a.indexOf(","))if(d=a.substring(a.indexOf(e)+e.length,a.indexOf(",")),a=a.substring(a.indexOf(",")+1).trim(),/\b(?:mov|add|sub|and|or|test|cmp|shl|shr|xor|rol|ror|sal|sar)\b/.test(e.toLowerCase())){e=
function parseInstruction(a,c,b){a=removeComment(a);a=removeLabel(a);var d=getTokens(a),e=d[0];if(void 0!==e&&""!==e&&!parseDWInstruction(a,c,b))if(/\b(?:mov|add|sub|and|or|test|cmp|shl|shr|mul|push|pop|div|xor|hwi|hwq|nop|neg|call|ret|jmp|jnz|jg|jl|jge|jle|int|jz|js|jns|brk|not|jc|jnc|ror|rol|sal|sar|jo|jno|inc|dec|rcl|xchg|rcr)\b/.test(e.toLowerCase()))if(-1!==a.indexOf(","))if(d=a.substring(a.indexOf(e)+e.length,a.indexOf(",")),a=a.substring(a.indexOf(",")+1).trim(),/\b(?:mov|add|sub|and|or|test|cmp|shl|shr|xor|rol|ror|sal|sar|rcl|xchg|rcr)\b/.test(e.toLowerCase())){e=
getOperandType(d,c);var f=getOperandType(a,c);e===OPERAND_INVALID?c.annotations.push({row:b,column:0,text:"Invalid operand: "+d,type:"error"}):f===OPERAND_INVALID?c.annotations.push({row:b,column:0,text:"Invalid operand: "+a,type:"error"}):e===OPERAND_IMM&&c.annotations.push({row:b,column:0,text:"Destination operand can't be an immediate value",type:"error"})}else c.annotations.push({row:b,column:0,text:e+" instruction with 2 operands is illegal",type:"error"});else 1<d.length?(d=a.substring(a.indexOf(e)+
e.length).trim(),/\b(?:push|mul|pop|div|neg|call|jnz|jg|jl|jge|jle|hwi|hwq|jz|js|jns|ret|jmp|not|jc|jnc|jo|jno)\b/.test(e.toLowerCase())?getOperandType(d,c)===OPERAND_INVALID&&c.annotations.push({row:b,column:0,text:"Invalid operand: "+d,type:"error"}):c.annotations.push({row:b,column:0,text:e+" instruction with 1 operand is illegal",type:"error"})):/\b(?:ret|brk|nop)\b/.test(e.toLowerCase())||c.annotations.push({row:b,column:0,text:e+" instruction with no operand is illegal",type:"error"});else c.annotations.push({row:b,
column:0,text:"Unknown mnemonic: "+e,type:"error"})}function parse(){for(var a=ace.edit("editor").getValue().split("\n"),c={labels:[],annotations:[]},b=0;b<a.length;b++)checkForLabel(a[b],c);for(b=0;b<a.length;b++)checkForSegmentDeclaration(a[b])||checkForEQUInstruction(a[b],c,b)||checkForORGInstruction(a[b],c,b)||parseInstruction(a[b],c,b);editor.getSession().setAnnotations(c.annotations)}
function gameClick(){document.getElementById("editorBtns").setAttribute("style","display: none");document.getElementById("gameBtns").setAttribute("style","")}function editorClick(){document.getElementById("editorBtns").setAttribute("style","");document.getElementById("gameBtns").setAttribute("style","display: none")}editor.on("change",parse);
e.length).trim(),/\b(?:push|mul|pop|div|neg|call|jnz|jg|jl|jge|jle|hwi|hwq|jz|js|jns|ret|jmp|not|jc|jnc|jo|jno|inc|dec)\b/.test(e.toLowerCase())?getOperandType(d,c)===OPERAND_INVALID&&c.annotations.push({row:b,column:0,text:"Invalid operand: "+d,type:"error"}):c.annotations.push({row:b,column:0,text:e+" instruction with 1 operand is illegal",type:"error"})):/\b(?:ret|brk|nop)\b/.test(e.toLowerCase())||c.annotations.push({row:b,column:0,text:e+" instruction with no operand is illegal",type:"error"});
else c.annotations.push({row:b,column:0,text:"Unknown mnemonic: "+e,type:"error"})}function parse(){for(var a=ace.edit("editor").getValue().split("\n"),c={labels:[],annotations:[]},b=0;b<a.length;b++)checkForLabel(a[b],c);for(b=0;b<a.length;b++)checkForSegmentDeclaration(a[b])||checkForEQUInstruction(a[b],c,b)||checkForORGInstruction(a[b],c,b)||parseInstruction(a[b],c,b);editor.getSession().setAnnotations(c.annotations)}
function gameClick(){document.getElementById("editorBtns").setAttribute("style","display: none");document.getElementById("gameBtns").setAttribute("style","")}function editorClick(){document.getElementById("editorBtns").setAttribute("style","");document.getElementById("gameBtns").setAttribute("style","display: none")}var editorStorage;editorStorage="undefined"!==typeof window.localStorage?window.localStorage:!1;
var editorThemeOptions={available:"theme/ambiance theme/chaos theme/chrome theme/clouds theme/clouds_midnight theme/cobalt theme/crimson_editor theme/dawn theme/dracula theme/dreamweaver theme/eclipse theme/github theme/gob theme/gruvbox theme/idle_fingers theme/iplastic theme/katzenmilch theme/kr_theme theme/kuroir theme/merbivore theme/merbivore_soft theme/mono_industrial theme/monokai theme/pastel_on_dark theme/solarized_dark theme/solarized_light theme/sqlserver theme/terminal theme/textmate theme/tomorrow theme/tomorrow_night_blue theme/tomorrow_night_bright theme/tomorrow_night_eighties theme/tomorrow_night theme/twilight theme/vibrant_ink theme/xcode".split(" "),defaultTheme:"theme/tomorrow"};
if(editorStorage){var storedTheme=editorStorage.getItem("editorTheme");null!==storedTheme&&-1!==editorThemeOptions.available.indexOf(storedTheme)&&(editorThemeOptions.defaultTheme=storedTheme)}var editorThemeSelectElement=document.getElementById("editorTheme");
function editorOnThemeChange(){if(null===editorThemeSelectElement)console.error("editorOnThemeChange() :: editorThemeSelectElement seems to be 'null'");else{var a=editorThemeSelectElement;a=a.options[a.selectedIndex];-1===editorThemeOptions.available.indexOf(a.value)?console.error("editorOnThemeChange() :: user somehow selected an invalid theme : '"+a.value+"' for '"+a.text+"'"):(editorStorage&&editorStorage.setItem("editorTheme",a.value),editor.setTheme("ace/"+a.value))}}
editorThemeSelectElement.addEventListener("change",editorOnThemeChange);editorThemeOptions.available.forEach(function(a){var c=document.createElement("option");c.value=a;c.text=a.substring(6);a===editorThemeOptions.defaultTheme&&(c.selected=!0);editorThemeSelectElement.appendChild(c)});editorOnThemeChange();editor.getSession().setMode("ace/mode/mar");editor.setFontSize(16);editor.setDisplayIndentGuides(!1);document.getElementById("editor").style.fontFamily="fixedsys";editor.on("change",parse);

Binary file not shown.

View File

@ -1,7 +1,7 @@
@font-face {
font-family: 'fixedsys';
src: url("./fonts/FSEX301-L2.ttf");
src: url("../assets/fonts/FSEX301-L2.ttf");
}
#tabs {
@ -11,24 +11,22 @@
.container {
width: 100%;
}
#game {
box-shadow: rgba(46, 94, 80, 0.45) 0ex 0ex 2ex;
/*margin-top: 1em;*/
box-shadow: rgba(46, 94, 80, 0.45) 0 0 2ex;
outline: none;
width: 100%;
margin: 1em 0 1em 1em;
box-sizing: border-box;
/*background: #282828;*/
background: whitesmoke;
}
#editor {
margin: 1em 0 1em 1em;
height: 35em;
box-shadow: rgba(46, 94, 80, 0.45) 0ex 0ex 2ex;
box-shadow: rgba(46, 94, 80, 0.45) 0 0 2ex;
}
@ -38,7 +36,32 @@
}
.ace_gutter-cell.ace_error {
background-image: url("sprites/err_annotation.png") !important;
background-image: url("../images/err_annotation.png") !important;
background-position: 2px center;
}
#tabs ul, li, a {
display: inline;
}
#tabs .ui-tabs-nav li.ui-tabs-active a {
background: #a1cd9b;
}
#editorBtns {
display: inline;
}
.editorBtn {
background: #895EC3;
padding: .85em 1em
}
.editorBtn:hover {
background: #A386CA;
}
#gameBtns {
display: inline;
}

100
mar/mar.ts Normal file
View File

@ -0,0 +1,100 @@
// Typescript V2.4.1
let RENDERER_WIDTH = document.getElementById("game").clientWidth * window.devicePixelRatio;
let RENDERER_HEIGHT = (window.innerHeight / 1.40) * window.devicePixelRatio;
let DEBUG: boolean = true;
let config = {
tileTint: 0xFFFFFF,
wallTint: 0xDDDDDD,
oreTint: 0xF3F3F3,
cubotHoverTint: 0x00FF00,
cubotTint: 0xFFFFFF,
textFill: "#FFFFFF",
textStroke: "#9298a8",
biomassTint: 0x63B85F,
biomassHoverTint: 0x00FF00,
tileHoverTint: 0x00FF00,
itemIron: 0x434341,
textIron: "#434341",
itemCopper: 0xC87D38,
textCopper: "#C87D38",
hologramFill: "#0aced6",
hologramStroke: "#12FFB0",
copperFill: "#C87D38",
plainSprite: "tiles/tile",
wallSprite: "tiles/bigTile",
walkDuration: 800, //walk animation duration in ms
holoStyle: (fill) => {
return {
fontSize: 32,
fill: fill ? fill : config.hologramFill,
stroke: config.hologramStroke,
strokeThickness: 1,
font: "fixedsys"
}
},
kbBufferX: 225, ///Position of the keyboard buffer fill on screen
kbBufferY: 20,
arrowTextStyle: {
fontSize: 32,
fill: "#ffffff",
stroke: "#9298a8",
strokeThickness: 1,
font: "fixedsys"
},
lowEnergy: 100, //Low energy threshold to change color
lowEnergyTint: 0xCC0000,
bigMessageFill: "#ff803d",
arrowTint: 0xFFFFFF,
arrowHoverTint: 0x00FF00,
selfUsernameColor: 0xFB4D0A, //Color of own Cubot's username.
otherCubotAlpha: 0.6,
defaultWorldSize: 16 //Will fallback to this when server does not provide world width
};
class Util {
//todo: find a more elegant way of doing this. Maybe this is related: https://github.com/lewster32/phaser-plugin-isometric/issues/7
static getIsoY(y: number) {
return Util.getIsoX(y);
}
static getIsoX(x: number) {
return (x * 71.5)
}
static getDeltaX(direction: Direction) {
switch (direction) {
case Direction.NORTH:
case Direction.SOUTH:
return 0;
case Direction.EAST:
return 1;
case Direction.WEST:
return -1;
}
}
static getDeltaY(direction: Direction) {
switch (direction) {
case Direction.EAST:
case Direction.WEST:
return 0;
case Direction.NORTH:
return 1;
case Direction.SOUTH:
return -1;
}
}
}
let mar = new MarGame();
var myVarX = 0.46;
var myVarY = 0.46;

View File

@ -1,101 +0,0 @@
fullscreen = false;
function gameLoop() {
requestAnimationFrame(gameLoop);
for(var i in game.world.objects){
if(game.world.objects[i]){
game.world.objects[i].update();
}
}
game.worldLayer.children.sort(depthCompare);
game.renderer.render(game.rootContainer);
}
function Game(){
var world;
var worldX;
var worldY;
var self = this;
this.calculateBounds = function(){
if (fullscreen) {
self.RENDERER_WIDTH = window.innerWidth - 4;
self.RENDERER_HEIGHT = window.innerHeight - 4;
} else {
self.RENDERER_WIDTH = document.getElementById("game").clientWidth;
self.RENDERER_HEIGHT = (window.innerHeight / 1.25);
}
};
//Setup renderer
this.calculateBounds();
this.renderer = PIXI.autoDetectRenderer(256, 256);
document.getElementById("game").appendChild(this.renderer.view);
this.rootContainer = new PIXI.Container();
this.renderer.backgroundColor = 0x282828;
this.renderer.resize(this.RENDERER_WIDTH, this.RENDERER_HEIGHT);
window.onresize = function () {
self.calculateBounds();
self.renderer.resize(self.RENDERER_WIDTH, self.RENDERER_HEIGHT);
};
//SETUP BACKGROUND LAYER & PANNING
this.bgLayer = new PIXI.Container();
this.rootContainer.addChildAt(this.bgLayer, 0);
this.bg = new PIXI.Sprite();
this.bg.interactive = true;
this.bg.hitArea = new PIXI.Rectangle(0, 0, this.RENDERER_WIDTH, this.RENDERER_HEIGHT);
this.bg.on("pointerdown", function (e) {
self.pointerdown = true;
self.pointerFirstClick = e.data.getLocalPosition(self.rootContainer);
});
this.bg.on("pointerup", function () {
self.pointerdown = false;
self.pointerLastDrag = null;
});
this.bg.on("pointerupoutside", function () {
self.pointerdown = false;
self.pointerLastDrag = null;
});
this.bg.on("pointermove", function (e) {
if (self.pointerdown === true) {
//Dragging
var currentMouse = e.data.getLocalPosition(self.rootContainer);
if (self.pointerLastDrag !== null) {
self.worldLayer.position.x += currentMouse.x - self.pointerLastDrag.x;
self.worldLayer.position.y += currentMouse.y - self.pointerLastDrag.y;
} else {
self.worldLayer.position.x += currentMouse.x - self.pointerFirstClick.x;
self.worldLayer.position.y += currentMouse.y - self.pointerFirstClick.y;
}
self.pointerLastDrag = currentMouse;
}
});
this.bgLayer.addChild(this.bg);
//------------------------------------
}

View File

@ -1,274 +0,0 @@
/**
* Listens for authentications responses from the server
*/
function authListener(message){
if(message.t === "auth"){
if(message.m === "ok"){
console.log("Auth successful");
client.requestUserInfo();
} else {
console.log("Auth failed");
}
}
}
/**
* Listens for user info responses from the server
*/
function userInfoListener(message){
if(message.t === "userInfo"){
game = new Game();
game.worldX = message.worldX;
game.worldY = message.worldY;
client.requestTerrain();
}
}
function formattedKeyBuffer(kbBuffer) {
var str = "Keyboard: ";
for(var i = 0; i < 16; i++){
if(kbBuffer[i] !== undefined) {
str += "0x" + kbBuffer[i].toString(16) + " ";
} else {
str += "____ ";
}
}
return str;
}
function terrainListener(message){
if(message.t === "terrain"){
if(game.world !== undefined){
game.world.update(message.terrain);
} else {
game.world = new Word(message.terrain);
//Setup keyboard buffer display
game.textLayer = new PIXI.Container();
game.rootContainer.addChild(game.textLayer);
game.kbBuffer = [];
game.keyboardBuffer = new PIXI.Text(formattedKeyBuffer([]), {fontSize: 16, fontFamily: "fixedsys", fill: "white"});
game.textLayer.addChild(game.keyboardBuffer);
//Handle keypresses
window.addEventListener('keydown', function(event) {
if(game.kbBuffer.length <= 16) {
client.sendKeypress(event.keyCode);
//Locally update the buffer
game.kbBuffer.push(event.keyCode);
game.keyboardBuffer.text = formattedKeyBuffer(game.kbBuffer);
if(event.keyCode >= 37 && event.keyCode <= 40){
event.preventDefault();
}
}
});
console.log("Gameloop started");
gameLoop();
}
}
}
function tickListener(message){
if(message.t === "tick"){
//Request objects
client.socket.send(JSON.stringify({t: "object", x: game.worldX, y: game.worldY}));
//Update key buffer display
if(game.textLayer){
if(message.keys !== undefined){
console.log(message.keys);
game.kbBuffer = message.keys;
game.keyboardBuffer.text = formattedKeyBuffer(game.kbBuffer);
}
}
}
}
function objectListener(message){
if(message.t === "object"){
game.world.updateObjects(message.objects);
}
}
function codeListener(message){
if(message.t === "code"){
ace.edit("editor").setValue(message.code);
}
}
function GameClient(callback) {
var self = this;
var listeners = [];
var xhr = new XMLHttpRequest();
xhr.open("GET", "./getServerInfo.php", true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
console.log("Received server info " + xhr.responseText);
setTimeout(function(){
var info = JSON.parse(xhr.responseText);
self.socket = new WebSocket(info.address);
self.username = info.username;
self.tickLength = info.tickLength;
self.serverName = info.serverName;
self.socket.onopen = function () {
//Send auth request
self.socket.send(info.token);
//Setup event managers
listeners.push(authListener);
listeners.push(userInfoListener);
listeners.push(terrainListener);
listeners.push(tickListener);
listeners.push(objectListener);
listeners.push(codeListener);
client.socket.onmessage = function(e){
//console.log("Received " + e.data);
var message = JSON.parse(e.data);
for(var i = 0; i < listeners.length ; i++){
listeners[i](message);
}
};
self.reloadCode();
if(callback !== undefined){
callback();
}
}
}, 100);
}
};
xhr.send(null);
this.requestUserInfo = function(){
this.socket.send(JSON.stringify({t: "userInfo"}));
};
this.requestTerrain = function(){
this.socket.send(JSON.stringify({t: "terrain", x: game.worldX, y: game.worldY}));
};
this.uploadCode = function(code){
console.log("Uploaded code");
this.socket.send(JSON.stringify({t: "uploadCode", code: code}))
};
this.reloadCode = function(){
this.socket.send(JSON.stringify({t: "codeRequest"}))
};
this.sendKeypress = function(key){
if(key !== 0){
this.socket.send(JSON.stringify({t:"k", k:key}));
}
};
}
// Change an object's location and initialise the move animation
function moveObject(newX, newY, gameObject) {
//Resync object
for(clip in gameObject.clips){
gameObject.clips[clip].x = (gameObject.x - gameObject.y) * 64;
gameObject.clips[clip].y = ((gameObject.x + gameObject.y) * 32) - 16;
}
var tiledx = newX - gameObject.x;
var tiledy = newY - gameObject.y;
gameObject.dx = 0;
gameObject.dy = 0;
//Recalculate position
gameObject.x = newX;
gameObject.y = newY;
if (tiledx === 1) {
//We need to move 128px to the right and the minimum tick length is 1s.
//This means that we have maximum 60 frames to do the animation
gameObject.dx = 64 / 58;
gameObject.dy = 32 / 58;
gameObject.walking = 58;
//Recalculate Z order immediately
gameObject.sprite.z = gameObject.y + gameObject.x + 0.1;
} else if (tiledx === -1) {
gameObject.dx = -64 / 58;
gameObject.dy = -32 / 58;
gameObject.walking = 58;
//The Z order needs to be recalculated when the movement ends
gameObject.recalculateZAfter = true;
} else if (tiledy === 1) {
gameObject.dx = -64 / 58;
gameObject.dy = 32 / 58;
gameObject.walking = 58;
//Recalculate Z order immediately
gameObject.sprite.z = gameObject.y + gameObject.x + 0.1;
} else if (tiledy === -1) {
gameObject.dx = 64 / 58;
gameObject.dy = -32 / 58;
gameObject.walking = 58;
//The Z order needs to be recalculated when the movement ends
gameObject.recalculateZAfter = true;
}
game.worldLayer.children.sort(depthCompare);
}

View File

@ -1,363 +0,0 @@
OBJ_CUBOT = 1;
OBJ_PLANT = 2;
OBJ_KILN = 3;
OBJ_DIGESTER = 4;
OBJ_ROCKET = 5;
DIR_NORTH = 0;
DIR_EAST = 1;
DIR_SOUTH = 2;
DIR_WEST = 3;
ACTION_WALK =2;
function getItemTexture(item){
return PIXI.Texture.fromFrame("objects/plant1_s");
}
function getCubotAnimatedSprites(){
var walk_e = [];
var walk_n = [];
var walk_s = [];
var walk_w = [];
var i;
for(i = 1; i <= 30; i++){
walk_e.push(PIXI.Texture.fromFrame("cubot/walk_e/" + ("0000" + i).slice(-4)))
}
for(i = 1; i <= 30; i++){
walk_n.push(PIXI.Texture.fromFrame("cubot/walk_n/" + ("0000" + i).slice(-4)))
}
for(i = 1; i <= 30; i++){
walk_s.push(PIXI.Texture.fromFrame("cubot/walk_s/" + ("0000" + i).slice(-4)))
}
for(i = 1; i <= 30; i++){
walk_w.push(PIXI.Texture.fromFrame("cubot/walk_w/" + ("0000" + i).slice(-4)))
}
var clip_wal_e = new PIXI.extras.AnimatedSprite(walk_e);
clip_wal_e.animationSpeed = 0.5;
clip_wal_e.onFrameChange = function(){
if(this.currentFrame === 29){
this.gotoAndPlay(10);
}
};
var clip_wal_n = new PIXI.extras.AnimatedSprite(walk_n);
clip_wal_n.animationSpeed = 0.5;
clip_wal_n.onFrameChange = function(){
if(this.currentFrame === 29){
this.gotoAndPlay(10);
}
};
var clip_wal_s = new PIXI.extras.AnimatedSprite(walk_s);
clip_wal_s.animationSpeed = 0.5;
clip_wal_s.onFrameChange = function(){
if(this.currentFrame === 29){
this.gotoAndPlay(10);
}
};
var clip_wal_w = new PIXI.extras.AnimatedSprite(walk_w);
clip_wal_w.animationSpeed = 0.5;
clip_wal_w.onFrameChange = function(){
if(this.currentFrame === 29){
this.gotoAndPlay(10);
}
};
var clips = {"walk_e": clip_wal_e,
"walk_n":clip_wal_n,
"walk_s":clip_wal_s,
"walk_w":clip_wal_w};
return clips;
}
function getObjectTexture(obj, selected){
switch(obj.type){
case OBJ_CUBOT:
//Tortoise
if(selected){
return PIXI.Texture.fromFrame("cubot/walk_w/0001");
} else {
switch (obj.direction){
case DIR_NORTH:
return PIXI.Texture.fromFrame("cubot/walk_n/0001");
case DIR_EAST:
return PIXI.Texture.fromFrame("cubot/walk_e/0001");
case DIR_SOUTH:
return PIXI.Texture.fromFrame("cubot/walk_s/0001");
case DIR_WEST:
return PIXI.Texture.fromFrame("cubot/walk_w/0001");
}
}
break;
case OBJ_PLANT:
//Plant
if(selected){
return PIXI.Texture.fromFrame("objects/plant1_s");
} else {
return PIXI.Texture.fromFrame("objects/plant1");
}
case OBJ_KILN:
//Kiln
if(selected){
return PIXI.Texture.fromFrame("objects/kiln_s");
} else {
return PIXI.Texture.fromFrame("objects/kiln");
}
case OBJ_DIGESTER:
//Digester
return PIXI.Texture.fromFrame("objects/digester");
case OBJ_ROCKET:
//Rocket
return PIXI.Texture.fromFrame("objects/rocket");
}
}
function getZPosition(type, x, y) {
switch (type){
case 1:
case 2:
case 3:
case 4:
return x + y + 0.1;
case 5:
return x + y + + 11.1;
}
}
function getXPosition(type, x, y) {
switch (type){
case OBJ_CUBOT:
return (x - y) * 64;
case OBJ_PLANT:
return (x - y) * 64 + 32;
case OBJ_KILN:
return (x - y) * 64;
case OBJ_DIGESTER:
return ((x - y) * 64) - 64;
case OBJ_ROCKET:
return (x - y) * 64;
}
}
function getYPosition(type, x, y) {
switch (type){
case OBJ_CUBOT:
return ((x + y) * 32) - 8;
case OBJ_PLANT:
return ((x + y) * 32) - 26;
case OBJ_KILN:
return ((x + y) * 32) - 58;
case OBJ_DIGESTER:
return ((x + y) * 32) - 64;
case OBJ_ROCKET:
return ((x + y) * 32) - 128;
}
}
/**
* Object an object with the new instance from the server
* @param object
* @param responseObj
*/
function updateGameObject(object, responseObj){
//Update location
if (object.x !== responseObj.x || object.y !== responseObj.y) {
//location changed
moveObject(responseObj.x, responseObj.y, object);
}
//Overwrite object fields
for(var key in responseObj){
object[key] = responseObj[key];
}
if(object.type === OBJ_CUBOT){
// object.sprite.x = getXPosition(object.type, object.x, object.y);
// object.sprite.y = getYPosition(object.type, object.x, object.y);
// object.sprite.z = getZPosition(object.type, object.x, object.y);
if(object.action === ACTION_WALK){
//Walking
switch (object.direction){
case DIR_NORTH:
object.clips.walk_n.x = object.sprite.x;
object.clips.walk_n.y = object.sprite.y;
object.clips.walk_n.z = object.sprite.z;
if(!object.clips.walk_n.visible) {
object.clips.walk_n.visible = true;
object.clips.walk_n.play();
object.clips.walk_e.visible = false;
object.clips.walk_s.visible = false;
object.clips.walk_w.visible = false;
}
break;
case DIR_EAST:
object.clips.walk_e.x = object.sprite.x;
object.clips.walk_e.y = object.sprite.y;
object.clips.walk_e.z = object.sprite.z;
if(!object.clips.walk_e.visible){
object.clips.walk_n.visible = false;
object.clips.walk_e.visible = true;
object.clips.walk_e.play();
object.clips.walk_s.visible = false;
object.clips.walk_w.visible = false;
}
break;
case DIR_SOUTH:
object.clips.walk_s.x = object.sprite.x;
object.clips.walk_s.y = object.sprite.y;
object.clips.walk_s.z = object.sprite.z;
if(!object.clips.walk_s.visible){
object.clips.walk_n.visible = false;
object.clips.walk_e.visible = false;
object.clips.walk_s.visible = true;
object.clips.walk_s.play();
object.clips.walk_w.visible = false;
}
break;
case DIR_WEST:
object.clips.walk_w.x = object.sprite.x;
object.clips.walk_w.y = object.sprite.y;
object.clips.walk_w.z = object.sprite.z;
if(!object.clips.walk_s.visible){
object.clips.walk_n.visible = false;
object.clips.walk_e.visible = false;
object.clips.walk_s.visible = false;
object.clips.walk_w.visible = true;
object.clips.walk_w.play();
}
break;
}
}
}
return object;
}
/**
* Called each frame
*/
function update(){
if (this.walking === undefined) {
this.walking = 0;
} else if (this.walking > 0) {
//The object has more walking frames to do
for(clip in this.clips){
this.clips[clip].x += this.dx;
this.clips[clip].y += this.dy;
}
this.walking--;
if (this.walking === 0 && this.recalculateZAfter) {
//Finished walking cycle
for(clip in this.clips){
this.clips[clip].z = this.y + this.x + 0.1;
}
this.recalculateZAfter = false;
}
}
}
function createGameObject(objData){
console.log(objData);
objData.sprite = new PIXI.Sprite(getObjectTexture(objData));
objData.sprite.x = getXPosition(objData.type, objData.x, objData.y);
objData.sprite.y = getYPosition(objData.type, objData.x, objData.y);
objData.sprite.z = getZPosition(objData.type, objData.x, objData.y);
objData.sprite.interactive = true;
objData.sprite.buttonMode = true;
objData.sprite.on("click", function(){
console.log(objData);
});
objData.sprite.on("pointerover", function(){
objData.sprite.texture = getObjectTexture(objData, true);
});
objData.sprite.on("pointerout", function(){
objData.sprite.texture = getObjectTexture(objData, false);
});
//Setup Inventory
// createInventory(objData);
objData.update = update;
if(objData.type === OBJ_CUBOT){
objData.clips = getCubotAnimatedSprites();
objData.clips.walk_e.visible = false;
objData.clips.walk_n.visible = false;
objData.clips.walk_s.visible = false;
objData.clips.walk_w.visible = false;
game.worldLayer.addChild(objData.clips.walk_e);
game.worldLayer.addChild(objData.clips.walk_n);
game.worldLayer.addChild(objData.clips.walk_s);
game.worldLayer.addChild(objData.clips.walk_w);
} else {
game.worldLayer.addChild(objData.sprite);
}
return objData;
}

View File

@ -1,92 +0,0 @@
TILE_PLAIN = 0;
TILE_WALL = 1;
TILE_IRON = 2;
TILE_COPPER = 3;
getTileYOffset = function(terrainType) {
if (terrainType === TILE_WALL) {
return -40;
} else {
return 0;
}
};
getTileXOffset = function(terrainType) {
return 0;
};
getTileHitBox = function(terrainType) {
if (terrainType === TILE_PLAIN) {
return new PIXI.Polygon(
new PIXI.Point(64, 0),
new PIXI.Point(128, 32),
new PIXI.Point(64, 64),
new PIXI.Point(0, 32)
)
} else if(terrainType === TILE_WALL) {
return new PIXI.Polygon(
new PIXI.Point(64, 0),
new PIXI.Point(128, 32),
new PIXI.Point(128, 72),
new PIXI.Point(64, 103),
new PIXI.Point(0, 72),
new PIXI.Point(0, 32)
);
}
};
TILE_TEXTURE = function(terrainType, selected) {
switch (terrainType){
case TILE_PLAIN:
return selected ? PIXI.Texture.fromFrame("tiles/plain_s") : PIXI.Texture.fromFrame("tiles/plain");
case TILE_WALL:
return selected ? PIXI.Texture.fromFrame("tiles/wall_s") : PIXI.Texture.fromFrame("tiles/wall");
case TILE_IRON:
return selected ? PIXI.Texture.fromFrame("tiles/iron") : PIXI.Texture.fromFrame("tiles/iron");
case TILE_COPPER:
return selected ? PIXI.Texture.fromFrame("tiles/copper") : PIXI.Texture.fromFrame("tiles/copper");
}
};
function Tile(terrainType) {
this.sprite = new PIXI.Sprite(TILE_TEXTURE(terrainType, false));
this.sprite.hitArea = getTileHitBox(terrainType);
this.sprite.terrainType = terrainType;
//Setup Events
//todo: We are assigning an event to each tile (256), is it efficient?
this.sprite.interactive = true;
this.sprite.on("pointerover", function() {
this.texture = TILE_TEXTURE(this.terrainType, true);
//TODO Show tooltip / debug info here
});
this.sprite.on("pointerout", function() {
this.texture = TILE_TEXTURE(this.terrainType, false);
});
//Behave like background when clicked
this.sprite.on("pointerdown", pointerDown);
this.sprite.on("pointerup", bgPointerUp);
this.sprite.on("pointerupoutside", bgPointerUp);
}
function pointerDown(e) {
game.pointerdown = true;
game.pointerFirstClick = e.data.getLocalPosition(game.rootContainer);
}
function bgPointerUp() {
game.pointerdown = false;
game.pointerLastDrag = null;
}

View File

@ -1,240 +0,0 @@
WORLD_WIDTH = 16;
WORLD_HEIGHT = 16;
/**
*
* @param terrain
* @constructor
*/
function Word(terrain) {
setupWorldLayer(this);
// game.worldLayer = new PIXI.Container();
this.tiles = {};
this.objects = [];
var self = this;
for (var x = 0; x < WORLD_HEIGHT; x++) {
for (var y = 0; y < WORLD_HEIGHT; y++) {
var terrainType = terrain[y * WORLD_WIDTH + x];
var tile = new Tile(terrainType);
tile.sprite.x = (x - y) * 64 + getTileXOffset(terrainType);
tile.sprite.y = (x + y) * 32 + getTileYOffset(terrainType);
tile.sprite.z = y + x;
this.tiles[x + ',' + y] = tile;
game.worldLayer.addChild(tile.sprite);
game.rootContainer.addChild(game.worldLayer);
}
}
game.worldLayer.children.sort(depthCompare);
/**
* Update object from parsed JSON string sent from the server
* @param response parsed JSON string sent from the server
*/
this.updateObjects = function(response) {
//Mark objects as not updated
for(var i = 0; i < self.objects.length ; i++){
self.objects[i].updated = false;
}
for(var i = 0; i < response.length ; i++){
response[i].updated = true;
//Update/Create the object
var existingObject = self.getObject(response[i].id);
if(existingObject !== null){
//Object already exists
existingObject = updateGameObject(existingObject, response[i]);
} else {
//Object is new
var newObj = createGameObject(response[i]);
self.addObject(newObj);
}
}
//Delete not updated objects (see above comments)
for (var i = 0; i < self.objects.length; i++) {
if (!self.objects[i].updated) {
console.log("DEBUG: removed " + self.objects[i].id);
game.worldLayer.removeChild(self.objects[i].sprite);
self.objects.splice(i, 1);
}
}
game.worldLayer.children.sort(depthCompare);
};
/**
* Add an object the the 'current' objects
* @param object
*/
this.addObject = function(object) {
self.objects.push(object);
};
/**
* Get object from the list of 'current' objects (Objects shown on the screen)
* @param id objectId of the object
*/
this.getObject = function(id) {
for(var i = 0; i < self.objects.length; i++) {
if (self.objects[i].id === id) {
return self.objects[i];
}
}
return null;
};
this.update = function(terrain){
for (key in this.tiles) {
game.worldLayer.removeChild(this.tiles[key].sprite);
}
for (var j = 0; j < this.objects.length; j++) {
game.worldLayer.removeChild(this.objects[j].sprite);
}
this.tiles = {};
this.objects = [];
for (var x = 0; x < WORLD_HEIGHT; x++) {
for (var y = 0; y < WORLD_HEIGHT; y++) {
var terrainType = terrain[y * WORLD_WIDTH + x];
var tile = new Tile(terrainType);
tile.sprite.x = (x - y) * 64 + getTileXOffset(terrainType);
tile.sprite.y = (x + y) * 32 + getTileYOffset(terrainType);
tile.sprite.z = y + x;
this.tiles[x + ',' + y] = tile;
game.worldLayer.addChild(tile.sprite);
game.rootContainer.addChild(game.worldLayer);
}
}
game.worldLayer.children.sort(depthCompare);
}
}
function setupWorldLayer(world) {
game.worldLayer = new PIXI.Container();
game.worldLayer.x = 736;
game.worldLayer.y = -32;
game.rootContainer.addChild(game.worldLayer);
//NORTH
var arrow_north = new PIXI.Sprite(PIXI.Texture.fromFrame("ui/arrow_north"));
arrow_north.x = 528;
arrow_north.y = 224;
arrow_north.interactive = true;
arrow_north.buttonMode = true;
arrow_north.on("pointerover", function () {
arrow_north.texture = PIXI.Texture.fromFrame("ui/arrow_north_s");
});
arrow_north.on("pointerout", function () {
arrow_north.texture = PIXI.Texture.fromFrame("ui/arrow_north");
});
arrow_north.on("pointerdown", function () {
game.worldY--;
client.requestTerrain()
});
game.worldLayer.addChild(arrow_north);
//EAST
var arrow_east = new PIXI.Sprite(PIXI.Texture.fromFrame("ui/arrow_east"));
arrow_east.x = 528;
arrow_east.y = 750;
arrow_east.interactive = true;
arrow_east.buttonMode = true;
arrow_east.on("pointerover", function () {
arrow_east.texture = PIXI.Texture.fromFrame("ui/arrow_east_s");
});
arrow_east.on("pointerout", function () {
arrow_east.texture = PIXI.Texture.fromFrame("ui/arrow_east");
});
arrow_east.on("pointerdown", function () {
game.worldX++;
client.requestTerrain();
});
game.worldLayer.addChild(arrow_east);
//SOUTH
var arrow_south = new PIXI.Sprite(PIXI.Texture.fromFrame("ui/arrow_south"));
arrow_south.x = -496;
arrow_south.y = 750;
arrow_south.interactive = true;
arrow_south.buttonMode = true;
arrow_south.on("pointerover", function () {
arrow_south.texture = PIXI.Texture.fromFrame("ui/arrow_south_s");
});
arrow_south.on("pointerout", function () {
arrow_south.texture = PIXI.Texture.fromFrame("ui/arrow_south");
});
arrow_south.on("pointerdown", function () {
game.worldY++;
client.requestTerrain();
});
game.worldLayer.addChild(arrow_south);
//WEST
var arrow_west = new PIXI.Sprite(PIXI.Texture.fromFrame("ui/arrow_west"));
arrow_west.x = -496;
arrow_west.y = 224;
arrow_west.interactive = true;
arrow_west.buttonMode = true;
arrow_west.on("pointerover", function () {
arrow_west.texture = PIXI.Texture.fromFrame("ui/arrow_west_s");
});
arrow_west.on("pointerout", function () {
arrow_west.texture = PIXI.Texture.fromFrame("ui/arrow_west");
});
arrow_west.on("pointerdown", function () {
game.worldX--;
client.requestTerrain();
});
game.worldLayer.addChild(arrow_west)
}
/**
* Compare depth of two sprites based on their z property
*/
function depthCompare(a, b) {
if (a.z < b.z) {
return -1;
}
if (a.z > b.z) {
return 1;
}
return 0;
}

View File

@ -1,311 +0,0 @@
"use strict";
console.log("hello")
// --------------------------
// MAR loop
function gameLoop() {
requestAnimationFrame(gameLoop);
//UPDATE EFFECTS
for (var i = 0; i < MAR.effects.length; i++) {
MAR.effects[i].update();
}
//Update objects
for (var j = 0; j < MAR.objects.length; j++) {
if (MAR.objects[j].objectType === 1) {-
MAR.objects[j].update();
}
}
MAR.renderer.render(MAR.rootContainer);
}
var setupCallback = function () {
getWorldTerrain();
gameLoop();
};
function tick() {
getGameEffects();
getGameObjects();
//Update indicators
for (var i = 0; i < MAR.objects.length; i++) {
if (MAR.objects[i].indicator !== undefined) {
MAR.objects[i].indicator.updateIcon();
}
}
//Update debug text
MAR.timeText.text = "gameTime: " + MAR.time;
}
function getGameObjects() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "./mar/objects.php?x=" + MAR.currentLocX + "&y=" + MAR.currentLocY, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
var jsonResponse = JSON.parse(xhr.responseText);
for (var i = 0; i < MAR.objects.length; i++) {
MAR.objects[i].updated = false;
}
for (var i = 0; i < jsonResponse.length; i++) {
var obj = getObject(jsonResponse[i].i);
if (obj !== null) {
//OBJECT already exist, update
obj.updated = true;
if (obj.objectType === 1) {
//Update direction
obj.direction = jsonResponse[i].d;
//Update location
if (obj.x !== jsonResponse[i].x || obj.y !== jsonResponse[i].y) {
//location changed
moveObject(jsonResponse[i].x, jsonResponse[i].y, obj);
}
//update held item
obj.heldItem = jsonResponse[i].h;
//Update action
obj.action = jsonResponse[i].a;
} else if (obj.objectType === 3) {
//Kiln object already exists, update
obj.qi = jsonResponse[i].qi; //Queued Iron
obj.qc = jsonResponse[i].qc; //Queued Copper
obj.ci = jsonResponse[i].ci; //Cooked Iron
obj.cc = jsonResponse[i].cc; //Cooked Copper
obj.f = jsonResponse[i].f; //Fuel
}
} else {
var newObj = new GameObject(jsonResponse[i]);
newObj.updated = true;
MAR.worldLayer.addChild(newObj.sprite);
MAR.objects.push(newObj);
console.log("DEBUG: added " + newObj.id);
}
}
//Delete not updated objects (see above comments)
for (var i = 0; i < MAR.objects.length; i++) {
if (!MAR.objects[i].updated) {
console.log("DEBUG: removed " + MAR.objects[i].id);
MAR.worldLayer.removeChild(MAR.objects[i].sprite);
MAR.objects.splice(i, 1);
}
}
MAR.worldLayer.children.sort(depthCompare);
}
};
xhr.send(null);
}
// --------------------------
// Display a single effect
function displayEffect(effect) {
if (effect.t === "ERROR") {
var newEffect = new IconEffect(effect.x, effect.y, "err_icon");
MAR.effects.push(newEffect);
addToWorldLayer(newEffect.sprite);
}
if (effect.t === "WARNING") {
var newEffect = new IconEffect(effect.x, effect.y, "warn_icon");
MAR.effects.push(newEffect);
addToWorldLayer(newEffect.sprite);
}
if (effect.t === "A_EMOTE") {
var newEffect = new IconEffect(effect.x, effect.y, "A_icon");
MAR.effects.push(newEffect);
addToWorldLayer(newEffect.sprite);
}
}
// --------------------------
// Query the MAR API to get the MAR effects
function getGameEffects() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "./mar/effects.php?x=" + MAR.currentLocX + "&y=" + MAR.currentLocY, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
var effects = JSON.parse(xhr.responseText);
for (var i = 0; i < effects.length; i++) {
displayEffect(effects[i]);
}
MAR.worldLayer.children.sort(depthCompare);
}
};
xhr.send(null);
}
function getWorldTerrain() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "./mar/terrain.php?x=" + MAR.currentLocX + "&y=" + MAR.currentLocY, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
var currentTerrain = JSON.parse(xhr.responseText);
//Calculate wall height
//First pass, set wall height to 2 for each wall tile with 3+ adjacent wall tile (diagonals don't count)
for (var y = 0; y < 16; y++) {
for (var x = 0; x < 16; x++) {
var tile = new Tile(currentTerrain[x * 16 + y]);
//Calculate neighbors
var neighbors = 0;
if (currentTerrain[x * 16 + y] === 1) {
if (currentTerrain[x * 16 + y - 16] === 1 ||
(currentTerrain[x * 16 + y - 16] !== undefined && currentTerrain[x * 16 + y - 16].wallHeight >= 1)) {
neighbors++;
} else {
}
if (currentTerrain[x * 16 + y + 16] === 1 ||
(currentTerrain[x * 16 + y + 16] !== undefined && currentTerrain[x * 16 + y + 16].wallHeight >= 1)) {
neighbors++;
}
if (currentTerrain[x * 16 + y + 1] === 1 ||
(currentTerrain[x * 16 + y + 1] !== undefined && currentTerrain[x * 16 + y + 1].wallHeight >= 1)) {
neighbors++;
}
if (currentTerrain[x * 16 + y - 1] === 1 ||
(currentTerrain[x * 16 + y - 1] !== undefined && currentTerrain[x * 16 + y - 1].wallHeight >= 1)) {
neighbors++;
}
if (neighbors >= 4) {
tile.wallHeight++;
}
}
tile.sprite.tileX = x;
tile.sprite.tileY = y;
tile.sprite.x += (x - y) * 64;
tile.sprite.y += (x + y) * 32;
tile.sprite.z += y + x;
//A bit hacky but it'll work for now...
currentTerrain[x * 16 + y] = tile;
}
}
//currentTerrain is no longer an array of ints but an array of Tile objects
//Add tiles to world layer
for (var i = 0; i < currentTerrain.length; i++) {
if (currentTerrain[i].sprite.tileId === 1) {
if (currentTerrain[i].wallHeight === 1) {
MAR.worldLayer.addChild(currentTerrain[i].sprite);
} else if (currentTerrain[i].wallHeight === 2) {
MAR.worldLayer.addChild(currentTerrain[i].sprite);
//Add duplicate sprite on top (63 px up)
var topTile = new Tile(1);
topTile.sprite.tileX = currentTerrain[i].sprite.tileX;
topTile.sprite.tileY = currentTerrain[i].sprite.tileY;
topTile.sprite.tileId = 1;
topTile.sprite.x = currentTerrain[i].sprite.x;
topTile.sprite.y = currentTerrain[i].sprite.y - 40;
topTile.sprite.z = currentTerrain[i].sprite.z + 1.1;
MAR.worldLayer.addChild(topTile.sprite);
MAR.tiles.push(topTile);
}
} else {
MAR.worldLayer.addChild(currentTerrain[i].sprite);
}
MAR.tiles.push(currentTerrain[i]);
}
MAR.worldLayer.children.sort(depthCompare);
}
};
xhr.send(null);
}
// --------------------------
// Query the MAR API to get MAR time
function getGameTime() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "./mar/time.php", true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
if (MAR.time !== xhr.responseText) {
MAR.timeChanged = true;
MAR.time = xhr.responseText;
} else {
MAR.timeChanged = false;
}
}
};
xhr.send(null);
}
// --------------------------
// Change an object's location and initialise the move animation
function moveObject(newX, newY, gameObject) {
//Resync object
gameObject.sprite.x = (gameObject.x - gameObject.y) * 64;
gameObject.sprite.y = ((gameObject.x + gameObject.y) * 32) - 16;
var tiledx = newX - gameObject.x;
var tiledy = newY - gameObject.y;
gameObject.dx = 0;
gameObject.dy = 0;
//Recalculate position
gameObject.x = newX;
gameObject.y = newY;
if (tiledx === 1) {
//We need to move 128px to the right and the minimum tick length is 1s.
//This means that we have maximum 60 frames to do the animation
gameObject.dx = 64 / 58;
gameObject.dy = 32 / 58;
gameObject.walking = 58;
//Recalculate Z order immediately
gameObject.sprite.z = gameObject.y + gameObject.x + 0.1;
} else if (tiledx === -1) {
gameObject.dx = -64 / 58;
gameObject.dy = -32 / 58;
gameObject.walking = 58;
//The Z order needs to be recalculated when the movement ends
gameObject.recalculateZAfter = true;
} else if (tiledy === 1) {
gameObject.dx = -64 / 58;
gameObject.dy = 32 / 58;
gameObject.walking = 58;
//Recalculate Z order immediately
gameObject.sprite.z = gameObject.y + gameObject.x + 0.1;
} else if (tiledy === -1) {
gameObject.dx = 64 / 58;
gameObject.dy = -32 / 58;
gameObject.walking = 58;
//The Z order needs to be recalculated when the movement ends
gameObject.recalculateZAfter = true;
}
MAR.worldLayer.children.sort(depthCompare);
}

File diff suppressed because it is too large Load Diff

21
mar/old/pixi.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,826 +0,0 @@
"use strict";
var MAR = {
RENDERER_BG: 0x282828,
currentLocX: 0,
currentLocY: 0,
effects: [],
tiles: [],
objects: []
};
if (fullscreen) {
MAR.RENDERER_WIDTH = window.innerWidth - 4;
MAR.RENDERER_HEIGHT = window.innerHeight - 4;
} else {
MAR.RENDERER_WIDTH = document.getElementById("game").clientWidth;
MAR.RENDERER_HEIGHT = (window.innerHeight / 1.25);
}
// --------------------------
// Load Sprites
PIXI.loader
.add("./mar/sprites/cubot.json")
.add("biomass", "./mar/sprites/biomass.png")
.add("rocket", "./mar/sprites/rocket.png")
.add("kiln", "./mar/sprites/kiln.png")
.add("digester", "./mar/sprites/digester.png")
.add("arrow_north", "./mar/sprites/arrow_north.png")
.add("arrow_north_s", "./mar/sprites/arrow_north_s.png")
.add("arrow_west", "./mar/sprites/arrow_west.png")
.add("arrow_west_s", "./mar/sprites/arrow_west_s.png")
.add("arrow_south", "./mar/sprites/arrow_south.png")
.add("arrow_south_s", "./mar/sprites/arrow_south_s.png")
.add("arrow_east", "./mar/sprites/arrow_east.png")
.add("arrow_east_s", "./mar/sprites/arrow_east_s.png")
.add("plain", "./mar/sprites/sample.png")
.add("tile_iron", "./mar/sprites/tile_iron.png")
.add("tile_copper", "./mar/sprites/tile_copper.png")
.add("plain_s", "./mar/sprites/Tile_iso_selected.png")
.add("wall", "./mar/sprites/Tile_iso _wall.png")
.add("wall_s", "./mar/sprites/Tile_iso _wall_s.png")
.add("GOURD_PLANT", "./mar/sprites/GOURD_PLANT.png")
.add("GOURD_PLANT_s", "./mar/sprites/GOURD_PLANT_s.png")
.add("LETTUCE_PLANT", "./mar/sprites/LETTUCE_PLANT.png")
.add("LETTUCE_PLANT_s", "./mar/sprites/LETTUCE_PLANT_s.png")
.add("OAK_TREE", "./mar/sprites/OAK_TREE.png")
.add("egg", "./mar/sprites/egg.png")
.add("plant1", "./mar/sprites/plant1.png")
.add("err_icon", "./mar/sprites/err_icon.png")
.add("warn_icon", "./mar/sprites/warn_icon.png")
.add("A_icon", "./mar/sprites/A_icon.png");
PIXI.loader
.on("progress", progressHandler)
.load(loaderCallback);
// --------------------------
// Handle progress change event
function progressHandler(loader, resource) {
//TODO - implement loading bar
}
// --------------------------
// Loader callback (Setup)
function loaderCallback() {
setupRenderer();
setupBackground();
// setupKeyBoard();
setupWorldLayer();
setupAutoUpdate();
setupDebugText();
setupCallback();
}
function addToWorldLayer(sprite) {
MAR.worldLayer.addChild(sprite);
MAR.worldLayer.children.sort(depthCompare);
}
// --------------------------
// Compare depth of two sprites based on their z property
function depthCompare(a, b) {
if (a.z < b.z) {
return -1;
}
if (a.z > b.z) {
return 1;
}
return 0;
}
function setupDebugText() {
MAR.textLayer = new PIXI.Container();
MAR.rootContainer.addChild(MAR.textLayer);
//Debug text
MAR.currentTileText = new PIXI.Text("", {fontSize: 12, fontFamily: "c64_mono", fill: "white"});
MAR.currentTileText.position.x = MAR.RENDERER_WIDTH - 100;
MAR.currentTileText.position.y = 10;
MAR.textLayer.addChild(MAR.currentTileText);
MAR.currentWorldText = new PIXI.Text("World 0,0", {fontSize: 12, fontFamily: "c64_mono", fill: "white"});
MAR.currentWorldText.position.x = MAR.RENDERER_WIDTH - 150;
MAR.currentWorldText.position.y = 100;
MAR.textLayer.addChild(MAR.currentWorldText);
MAR.timeText = new PIXI.Text("gameTime: 0", {fontSize: 12, fontFamily: "c64_mono", fill: "white"});
MAR.timeText.position.x = MAR.RENDERER_WIDTH - 200;
MAR.timeText.position.y = 70;
MAR.textLayer.addChild(MAR.timeText);
// Watermark
MAR.watermark = new PIXI.Text("Much Assembly Required V3.0", {fontSize: 20, fontFamily: "c64_mono", fill: "grey"});
MAR.watermark.position.x = MAR.RENDERER_WIDTH - 450;
MAR.watermark.position.y = MAR.RENDERER_HEIGHT - 30;
MAR.textLayer.addChild(MAR.watermark)
}
function setupAutoUpdate() {
window.setInterval(function () {
getGameTime();
if (MAR.timeChanged) {
tick();
}
}, 334);
}
function setupWorldLayer() {
MAR.worldLayer = new PIXI.Container();
MAR.worldLayer.x = 736;
MAR.worldLayer.y = -32;
MAR.rootContainer.addChild(MAR.worldLayer);
//NORTH
var arrow_north = new PIXI.Sprite(PIXI.loader.resources["arrow_north"].texture);
arrow_north.x = 528;
arrow_north.y = 224;
arrow_north.interactive = true;
arrow_north.buttonMode = true;
arrow_north.on("pointerover", function () {
arrow_north.texture = PIXI.loader.resources["arrow_north_s"].texture;
});
arrow_north.on("pointerout", function () {
arrow_north.texture = PIXI.loader.resources["arrow_north"].texture;
});
arrow_north.on("pointerdown", function () {
clearWorldLayer();
MAR.currentLocY--;
getWorldTerrain();
getGameObjects();
updateCurrentWorldText();
});
MAR.worldLayer.addChild(arrow_north);
//EAST
var arrow_east = new PIXI.Sprite(PIXI.loader.resources["arrow_east"].texture);
arrow_east.x = 528;
arrow_east.y = 750;
arrow_east.interactive = true;
arrow_east.buttonMode = true;
arrow_east.on("pointerover", function () {
arrow_east.texture = PIXI.loader.resources["arrow_east_s"].texture;
});
arrow_east.on("pointerout", function () {
arrow_east.texture = PIXI.loader.resources["arrow_east"].texture;
});
arrow_east.on("pointerdown", function () {
clearWorldLayer();
MAR.currentLocX++;
getWorldTerrain();
getGameObjects();
updateCurrentWorldText();
});
MAR.worldLayer.addChild(arrow_east);
//SOUTH
var arrow_south = new PIXI.Sprite(PIXI.loader.resources["arrow_south"].texture);
arrow_south.x = -496;
arrow_south.y = 750;
arrow_south.interactive = true;
arrow_south.buttonMode = true;
arrow_south.on("pointerover", function () {
arrow_south.texture = PIXI.loader.resources["arrow_south_s"].texture;
});
arrow_south.on("pointerout", function () {
arrow_south.texture = PIXI.loader.resources["arrow_south"].texture;
});
arrow_south.on("pointerdown", function () {
clearWorldLayer();
MAR.currentLocY++;
getWorldTerrain();
getGameObjects();
updateCurrentWorldText();
});
MAR.worldLayer.addChild(arrow_south);
//WEST
var arrow_west = new PIXI.Sprite(PIXI.loader.resources["arrow_west"].texture);
arrow_west.x = -496;
arrow_west.y = 224;
arrow_west.interactive = true;
arrow_west.buttonMode = true;
arrow_west.on("pointerover", function () {
arrow_west.texture = PIXI.loader.resources["arrow_west_s"].texture;
});
arrow_west.on("pointerout", function () {
arrow_west.texture = PIXI.loader.resources["arrow_west"].texture;
});
arrow_west.on("pointerdown", function () {
clearWorldLayer();
MAR.currentLocX--;
getWorldTerrain();
getGameObjects();
updateCurrentWorldText();
});
MAR.worldLayer.addChild(arrow_west)
}
function clearWorldLayer() {
for (var i = 0; i < MAR.tiles.length; i++) {
MAR.worldLayer.removeChild(MAR.tiles[i].sprite);
}
for (var j = 0; j < MAR.objects.length; j++) {
MAR.worldLayer.removeChild(MAR.objects[j].sprite);
if (MAR.objects[j].indicator !== undefined) {
MAR.worldLayer.removeChild(MAR.objects[j].indicator.sprite);
}
//todo Remove inv indicator as well
}
MAR.objects = [];
MAR.tiles = [];
}
function updateCurrentWorldText() {
MAR.currentWorldText.text = MAR.currentLocX + "," + MAR.currentLocY;
}
function setupKeyBoard() {
//SETUP KEYBOARD LISTENERS
// var leftArrow = keyboard(37);
// var rightArrow = keyboard(39);
var downArrow = keyboard(40);
var upArrow = keyboard(38);
downArrow.press = function () {
MAR.worldLayer.scale.x -= 0.1;
MAR.worldLayer.scale.y -= 0.1;
};
upArrow.press = function () {
MAR.worldLayer.scale.x += 0.1;
MAR.worldLayer.scale.y += 0.1;
}
}
function setupBackground() {
//SETUP BACKGROUND LAYER & PANNING
MAR.bgLayer = new PIXI.Container();
MAR.rootContainer.addChild(MAR.bgLayer);
MAR.bg = new PIXI.Sprite();
MAR.bg.interactive = true;
MAR.bg.hitArea = new PIXI.Rectangle(0, 0, MAR.RENDERER_WIDTH, MAR.RENDERER_HEIGHT);
MAR.bg.on("pointerover", function () {
MAR.currentTileText.text = "-";
});
MAR.bg.on("pointerdown", function (e) {
MAR.pointerdown = true;
MAR.pointerFirstClick = e.data.getLocalPosition(MAR.rootContainer);
});
MAR.bg.on("pointerup", function () {
MAR.pointerdown = false;
MAR.pointerLastDrag = null;
});
MAR.bg.on("pointerupoutside", function () {
MAR.pointerdown = false;
MAR.pointerLastDrag = null;
});
MAR.bg.on("pointermove", function (e) {
if (MAR.pointerdown === true) {
var currentMouse = e.data.getLocalPosition(MAR.rootContainer);
if (MAR.pointerLastDrag != null) {
MAR.worldLayer.position.x += currentMouse.x - MAR.pointerLastDrag.x;
MAR.worldLayer.position.y += currentMouse.y - MAR.pointerLastDrag.y;
} else {
MAR.worldLayer.position.x += currentMouse.x - MAR.pointerFirstClick.x;
MAR.worldLayer.position.y += currentMouse.y - MAR.pointerFirstClick.y;
}
MAR.pointerLastDrag = currentMouse;
}
});
MAR.bgLayer.addChild(MAR.bg);
}
function setupRenderer() {
MAR.renderer = PIXI.autoDetectRenderer(256, 256);
document.getElementById("game").appendChild(MAR.renderer.view);
MAR.rootContainer = new PIXI.Container();
MAR.renderer.backgroundColor = MAR.RENDERER_BG;
MAR.renderer.resize(MAR.RENDERER_WIDTH, MAR.RENDERER_HEIGHT);
window.onresize = function (event) {
if (fullscreen) {
MAR.RENDERER_WIDTH = window.innerWidth - 4;
MAR.RENDERER_HEIGHT = window.innerHeight - 4;
} else {
MAR.RENDERER_WIDTH = document.getElementById("game").clientWidth;
MAR.RENDERER_HEIGHT = (window.innerHeight / 1.25);
}
MAR.renderer.resize(MAR.RENDERER_WIDTH, MAR.RENDERER_HEIGHT);
}
}
// --------------------------
//From https://github.com/kittykatattack/learningPixi#keyboard
function keyboard(keyCode) {
var key = {};
key.code = keyCode;
key.isDown = false;
key.isUp = true;
key.press = undefined;
key.release = undefined;
//The downHandler
key.downHandler = function (event) {
if (event.keyCode === key.code) {
if (key.isUp && key.press) key.press();
key.isDown = true;
key.isUp = false;
}
event.preventDefault();
};
//The upHandler
key.upHandler = function (event) {
if (event.keyCode === key.code) {
if (key.isDown && key.release) key.release();
key.isDown = false;
key.isUp = true;
}
event.preventDefault();
};
//Attach event listeners
window.addEventListener(
"keydown", key.downHandler.bind(key), false
);
window.addEventListener(
"keyup", key.upHandler.bind(key), false
);
return key;
}
// --------------------------
// Classes
// Particle effect
function ParticleEffect(x, y, bp) {
this.x = x;
this.y = y;
this.bluePrint = bp;
this.framesLeft = bp.framesCount;
}
ParticleEffect.prototype.graphics = new PIXI.Graphics();
ParticleEffect.prototype.particles = [];
ParticleEffect.prototype.update = function () {
this.graphics.clear();
this.framesLeft--;
//Add new particles
while (this.particles.length < this.bluePrint.particleCount && this.framesLeft > 0) {
this.particles.push(this.bluePrint.createParticle(this.x, this.y));
}
//Draw & update particles
for (var i = 0; i < this.particles.length; i++) {
var p = this.particles[i];
var g = this.graphics;
g.beginFill(p.color);
g.drawRect(p.x, p.y, p.size, p.size);
g.endFill();
p.y += p.dy;
p.x += p.dx;
p.ttl--;
}
//Delete dead particles
var particles_ = this.particles.slice(); //Copy array
for (var j = 0; j < particles_.length; j++) {
if (particles_[j].ttl <= 0) {
this.particles.splice(j, 1);
}
}
//Delete effect
if (this.particles.length <= 0) {
MAR.rootContainer.removeChild(this.graphics);
}
};
//Icon effect
function IconEffect(x, y, resourceName) {
this.framesLeft = 55;
this.sprite = new PIXI.Sprite(PIXI.loader.resources[resourceName].texture);
this.sprite.alpha = 0.9;
this.sprite.x = ((x - y) * 64) + 40;
this.sprite.y = ((x + y) * 32) - 45;
this.sprite.z = y + x + 0.2;
}
IconEffect.prototype.update = function () {
if (this.framesLeft < 30) {
this.sprite.alpha = (this.framesLeft / 40);
//Remove itself
if (this.framesLeft === 0) {
MAR.rootContainer.removeChild(this.sprite);
}
}
this.framesLeft--;
};
//Game object
function GameObject(objData) {
this.objectType = objData.t;
this.x = objData.x;
this.y = objData.y;
this.direction = objData.d;
this.id = objData.i;
this.animSpeed = 1;
this.waitTicks = this.animSpeed;
//Create sprite
if (this.objectType === 1) {
this.heldItem = objData.h;
this.action = objData.a;
//Tortoise
var sprite = null;
if (this.direction === 0) {
//North
sprite = new PIXI.Sprite(PIXI.Texture.fromFrame("walk_n/0001"));
} else if (this.direction === 1) {
//East
sprite = new PIXI.Sprite(PIXI.Texture.fromFrame("walk_n/0001"));
} else if (this.direction === 2) {
//South
sprite = new PIXI.Sprite(PIXI.Texture.fromFrame("walk_n/0001"));
} else if (this.direction === 3) {
//West
sprite = new PIXI.Sprite(PIXI.Texture.fromFrame("walk_n/0001"));
}
sprite.y = ((this.x + this.y) * 32) - 8;
sprite.x = (this.x - this.y) * 64;
sprite.z = this.y + this.x + 0.1;
this.sprite = sprite;
//Add inventory indicator
this.indicator = new InventoryIndicator(this);
this.indicator.sprite = new PIXI.Text("", {fontSize: 12, fontFamily: "c64_mono", fill: "white"});//Will be replace by a texture
this.indicator.updateIcon = function () {
if (this.parentObj.heldItem === 1) {
this.sprite.text = "Biomass";
} else if (this.parentObj.heldItem === 2) {
this.sprite.text = "CH3OH";
} else if (this.parentObj.heldItem === 3) {
this.sprite.text = "Fe";
} else if (this.parentObj.heldItem === 4) {
this.sprite.text = "Cu";
} else if (this.parentObj.heldItem === 5) {
this.sprite.text = "Fe pl8";
} else if (this.parentObj.heldItem === 6) {
this.sprite.text = "Cu pl8";
} else {
this.sprite.text = "";
}
};
this.indicator.updateIcon();
this.indicator.updatePos();
addToWorldLayer(this.indicator.sprite);
} else if (this.objectType === 2) {
//Plant
var sprite = new PIXI.Sprite(PIXI.loader.resources["plant1"].texture); //Todo handle different plant styles
sprite.x = (this.x - this.y) * 64 + 32;
sprite.y = ((this.x + this.y) * 32) - 26;
sprite.z = this.y + this.x + 0.1;
this.sprite = sprite;
//todo life bar thingy indicator
} else if (this.objectType === 3) {
//Kiln
this.qi = objData.qi; //Queued Iron
this.qc = objData.qc; //Queued Copper
this.ci = objData.ci; //Cooked Iron
this.cc = objData.cc; //Cooked Copper
this.f = objData.f; //fuel
var sprite = new PIXI.Sprite(PIXI.loader.resources["kiln"].texture);
sprite.x = ((this.x - this.y) * 64);
sprite.y = ((this.x + this.y) * 32) - 58;
sprite.z = this.y + this.x + 0.1;
this.sprite = sprite;
//Add inventory indicator
this.indicator = new InventoryIndicator(this);
this.indicator.sprite = new PIXI.Text("", {fontSize: 12, fontFamily: "c64_mono", fill: "white"});//Will be replace by a texture
this.indicator.updateIcon = function () {
this.sprite.text = this.parentObj.qc + ":" + this.parentObj.qi + "\n" +
this.parentObj.cc + ":" + this.parentObj.ci + "\nf:" + this.parentObj.f;
};
this.indicator.updateIcon();
this.indicator.updatePos();
addToWorldLayer(this.indicator.sprite);
//todo life bar thingy indicator
} else if (this.objectType === 4) {
//Digester
var sprite = new PIXI.Sprite(PIXI.loader.resources["digester"].texture);
sprite.x = ((this.x - this.y) * 64) - 64;
sprite.y = ((this.x + this.y) * 32) - 64;
sprite.z = this.y + this.x + 11.1;
this.sprite = sprite;
//todo life bar thingy indicator
//todo inventory indicator
} else if (this.objectType === 5) {
//Rocket
var sprite = new PIXI.Sprite(PIXI.loader.resources["rocket"].texture);
sprite.x = (this.x - this.y) * 64;
sprite.y = ((this.x + this.y) * 32) - 128;
sprite.z = this.y + this.x + 0.1;
this.sprite = sprite;
//todo life bar thingy indicator
//todo progress indicator
}
}
GameObject.prototype.update = function () {
if (this.walking === undefined) {
this.walking = 0;
} else if (this.walking > 0) {
//The object has more walking frames to do
this.sprite.x += this.dx;
this.sprite.y += this.dy;
this.walking--;
if (this.walking === 0) {
//Finished walking cycle
if (this.recalculateZAfter) {
this.sprite.z = this.y + this.x + 0.1;
this.recalculateZAfter = false;
}
} else {
//Play 10 first frames then loop frames 10-30
if (this.frame === undefined) {
this.frame = 1;
} else if (this.frame === 30) {
this.frame = 10;
} else {
if (this.waitTicks === 0) {
this.frame++;
this.waitTicks = this.animSpeed;
} else {
this.waitTicks--;
}
}
}
}
if ((this.digging === undefined || isNaN(this.digging)) && this.action === 1) {
//Just started digging animation
console.log("started digging");
this.digging = 1;
this.action = 0;
} else {
//Continue digging animation
this.digging++;
if (this.digging === 41) {
//Reached end of animation
this.digging = undefined;
}
}
if (this.direction === 0) {
//North
if (this.walking !== 0) {
this.sprite.texture = PIXI.Texture.fromFrame("walk_n/" + ("0000" + this.frame).slice(-4));
} else if (this.digging > 0) {
//Digging
this.sprite.texture = PIXI.Texture.fromFrame("dig_n/" + ("0000" + this.digging).slice(-4));
} else {
this.sprite.texture = PIXI.Texture.fromFrame("walk_n/0001");
}
} else if (this.direction === 1) {
//East
if (this.walking !== 0) {
this.sprite.texture = PIXI.Texture.fromFrame("walk_e/" + ("0000" + this.frame).slice(-4));
} else if (this.digging > 0) {
//Digging
this.sprite.texture = PIXI.Texture.fromFrame("dig_e/" + ("0000" + this.digging).slice(-4));
} else {
this.sprite.texture = PIXI.Texture.fromFrame("walk_e/0001");
}
} else if (this.direction === 2) {
//South
if (this.walking !== 0) {
this.sprite.texture = PIXI.Texture.fromFrame("walk_s/" + ("0000" + this.frame).slice(-4));
} else if (this.digging > 0) {
//Digging
this.sprite.texture = PIXI.Texture.fromFrame("dig_s/" + ("0000" + this.digging).slice(-4));
} else {
this.sprite.texture = PIXI.Texture.fromFrame("walk_s/0001");
}
} else if (this.direction === 3) {
//West
if (this.walking !== 0) {
this.sprite.texture = PIXI.Texture.fromFrame("walk_w/" + ("0000" + this.frame).slice(-4));
} else if (this.digging > 0) {
//Digging
this.sprite.texture = PIXI.Texture.fromFrame("dig_w/" + ("0000" + this.digging).slice(-4));
} else {
this.sprite.texture = PIXI.Texture.fromFrame("walk_w/0001");
}
}
//Sync indicator icon location and z order
this.indicator.sprite.x = this.sprite.x;
this.indicator.sprite.y = this.sprite.y;
this.indicator.sprite.z = this.sprite.z + 0.1;
MAR.worldLayer.children.sort(depthCompare);
};
//Tile
function Tile(terrainType) {
if (terrainType === 0) {
this.sprite = new PIXI.Sprite(PIXI.loader.resources["plain"].texture);
this.sprite.x = 0;
this.sprite.y = 0;
this.sprite.z = 0;
this.sprite.hitArea = new PIXI.Polygon(
new PIXI.Point(64, 0),
new PIXI.Point(128, 32),
new PIXI.Point(64, 64),
new PIXI.Point(0, 32)
);
} else if (terrainType === 1) {
this.sprite = new PIXI.Sprite(PIXI.loader.resources["wall"].texture);
this.sprite.x = 0;
this.sprite.y = -40;
this.sprite.z = 0;
this.sprite.hitArea = new PIXI.Polygon(
new PIXI.Point(64, 0),
new PIXI.Point(128, 32),
new PIXI.Point(128, 72),
new PIXI.Point(64, 103),
new PIXI.Point(0, 72),
new PIXI.Point(0, 32)
);
this.wallHeight = 1;
} else if (terrainType === 2) {
this.sprite = new PIXI.Sprite(PIXI.loader.resources["tile_iron"].texture);
this.sprite.x = 0;
this.sprite.y = 0;
this.sprite.z = 0;
this.sprite.hitArea = new PIXI.Polygon(
new PIXI.Point(64, 0),
new PIXI.Point(128, 32),
new PIXI.Point(64, 64),
new PIXI.Point(0, 32)
);
} else if (terrainType === 3) {
this.sprite = new PIXI.Sprite(PIXI.loader.resources["tile_copper"].texture);
this.sprite.x = 0;
this.sprite.y = 0;
this.sprite.z = 0;
this.sprite.hitArea = new PIXI.Polygon(
new PIXI.Point(64, 0),
new PIXI.Point(128, 32),
new PIXI.Point(64, 64),
new PIXI.Point(0, 32)
);
}
this.sprite.tileId = terrainType;
//Assigning event to each tile inefficient?
this.sprite.interactive = true;
this.sprite.on("pointerover", function () {
var tileName = "null";
//Change tile texture to indicate hover state
if (this.tileId === 0) {
this.texture = PIXI.loader.resources["plain_s"].texture;
tileName = "plain";
} else if (this.tileId === 1) {
this.texture = PIXI.loader.resources["wall_s"].texture;
tileName = "wall";
}//todo add other tiles
//Change info text
//todo make this better
MAR.currentTileText.text = "(" + this.tileX + "," + this.tileY + "," + this.z + ")\n" + tileName;
});
this.sprite.on("pointerout", function () {
//Change tile texture to indicate hover state
if (this.tileId === 0) {
this.texture = PIXI.loader.resources["plain"].texture;
} else if (this.tileId === 1) {
this.texture = PIXI.loader.resources["wall"].texture;
}
});
//Behave like background when clicked
this.sprite.on("pointerdown", pointerDown);
this.sprite.on("pointerup", bgPointerUp);
this.sprite.on("pointerupoutside", bgPointerUp);
}
function pointerDown(e) {
MAR.pointerdown = true;
MAR.pointerFirstClick = e.data.getLocalPosition(MAR.rootContainer);
}
function bgPointerUp() {
MAR.pointerdown = false;
MAR.pointerLastDrag = null;
}
// --------------------------
// Get an object from the current World's object list
function getObject(id) {
for (var i = 0; i < MAR.objects.length; i++) {
if (MAR.objects[i].id === id) {
return MAR.objects[i];
}
}
return null;
}
// --------------------------
//Integer distance between 2 tiles
function distance(x1, y1, x2, y2) {
return Math.abs(x1 - x2) + Math.abs(y1 - y2)
}
//Inventory indicator
function InventoryIndicator(parentObj, sprite) {
this.parentObj = parentObj;
this.sprite = sprite;
}
InventoryIndicator.prototype.updatePos = function () {
this.sprite.x = this.parentObj.sprite.x; //todo add offSetX property
this.sprite.y = this.parentObj.sprite.y;
this.sprite.z = this.parentObj.sprite.z + 0.1;
};
InventoryIndicator.prototype.updateIcon = function () {
console.log("FIXME: forgot to define updateIcon");
};

1108
mar/p2.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -725,7 +725,7 @@ Phaser.Plugin.Isometric.IsoSprite = function (game, x, y, z, key, frame) {
Phaser.Sprite.call(this, game, x, y, key, frame);
/**
* @property {number} type - The const type of this object.
* @property {number} objType - The const objType of this object.
* @readonly
*/
this.type = Phaser.Plugin.Isometric.ISOSPRITE;
@ -2009,7 +2009,7 @@ Phaser.Plugin.Isometric.Body = function (sprite) {
this.game = sprite.game;
/**
* @property {number} type - The type of physics system this body belongs to.
* @property {number} objType - The objType of physics system this body belongs to.
*/
this.type = Phaser.Plugin.Isometric.ISOARCADE;
@ -2219,7 +2219,7 @@ Phaser.Plugin.Isometric.Body = function (sprite) {
/**
* This flag allows you to disable the custom x separation that takes place by Physics.IsoArcade.separate.
* Used in combination with your own collision processHandler you can create whatever type of collision response you need.
* Used in combination with your own collision processHandler you can create whatever objType of collision response you need.
* @property {boolean} customSeparateX - Use a custom separation system or the built-in one?
* @default
*/
@ -2227,7 +2227,7 @@ Phaser.Plugin.Isometric.Body = function (sprite) {
/**
* This flag allows you to disable the custom y separation that takes place by Physics.IsoArcade.separate.
* Used in combination with your own collision processHandler you can create whatever type of collision response you need.
* Used in combination with your own collision processHandler you can create whatever objType of collision response you need.
* @property {boolean} customSeparateY - Use a custom separation system or the built-in one?
* @default
*/
@ -2235,7 +2235,7 @@ Phaser.Plugin.Isometric.Body = function (sprite) {
/**
* This flag allows you to disable the custom z separation that takes place by Physics.IsoArcade.separate.
* Used in combination with your own collision processHandler you can create whatever type of collision response you need.
* Used in combination with your own collision processHandler you can create whatever objType of collision response you need.
* @property {boolean} customSeparateZ - Use a custom separation system or the built-in one?
* @default
*/

112
mar/phaser-plugin-isometric.min.js vendored Normal file
View File

@ -0,0 +1,112 @@
/*
2015 Lewis Lane (Rotates.org)
@license {@link http://opensource.org/licenses/MIT|MIT License}
*/
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(a,b,c){a!=Array.prototype&&a!=Object.prototype&&(a[b]=c.value)};$jscomp.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};$jscomp.global=$jscomp.getGlobal(this);
$jscomp.polyfill=function(a,b,c,d){if(b){c=$jscomp.global;a=a.split(".");for(d=0;d<a.length-1;d++){var e=a[d];e in c||(c[e]={});c=c[e]}a=a[a.length-1];d=c[a];b=b(d);b!=d&&null!=b&&$jscomp.defineProperty(c,a,{configurable:!0,writable:!0,value:b})}};$jscomp.polyfill("Array.prototype.fill",function(a){return a?a:function(a,c,d){var b=this.length||0;0>c&&(c=Math.max(0,b+c));if(null==d||d>b)d=b;d=Number(d);0>d&&(d=Math.max(0,b+d));for(c=Number(c||0);c<d;c++)this[c]=a;return this}},"es6","es3");
Phaser.Plugin.Isometric=function(a,b,c){c=c||Phaser.Plugin.Isometric.CLASSIC;Phaser.Plugin.call(this,a,b);this.projector=new Phaser.Plugin.Isometric.Projector(this.game,c);this.game.iso=this.game.iso||this.projector};Phaser.Plugin.Isometric.prototype=Object.create(Phaser.Plugin.prototype);Phaser.Plugin.Isometric.prototype.constructor=Phaser.Plugin.Isometric;Phaser.Plugin.Isometric.VERSION="0.9.3";Phaser.Plugin.Isometric.UP=0;Phaser.Plugin.Isometric.DOWN=1;Phaser.Plugin.Isometric.FORWARDX=2;
Phaser.Plugin.Isometric.FORWARDY=3;Phaser.Plugin.Isometric.BACKWARDX=4;Phaser.Plugin.Isometric.BACKWARDY=5;Phaser.Plugin.Isometric.ISOSPRITE="isosprite";Phaser.Plugin.Isometric.ISOARCADE="isoarcade";
Phaser.Plugin.Isometric.Cube=function(a,b,c,d,e,f){this.x=a||0;this.y=b||0;this.z=c||0;this.widthX=d||0;this.widthY=e||0;this.height=f||0;this._corners=[new Phaser.Plugin.Isometric.Point3(this.x,this.y,this.z),new Phaser.Plugin.Isometric.Point3(this.x,this.y,this.z+this.height),new Phaser.Plugin.Isometric.Point3(this.x,this.y+this.widthY,this.z),new Phaser.Plugin.Isometric.Point3(this.x,this.y+this.widthY,this.z+this.height),new Phaser.Plugin.Isometric.Point3(this.x+this.widthX,this.y,this.z),new Phaser.Plugin.Isometric.Point3(this.x+
this.widthX,this.y,this.z+this.height),new Phaser.Plugin.Isometric.Point3(this.x+this.widthX,this.y+this.widthY,this.z),new Phaser.Plugin.Isometric.Point3(this.x+this.widthX,this.y+this.widthY,this.z+this.height)]};Phaser.Plugin.Isometric.Cube.prototype.constructor=Phaser.Plugin.Isometric.Cube;
Phaser.Plugin.Isometric.Cube.prototype={setTo:function(a,b,c,d,e,f){this.x=a;this.y=b;this.z=c;this.widthX=d;this.widthY=e;this.height=f;return this},copyFrom:function(a){this.setTo(a.x,a.y,a.z,a.widthX,a.widthY,a.height)},copyTo:function(a){a.x=this.x;a.y=this.y;a.z=this.z;a.widthX=this.widthX;a.widthY=this.widthY;a.height=this.height;return a},size:function(a){return Phaser.Plugin.Isometric.Cube.size(this,a)},contains:function(a,b,c){return Phaser.Plugin.Isometric.Cube.contains(this,a,b,c)},containsXY:function(a,
b){return Phaser.Plugin.Isometric.Cube.containsXY(this,a,b)},clone:function(a){return Phaser.Plugin.Isometric.Cube.clone(this,a)},intersects:function(a){return Phaser.Plugin.Isometric.Cube.intersects(this,a)},getCorners:function(){this._corners[0].setTo(this.x,this.y,this.z);this._corners[1].setTo(this.x,this.y,this.z+this.height);this._corners[2].setTo(this.x,this.y+this.widthY,this.z);this._corners[3].setTo(this.x,this.y+this.widthY,this.z+this.height);this._corners[4].setTo(this.x+this.widthX,
this.y,this.z);this._corners[5].setTo(this.x+this.widthX,this.y,this.z+this.height);this._corners[6].setTo(this.x+this.widthX,this.y+this.widthY,this.z);this._corners[7].setTo(this.x+this.widthX,this.y+this.widthY,this.z+this.height);return this._corners},toString:function(){return"[{Cube (x="+this.x+" y="+this.y+" z="+this.z+" widthX="+this.widthX+" widthY="+this.widthY+" height="+this.height+" empty="+this.empty+")}]"}};
Object.defineProperty(Phaser.Plugin.Isometric.Cube.prototype,"halfWidthX",{get:function(){return Math.round(.5*this.widthX)}});Object.defineProperty(Phaser.Plugin.Isometric.Cube.prototype,"halfWidthY",{get:function(){return Math.round(.5*this.widthY)}});Object.defineProperty(Phaser.Plugin.Isometric.Cube.prototype,"halfHeight",{get:function(){return Math.round(.5*this.height)}});
Object.defineProperty(Phaser.Plugin.Isometric.Cube.prototype,"bottom",{get:function(){return this.z},set:function(a){this.height=a>=this.top?0:this.top-a;this.z=a}});Object.defineProperty(Phaser.Plugin.Isometric.Cube.prototype,"top",{get:function(){return this.z+this.height},set:function(a){this.height=a<=this.z?0:a-this.z}});Object.defineProperty(Phaser.Plugin.Isometric.Cube.prototype,"backX",{get:function(){return this.x},set:function(a){this.widthX=a>=this.frontX?0:this.frontX-a;this.x=a}});
Object.defineProperty(Phaser.Plugin.Isometric.Cube.prototype,"backY",{get:function(){return this.y},set:function(a){this.widthY=a>=this.frontY?0:this.frontY-a;this.y=a}});Object.defineProperty(Phaser.Plugin.Isometric.Cube.prototype,"frontX",{get:function(){return this.x+this.widthX},set:function(a){this.widthX=a<=this.x?0:a-this.x}});Object.defineProperty(Phaser.Plugin.Isometric.Cube.prototype,"frontY",{get:function(){return this.y+this.widthY},set:function(a){this.widthY=a<=this.y?0:a-this.y}});
Object.defineProperty(Phaser.Plugin.Isometric.Cube.prototype,"volume",{get:function(){return this.widthX*this.widthY*this.height}});Object.defineProperty(Phaser.Plugin.Isometric.Cube.prototype,"centerX",{get:function(){return this.x+this.halfWidthX},set:function(a){this.x=a-this.halfWidthX}});Object.defineProperty(Phaser.Plugin.Isometric.Cube.prototype,"centerY",{get:function(){return this.y+this.halfWidthY},set:function(a){this.y=a-this.halfWidthY}});
Object.defineProperty(Phaser.Plugin.Isometric.Cube.prototype,"centerZ",{get:function(){return this.z+this.halfHeight},set:function(a){this.z=a-this.halfHeight}});Object.defineProperty(Phaser.Plugin.Isometric.Cube.prototype,"randomX",{get:function(){return this.x+Math.random()*this.widthX}});Object.defineProperty(Phaser.Plugin.Isometric.Cube.prototype,"randomY",{get:function(){return this.y+Math.random()*this.widthY}});
Object.defineProperty(Phaser.Plugin.Isometric.Cube.prototype,"randomZ",{get:function(){return this.z+Math.random()*this.height}});Object.defineProperty(Phaser.Plugin.Isometric.Cube.prototype,"empty",{get:function(){return!this.widthX||!this.widthY||!this.height},set:function(a){!0===a&&this.setTo(0,0,0,0,0,0)}});Phaser.Plugin.Isometric.Cube.size=function(a,b){"undefined"===typeof b||null===b?b=new Phaser.Plugin.Isometric.Point3(a.widthX,a.widthY,a.height):b.setTo(a.widthX,a.widthY,a.height);return b};
Phaser.Plugin.Isometric.Cube.clone=function(a,b){"undefined"===typeof b||null===b?b=new Phaser.Plugin.Isometric.Cube(a.x,a.y,a.z,a.widthX,a.widthY,a.height):b.setTo(a.x,a.y,a.z,a.widthX,a.widthY,a.height);return b};Phaser.Plugin.Isometric.Cube.contains=function(a,b,c,d){return 0>=a.widthX||0>=a.widthY||0>=a.height?!1:b>=a.x&&b<=a.frontX&&c>=a.y&&c<=a.frontY&&d>=a.z&&d<=a.top};
Phaser.Plugin.Isometric.Cube.containsXY=function(a,b,c){return 0>=a.widthX||0>=a.widthY?!1:b>=a.x&&b<=a.frontX&&c>=a.y&&c<=a.frontY};Phaser.Plugin.Isometric.Cube.containsPoint3=function(a,b){return Phaser.Plugin.Isometric.Cube.contains(a,b.x,b.y,b.z)};Phaser.Plugin.Isometric.Cube.containsCube=function(a,b){return a.volume>b.volume?!1:a.x>=b.x&&a.y>=b.y&&a.z>=b.z&&a.frontX<=b.frontX&&a.frontY<=b.frontY&&a.top<=b.top};
Phaser.Plugin.Isometric.Cube.intersects=function(a,b){return 0>=a.widthX||0>=a.widthY||0>=a.height||0>=b.widthX||0>=b.widthY||0>=b.height?!1:!(a.frontX<b.x||a.frontY<b.y||a.x>b.frontX||a.y>b.frontY||a.z>b.top||a.top<b.z)};
Phaser.Plugin.Isometric.IsoSprite=function(a,b,c,d,e,f){Phaser.Sprite.call(this,a,b,c,e,f);this.type=Phaser.Plugin.Isometric.ISOSPRITE;this._isoPosition=new Phaser.Plugin.Isometric.Point3(b,c,d);this._depth=this.snap=0;this._isoBoundsChanged=this._isoPositionChanged=this._depthChanged=!0;this._project();this._isoBounds=this.resetIsoBounds()};Phaser.Plugin.Isometric.IsoSprite.prototype=Object.create(Phaser.Sprite.prototype);Phaser.Plugin.Isometric.IsoSprite.prototype.constructor=Phaser.Plugin.Isometric.IsoSprite;
Phaser.Plugin.Isometric.IsoSprite.prototype.postUpdate=function(){Phaser.Sprite.prototype.postUpdate.call(this);this._project()};Phaser.Plugin.Isometric.IsoSprite.prototype._project=function(){this._isoPositionChanged&&(this.game.iso.project(this._isoPosition,this.position),0<this.snap&&(this.position.x=Phaser.Math.snapTo(this.position.x,this.snap),this.position.y=Phaser.Math.snapTo(this.position.y,this.snap)),this._depthChanged=this._isoPositionChanged=this._isoBoundsChanged=!0)};
Phaser.Plugin.Isometric.IsoSprite.prototype.resetIsoBounds=function(){"undefined"===typeof this._isoBounds&&(this._isoBounds=new Phaser.Plugin.Isometric.Cube);var a=Math.abs(this.scale.x),b=Math.abs(this.scale.y);this._isoBounds.widthX=Math.round(.5*Math.abs(this.width))*a;this._isoBounds.widthY=Math.round(.5*Math.abs(this.width))*a;this._isoBounds.height=Math.round(Math.abs(this.height)-.5*Math.abs(this.width))*b;this._isoBounds.x=this.isoX+this._isoBounds.widthX*-this.anchor.x+.5*this._isoBounds.widthX;
this._isoBounds.y=this.isoY+this._isoBounds.widthY*this.anchor.x-.5*this._isoBounds.widthY;this._isoBounds.z=this.isoZ-Math.abs(this.height)*(1-this.anchor.y)+Math.abs(.5*this.width);return this._isoBounds};Object.defineProperty(Phaser.Plugin.Isometric.IsoSprite.prototype,"isoX",{get:function(){return this._isoPosition.x},set:function(a){this._isoPosition.x=a;this._depthChanged=this._isoPositionChanged=this._isoBoundsChanged=!0;this.body&&(this.body._reset=!0)}});
Object.defineProperty(Phaser.Plugin.Isometric.IsoSprite.prototype,"isoY",{get:function(){return this._isoPosition.y},set:function(a){this._isoPosition.y=a;this._depthChanged=this._isoPositionChanged=this._isoBoundsChanged=!0;this.body&&(this.body._reset=!0)}});
Object.defineProperty(Phaser.Plugin.Isometric.IsoSprite.prototype,"isoZ",{get:function(){return this._isoPosition.z},set:function(a){this._isoPosition.z=a;this._depthChanged=this._isoPositionChanged=this._isoBoundsChanged=!0;this.body&&(this.body._reset=!0)}});Object.defineProperty(Phaser.Plugin.Isometric.IsoSprite.prototype,"isoPosition",{get:function(){return this._isoPosition}});
Object.defineProperty(Phaser.Plugin.Isometric.IsoSprite.prototype,"isoBounds",{get:function(){if(this._isoBoundsChanged||!this._isoBounds)this.resetIsoBounds(),this._isoBoundsChanged=!1;return this._isoBounds}});Object.defineProperty(Phaser.Plugin.Isometric.IsoSprite.prototype,"depth",{get:function(){!0===this._depthChanged&&(this._depth=this._isoPosition.x+this._isoPosition.y+1.25*this._isoPosition.z,this._depthChanged=!1);return this._depth}});
Phaser.GameObjectCreator.prototype.isoSprite=function(a,b,c,d,e){return new Phaser.Plugin.Isometric.IsoSprite(this.game,a,b,c,d,e)};Phaser.GameObjectFactory.prototype.isoSprite=function(a,b,c,d,e,f){"undefined"===typeof f&&(f=this.world);return f.add(new Phaser.Plugin.Isometric.IsoSprite(this.game,a,b,c,d,e))};Phaser.Plugin.Isometric.prototype.addIsoSprite=function(a,b,c,d,e,f){return Phaser.GameObjectFactory.prototype.isoSprite.call(this.game.add,a,b,c,d,e,f)};
Phaser.Utils.Debug.prototype.isoSprite=function(a,b,c){if(a.isoBounds){"undefined"===typeof c&&(c=!0);b=b||"rgba(0,255,0,0.4)";var d=[];d=a.isoBounds.getCorners();var e=-a.game.camera.x,f=-a.game.camera.y;this.start();if(c){d=[d[1],d[3],d[2],d[6],d[4],d[5],d[1]];d=d.map(function(b){b=a.game.iso.project(b);b.x+=e;b.y+=f;return b});this.context.beginPath();this.context.fillStyle=b;this.context.moveTo(d[0].x,d[0].y);for(b=1;b<d.length;b++)this.context.lineTo(d[b].x,d[b].y);this.context.fill()}else d=
d.slice(0,d.length),d=d.map(function(b){b=a.game.iso.project(b);b.x+=e;b.y+=f;return b}),this.context.moveTo(d[0].x,d[0].y),this.context.beginPath(),this.context.strokeStyle=b,this.context.lineTo(d[1].x,d[1].y),this.context.lineTo(d[3].x,d[3].y),this.context.lineTo(d[2].x,d[2].y),this.context.lineTo(d[6].x,d[6].y),this.context.lineTo(d[4].x,d[4].y),this.context.lineTo(d[5].x,d[5].y),this.context.lineTo(d[1].x,d[1].y),this.context.lineTo(d[0].x,d[0].y),this.context.lineTo(d[4].x,d[4].y),this.context.moveTo(d[0].x,
d[0].y),this.context.lineTo(d[2].x,d[2].y),this.context.moveTo(d[3].x,d[3].y),this.context.lineTo(d[7].x,d[7].y),this.context.lineTo(d[6].x,d[6].y),this.context.moveTo(d[7].x,d[7].y),this.context.lineTo(d[5].x,d[5].y),this.context.stroke(),this.context.closePath();this.stop()}};Phaser.Plugin.Isometric.Octree=function(a,b,c,d,e,f,g,h,k){this.maxObjects=10;this.maxLevels=4;this.level=0;this.bounds={};this.objects=[];this.nodes=[];this._empty=[];this.reset(a,b,c,d,e,f,g,h,k)};
Phaser.Plugin.Isometric.Octree.prototype={reset:function(a,b,c,d,e,f,g,h,k){this.maxObjects=g||10;this.maxLevels=h||4;this.level=k||0;this.bounds={x:Math.round(a),y:Math.round(b),z:Math.round(c),widthX:d,widthY:e,height:f,subWidthX:Math.floor(.5*d),subWidthY:Math.floor(.5*e),subHeight:Math.floor(.5*f),frontX:Math.round(a)+Math.floor(.5*d),frontY:Math.round(b)+Math.floor(.5*e),top:Math.round(c)+Math.floor(.5*f)};this.objects.length=0;this.nodes.length=0},populate:function(a){a.forEach(this.populateHandler,
this,!0)},populateHandler:function(a){a.body&&a.exists&&this.insert(a.body)},split:function(){this.nodes[0]=new Phaser.Plugin.Isometric.Octree(this.bounds.x,this.bounds.y,this.bounds.z,this.bounds.subWidthX,this.bounds.subWidthY,this.bounds.subHeight,this.maxLevels,this.level+1);this.nodes[1]=new Phaser.Plugin.Isometric.Octree(this.bounds.frontX,this.bounds.y,this.bounds.z,this.bounds.subWidthX,this.bounds.subWidthY,this.bounds.subHeight,this.maxLevels,this.level+1);this.nodes[2]=new Phaser.Plugin.Isometric.Octree(this.bounds.x,
this.bounds.frontY,this.bounds.z,this.bounds.subWidthX,this.bounds.subWidthY,this.bounds.subHeight,this.maxLevels,this.level+1);this.nodes[3]=new Phaser.Plugin.Isometric.Octree(this.bounds.frontX,this.bounds.frontY,this.bounds.z,this.bounds.subWidthX,this.bounds.subWidthY,this.bounds.subHeight,this.maxLevels,this.level+1);this.nodes[4]=new Phaser.Plugin.Isometric.Octree(this.bounds.x,this.bounds.y,this.bounds.top,this.bounds.subWidthX,this.bounds.subWidthY,this.bounds.subHeight,this.maxLevels,this.level+
1);this.nodes[5]=new Phaser.Plugin.Isometric.Octree(this.bounds.frontX,this.bounds.y,this.bounds.top,this.bounds.subWidthX,this.bounds.subWidthY,this.bounds.subHeight,this.maxLevels,this.level+1);this.nodes[6]=new Phaser.Plugin.Isometric.Octree(this.bounds.x,this.bounds.frontY,this.bounds.top,this.bounds.subWidthX,this.bounds.subWidthY,this.bounds.subHeight,this.maxLevels,this.level+1);this.nodes[7]=new Phaser.Plugin.Isometric.Octree(this.bounds.frontX,this.bounds.frontY,this.bounds.top,this.bounds.subWidthX,
this.bounds.subWidthY,this.bounds.subHeight,this.maxLevels,this.level+1)},insert:function(a){var b=0;if(null!=this.nodes[0]){var c=this.getIndex(a);if(-1!=c){this.nodes[c].insert(a);return}}this.objects.push(a);if(this.objects.length>this.maxObjects&&this.level<this.maxLevels)for(null==this.nodes[0]&&this.split();b<this.objects.length;)c=this.getIndex(this.objects[b]),-1!=c?this.nodes[c].insert(this.objects.splice(b,1)[0]):b++},getIndex:function(a){var b=-1;a.x<this.bounds.frontX&&a.frontX<this.bounds.frontX?
a.y<this.bounds.frontY&&a.frontY<this.bounds.frontY?a.z<this.bounds.top&&a.top<this.bounds.top?b=0:a.z>this.bounds.top&&(b=4):a.y>this.bounds.frontY&&(a.z<this.bounds.top&&a.top<this.bounds.top?b=2:a.z>this.bounds.top&&(b=6)):a.x>this.bounds.frontX&&(a.y<this.bounds.frontY&&a.frontY<this.bounds.frontY?a.z<this.bounds.top&&a.top<this.bounds.top?b=1:a.z>this.bounds.top&&(b=5):a.y>this.bounds.frontY&&(a.z<this.bounds.top&&a.top<this.bounds.top?b=3:a.z>this.bounds.top&&(b=7)));return b},retrieve:function(a){if(a instanceof
Phaser.Plugin.Isometric.Cube){var b=this.objects;var c=this.getIndex(a)}else{if(!a.body)return this._empty;b=this.objects;c=this.getIndex(a.body)}this.nodes[0]&&(-1!==c?b=b.concat(this.nodes[c].retrieve(a)):(b=b.concat(this.nodes[0].retrieve(a)),b=b.concat(this.nodes[1].retrieve(a)),b=b.concat(this.nodes[2].retrieve(a)),b=b.concat(this.nodes[3].retrieve(a)),b=b.concat(this.nodes[4].retrieve(a)),b=b.concat(this.nodes[5].retrieve(a)),b=b.concat(this.nodes[6].retrieve(a)),b=b.concat(this.nodes[7].retrieve(a))));
return b},clear:function(){this.objects.length=0;for(var a=this.nodes.length;a--;)this.nodes[a].clear(),this.nodes.splice(a,1);this.nodes.length=0}};Phaser.Plugin.Isometric.Octree.prototype.constructor=Phaser.Plugin.Isometric.Octree;
Phaser.Utils.Debug.prototype.octree=function(a,b){b=b||"rgba(255,0,0,0.3)";this.start();var c=a.bounds;if(0===a.nodes.length){this.context.strokeStyle=b;c=(new Phaser.Plugin.Isometric.Cube(c.x,c.y,c.z,c.widthX,c.widthY,c.height)).getCorners();var d=-this.game.camera.x,e=-this.game.camera.y;c=c.slice(0,c.length);c=c.map(function(a){a=this.game.iso.project(a);a.x+=d;a.y+=e;return a});this.context.moveTo(c[0].x,c[0].y);this.context.beginPath();this.context.strokeStyle=b;this.context.lineTo(c[1].x,c[1].y);
this.context.lineTo(c[3].x,c[3].y);this.context.lineTo(c[2].x,c[2].y);this.context.lineTo(c[6].x,c[6].y);this.context.lineTo(c[4].x,c[4].y);this.context.lineTo(c[5].x,c[5].y);this.context.lineTo(c[1].x,c[1].y);this.context.lineTo(c[0].x,c[0].y);this.context.lineTo(c[4].x,c[4].y);this.context.moveTo(c[0].x,c[0].y);this.context.lineTo(c[2].x,c[2].y);this.context.moveTo(c[3].x,c[3].y);this.context.lineTo(c[7].x,c[7].y);this.context.lineTo(c[6].x,c[6].y);this.context.moveTo(c[7].x,c[7].y);this.context.lineTo(c[5].x,
c[5].y);this.context.stroke();this.context.closePath();for(b=0;b<a.objects.length;b++)this.body(a.objects[b].sprite,"rgb(0,255,0)",!1)}else for(b=0;b<a.nodes.length;b++)this.octree(a.nodes[b]);this.stop()};Phaser.Plugin.Isometric.Point3=function(a,b,c){this.x=a||0;this.y=b||0;this.z=c||0};
Phaser.Plugin.Isometric.Point3.prototype={copyFrom:function(a){return this.setTo(a.x,a.y,a.z)},copyTo:function(a){a.x=this.x;a.y=this.y;a.z=this.z;return a},equals:function(a){return a.x===this.x&&a.y===this.y&&a.z===this.z},set:function(a,b,c){this.x=a||0;this.y=b||(0!==b?this.x:0);this.z=c||("undefined"===typeof b?this.x:0);return this},setTo:function(a,b,c){return this.set(a,b,c)},add:function(a,b){this.x+=a||0;this.y+=b||0;return this},subtract:function(a,b,c){this.x-=a||0;this.y-=b||0;this.z-=
c||0;return this},multiply:function(a,b,c){this.x*=a||1;this.y*=b||1;this.z*=c||1;return this},divide:function(a,b,c){this.x/=a||1;this.y/=b||1;this.z/=c||1;return this}};Phaser.Plugin.Isometric.Point3.prototype.constructor=Phaser.Plugin.Isometric.Point3;Phaser.Plugin.Isometric.Point3.add=function(a,b,c){"undefined"===typeof c&&(c=new Phaser.Plugin.Isometric.Point3);c.x=a.x+b.x;c.y=a.y+b.y;c.z=a.z+b.z;return c};
Phaser.Plugin.Isometric.Point3.subtract=function(a,b,c){"undefined"===typeof c&&(c=new Phaser.Plugin.Isometric.Point3);c.x=a.x-b.x;c.y=a.y-b.y;c.z=a.z-b.z;return c};Phaser.Plugin.Isometric.Point3.multiply=function(a,b,c){"undefined"===typeof c&&(c=new Phaser.Plugin.Isometric.Point3);c.x=a.x*b.x;c.y=a.y*b.y;c.z=a.z*b.z;return c};Phaser.Plugin.Isometric.Point3.divide=function(a,b,c){"undefined"===typeof c&&(c=new Phaser.Plugin.Isometric.Point3);c.x=a.x/b.x;c.y=a.y/b.y;c.z=a.z/b.z;return c};
Phaser.Plugin.Isometric.Point3.equals=function(a,b){return a.x===b.x&&a.y===b.y&&a.z===b.z};Phaser.Plugin.Isometric.Projector=function(a,b){this.game=a;this._transform=null;this._projectionAngle=0;this.projectionAngle=b||Phaser.Plugin.Isometric.CLASSIC;this.anchor=new Phaser.Point(.5,0)};Phaser.Plugin.Isometric.CLASSIC=Math.atan(.5);Phaser.Plugin.Isometric.ISOMETRIC=Math.PI/6;Phaser.Plugin.Isometric.MILITARY=Math.PI/4;
Phaser.Plugin.Isometric.Projector.prototype={project:function(a,b){"undefined"===typeof b&&(b=new Phaser.Point);b.x=(a.x-a.y)*this._transform[0];b.y=(a.x+a.y)*this._transform[1]-a.z;b.x+=this.game.world.width*this.anchor.x;b.y+=this.game.world.height*this.anchor.y;return b},projectXY:function(a,b){"undefined"===typeof b&&(b=new Phaser.Point);b.x=(a.x-a.y)*this._transform[0];b.y=(a.x+a.y)*this._transform[1];b.x+=this.game.world.width*this.anchor.x;b.y+=this.game.world.height*this.anchor.y;return b},
unproject:function(a,b,c){"undefined"===typeof b&&(b=new Phaser.Plugin.Isometric.Point3);c=c||0;var d=a.x-this.game.world.x-this.game.world.width*this.anchor.x;a=a.y-this.game.world.y-this.game.world.height*this.anchor.y+c;b.x=d/(2*this._transform[0])+a/(2*this._transform[1]);b.y=-(d/(2*this._transform[0]))+a/(2*this._transform[1]);b.z=c;return b},simpleSort:function(a){a.sort("depth")},topologicalSort:function(a,b,c){function d(a){if(!1===a.isoVisitedFlag){a.isoVisitedFlag=!0;for(var b=a.isoSpritesBehind.length,
e=0;e<b&&null!==a.isoSpritesBehind[e];e++)d(a.isoSpritesBehind[e]),a.isoSpritesBehind[e]=null;a[c]=p++}}if(a instanceof Phaser.Group){var e=a.children;var f=!0}else if(a.length)e=a;else return;c=c||"isoDepth";"undefined"===typeof b&&(b=1.5);var g,h,k=e.length;for(g=0;g<k;g++){var l=e[g];var q=0;l.isoSpritesBehind||(l.isoSpritesBehind=[]);for(h=0;h<k;h++)if(g!=h){var m=e[h];var n=l.body||l.isoBounds;m._isoPosition.x+b<n.frontX-b&&m._isoPosition.y+b<n.frontY-b&&m._isoPosition.z+b<n.top-b&&(l.isoSpritesBehind[q++]=
m)}l.isoVisitedFlag=!1}var p=0;for(g=0;g<k;g++)d(e[g]);f&&a.sort(c)}};Object.defineProperty(Phaser.Plugin.Isometric.Projector.prototype,"projectionAngle",{get:function(){return this._projectionAngle},set:function(a){a!==this._projectionAngle&&(this._projectionAngle=a,this._transform=[Math.cos(this._projectionAngle),Math.sin(this._projectionAngle)])}});
Phaser.Plugin.Isometric.Body=function(a){this.sprite=a;this.game=a.game;this.type=Phaser.Plugin.Isometric.ISOARCADE;this.enable=!0;this.offset=new Phaser.Plugin.Isometric.Point3;this.position=new Phaser.Plugin.Isometric.Point3(a.isoX,a.isoY,a.isoZ);this.prev=new Phaser.Plugin.Isometric.Point3(this.position.x,this.position.y,this.position.z);this.allowRotation=!0;this.preRotation=this.rotation=a.rotation;this.sourceWidthY=this.sourceWidthX=a.texture.frame.width;this.sourceHeight=a.texture.frame.height;
this.widthX=Math.ceil(.5*a.width);this.widthY=Math.ceil(.5*a.width);this.height=a.height-Math.ceil(.5*a.width);this.halfWidthX=Math.abs(.5*this.widthX);this.halfWidthY=Math.abs(.5*this.widthY);this.halfHeight=Math.abs(.5*this.height);this.center=new Phaser.Plugin.Isometric.Point3(a.isoX+this.halfWidthX,a.isoY+this.halfWidthY,a.isoZ+this.halfHeight);this.velocity=new Phaser.Plugin.Isometric.Point3;this.newVelocity=new Phaser.Plugin.Isometric.Point3;this.deltaMax=new Phaser.Plugin.Isometric.Point3;
this.acceleration=new Phaser.Plugin.Isometric.Point3;this.drag=new Phaser.Plugin.Isometric.Point3;this.allowGravity=!0;this.gravity=new Phaser.Plugin.Isometric.Point3;this.bounce=new Phaser.Plugin.Isometric.Point3;this.maxVelocity=new Phaser.Plugin.Isometric.Point3(1E4,1E4,1E4);this.angularDrag=this.angularAcceleration=this.angularVelocity=0;this.maxAngular=1E3;this.mass=1;this.speed=this.angle=0;this.facing=Phaser.NONE;this.immovable=!1;this.moves=!0;this.customSeparateZ=this.customSeparateY=this.customSeparateX=
!1;this.overlapZ=this.overlapY=this.overlapX=0;this.collideWorldBounds=this.embedded=!1;this.checkCollision={none:!1,any:!0,up:!0,down:!0,frontX:!0,frontY:!0,backX:!0,backY:!0};this.touching={none:!0,up:!1,down:!1,frontX:!1,frontY:!1,backX:!1,backY:!1};this.wasTouching={none:!0,up:!1,down:!1,frontX:!1,frontY:!1,backX:!1,backY:!1};this.blocked={up:!1,down:!1,frontX:!1,frontY:!1,backX:!1,backY:!1};this.phase=0;this.skipTree=!1;this._reset=!0;this._sx=a.scale.x;this._sy=a.scale.y;this._dz=this._dy=this._dx=
0;this._corners=[new Phaser.Plugin.Isometric.Point3(this.x,this.y,this.z),new Phaser.Plugin.Isometric.Point3(this.x,this.y,this.z+this.height),new Phaser.Plugin.Isometric.Point3(this.x,this.y+this.widthY,this.z),new Phaser.Plugin.Isometric.Point3(this.x,this.y+this.widthY,this.z+this.height),new Phaser.Plugin.Isometric.Point3(this.x+this.widthX,this.y,this.z),new Phaser.Plugin.Isometric.Point3(this.x+this.widthX,this.y,this.z+this.height),new Phaser.Plugin.Isometric.Point3(this.x+this.widthX,this.y+
this.widthY,this.z),new Phaser.Plugin.Isometric.Point3(this.x+this.widthX,this.y+this.widthY,this.z+this.height)]};
Phaser.Plugin.Isometric.Body.prototype={updateBounds:function(){var a=Math.abs(this.sprite.scale.x),b=Math.abs(this.sprite.scale.y);if(a!==this._sx||b!==this._sy)this.widthX=Math.ceil(.5*this.sprite.width),this.widthY=Math.ceil(.5*this.sprite.width),this.height=Math.ceil(this.sprite.height-.5*this.sprite.width),this.halfWidthX=Math.floor(2*this.widthX),this.halfWidthY=Math.floor(2*this.widthY),this.halfHeight=Math.floor(2*this.height),this._sx=a,this._sy=b,this.center.setTo(this.position.x+this.halfWidthX,
this.position.y+this.halfWidthY,this.position.z+this.halfHeight),this._reset=!0},preUpdate:function(){if(this.enable){this.phase=1;this.wasTouching.none=this.touching.none;this.wasTouching.up=this.touching.up;this.wasTouching.down=this.touching.down;this.wasTouching.backX=this.touching.backX;this.wasTouching.backY=this.touching.backY;this.wasTouching.frontX=this.touching.frontX;this.wasTouching.frontY=this.touching.frontY;this.touching.none=!0;this.touching.up=!1;this.touching.down=!1;this.touching.backX=
!1;this.touching.backY=!1;this.touching.frontX=!1;this.touching.frontY=!1;this.blocked.up=!1;this.blocked.down=!1;this.blocked.backX=!1;this.blocked.frontX=!1;this.blocked.backY=!1;this.embedded=this.blocked.backX=!1;this.updateBounds();this.position.x=this.sprite.isoX+(this.widthX*-this.sprite.anchor.x+.5*this.widthX)+this.offset.x;this.position.y=this.sprite.isoY+(this.widthY*this.sprite.anchor.x-.5*this.widthY)+this.offset.y;this.position.z=this.sprite.isoZ-Math.abs(this.sprite.height)*(1-this.sprite.anchor.y)+
Math.abs(.5*this.sprite.width)+this.offset.z;this.preRotation=this.rotation=this.sprite.angle;if(this._reset||!0===this.sprite.fresh)this.prev.x=this.position.x,this.prev.y=this.position.y,this.prev.z=this.position.z;if(this.moves){this.game.physics.isoArcade.updateMotion(this);this.newVelocity.set(this.velocity.x*this.game.time.physicsElapsed,this.velocity.y*this.game.time.physicsElapsed,this.velocity.z*this.game.time.physicsElapsed);this.position.x+=this.newVelocity.x;this.position.y+=this.newVelocity.y;
this.position.z+=this.newVelocity.z;if(this.position.x!==this.prev.x||this.position.y!==this.prev.y||this.position.z!==this.prev.z)this.speed=Math.sqrt(this.velocity.x*this.velocity.x+this.velocity.y*this.velocity.y+this.velocity.z*this.velocity.z),this.angle=Math.atan2(this.velocity.y,this.velocity.x);this.collideWorldBounds&&this.checkWorldBounds();this.sprite.outOfBoundsKill&&!this.game.physics.isoArcade.bounds.intersects(this.sprite.isoBounds)&&this.sprite.kill()}this._dx=this.deltaX();this._dy=
this.deltaY();this._dz=this.deltaZ();this._reset=!1}},postUpdate:function(){this.enable&&2!==this.phase&&(this.phase=2,this._reset&&(this.prev.x=this.position.x,this.prev.y=this.position.y,this.prev.z=this.position.z),this.deltaAbsX()>=this.deltaAbsY()&&this.deltaAbsX()>=this.deltaAbsZ()?0>this.deltaX()?this.facing=Phaser.Plugin.Isometric.BACKWARDX:0<this.deltaX()&&(this.facing=Phaser.Plugin.Isometric.FORWARDX):this.deltaAbsY()>=this.deltaAbsX()&&this.deltaAbsY()>=this.deltaAbsZ()?0>this.deltaY()?
this.facing=Phaser.Plugin.Isometric.BACKWARDY:0<this.deltaY()&&(this.facing=Phaser.Plugin.Isometric.FORWARDY):0>this.deltaZ()?this.facing=Phaser.Plugin.Isometric.DOWN:0<this.deltaZ()&&(this.facing=Phaser.Plugin.Isometric.UP),this.moves&&(this._dx=this.deltaX(),this._dy=this.deltaY(),this._dz=this.deltaZ(),0!==this.deltaMax.x&&0!==this._dx&&(0>this._dx&&this._dx<-this.deltaMax.x?this._dx=-this.deltaMax.x:0<this._dx&&this._dx>this.deltaMax.x&&(this._dx=this.deltaMax.x)),0!==this.deltaMax.y&&0!==this._dy&&
(0>this._dy&&this._dy<-this.deltaMax.y?this._dy=-this.deltaMax.y:0<this._dy&&this._dy>this.deltaMax.y&&(this._dy=this.deltaMax.y)),0!==this.deltaMax.z&&0!==this._dz&&(0>this._dz&&this._dz<-this.deltaMax.z?this._dz=-this.deltaMax.z:0<this._dz&&this._dz>this.deltaMax.z&&(this._dz=this.deltaMax.z)),this.sprite.isoX+=this._dx,this.sprite.isoY+=this._dy,this.sprite.isoZ+=this._dz),this.center.setTo(this.position.x+this.halfWidthX,this.position.y+this.halfWidthY,this.position.z+this.halfHeight),this.allowRotation&&
(this.sprite.angle+=this.deltaR()),this.prev.x=this.position.x,this.prev.y=this.position.y,this.prev.z=this.position.z,this._reset=!1)},destroy:function(){this.sprite=null},checkWorldBounds:function(){this.position.x<this.game.physics.isoArcade.bounds.x&&this.game.physics.isoArcade.checkCollision.backX?(this.position.x=this.game.physics.isoArcade.bounds.x,this.velocity.x*=-this.bounce.x,this.blocked.backX=!0):this.frontX>this.game.physics.isoArcade.bounds.frontX&&this.game.physics.isoArcade.checkCollision.frontX&&
(this.position.x=this.game.physics.isoArcade.bounds.frontX-this.widthX,this.velocity.x*=-this.bounce.x,this.blocked.frontX=!0);this.position.y<this.game.physics.isoArcade.bounds.y&&this.game.physics.isoArcade.checkCollision.backY?(this.position.y=this.game.physics.isoArcade.bounds.y,this.velocity.y*=-this.bounce.y,this.blocked.backY=!0):this.frontY>this.game.physics.isoArcade.bounds.frontY&&this.game.physics.isoArcade.checkCollision.frontY&&(this.position.y=this.game.physics.isoArcade.bounds.frontY-
this.widthY,this.velocity.y*=-this.bounce.y,this.blocked.frontY=!0);this.position.z<this.game.physics.isoArcade.bounds.z&&this.game.physics.isoArcade.checkCollision.down?(this.position.z=this.game.physics.isoArcade.bounds.z,this.velocity.z*=-this.bounce.z,this.blocked.down=!0):this.top>this.game.physics.isoArcade.bounds.top&&this.game.physics.isoArcade.checkCollision.up&&(this.position.z=this.game.physics.isoArcade.bounds.top-this.height,this.velocity.z*=-this.bounce.z,this.blocked.up=!0)},setSize:function(a,
b,c,d,e,f){"undefined"===typeof d&&(d=this.offset.x);"undefined"===typeof e&&(e=this.offset.y);"undefined"===typeof f&&(f=this.offset.z);this.sourceWidthX=a;this.sourceWidthY=b;this.sourceHeight=c;this.widthX=this.sourceWidthX*this._sx;this.widthY=this.sourceWidthY*this._sx;this.height=this.sourceHeight*this._sy;this.halfWidthX=Math.floor(.5*this.widthX);this.halfWidthY=Math.floor(.5*this.widthY);this.halfHeight=Math.floor(.5*this.height);this.offset.setTo(d,e,f);this.center.setTo(this.position.x+
this.halfWidthX,this.position.y+this.halfWidthY,this.position.z+this.halfHeight)},reset:function(a,b,c){this.velocity.set(0);this.acceleration.set(0);this.angularAcceleration=this.angularVelocity=0;this.position.x=a+(this.widthX*-this.sprite.anchor.x+.5*this.widthX)+this.offset.x;this.position.y=b+(this.widthY*this.sprite.anchor.x-.5*this.widthY)+this.offset.y;this.position.z=c-Math.abs(this.sprite.height)*(1-this.sprite.anchor.y)+Math.abs(.5*this.sprite.width)+this.offset.z;this.prev.x=this.position.x;
this.prev.y=this.position.y;this.prev.z=this.position.z;this.preRotation=this.rotation=this.sprite.angle;this._sx=this.sprite.scale.x;this._sy=this.sprite.scale.y;this.center.setTo(this.position.x+this.halfWidthX,this.position.y+this.halfWidthY,this.position.z+this.halfHeight);this.sprite._isoPositionChanged=!0},hitTest:function(a,b,c){return Phaser.Plugin.Isometric.Cube.contains(this,a,b,c)},onFloor:function(){return this.blocked.down},onWall:function(){return this.blocked.frontX||this.blocked.frontY||
this.blocked.backX||this.blocked.backY},deltaAbsX:function(){return 0<this.deltaX()?this.deltaX():-this.deltaX()},deltaAbsY:function(){return 0<this.deltaY()?this.deltaY():-this.deltaY()},deltaAbsZ:function(){return 0<this.deltaZ()?this.deltaZ():-this.deltaZ()},deltaX:function(){return this.position.x-this.prev.x},deltaY:function(){return this.position.y-this.prev.y},deltaZ:function(){return this.position.z-this.prev.z},deltaR:function(){return this.rotation-this.preRotation},getCorners:function(){this._corners[0].setTo(this.x,
this.y,this.z);this._corners[1].setTo(this.x,this.y,this.z+this.height);this._corners[2].setTo(this.x,this.y+this.widthY,this.z);this._corners[3].setTo(this.x,this.y+this.widthY,this.z+this.height);this._corners[4].setTo(this.x+this.widthX,this.y,this.z);this._corners[5].setTo(this.x+this.widthX,this.y,this.z+this.height);this._corners[6].setTo(this.x+this.widthX,this.y+this.widthY,this.z);this._corners[7].setTo(this.x+this.widthX,this.y+this.widthY,this.z+this.height);return this._corners}};
Object.defineProperty(Phaser.Plugin.Isometric.Body.prototype,"top",{get:function(){return this.position.z+this.height}});Object.defineProperty(Phaser.Plugin.Isometric.Body.prototype,"frontX",{get:function(){return this.position.x+this.widthX}});Object.defineProperty(Phaser.Plugin.Isometric.Body.prototype,"right",{get:function(){return this.position.x+this.widthX}});Object.defineProperty(Phaser.Plugin.Isometric.Body.prototype,"frontY",{get:function(){return this.position.y+this.widthY}});
Object.defineProperty(Phaser.Plugin.Isometric.Body.prototype,"bottom",{get:function(){return this.position.y+this.widthY}});Object.defineProperty(Phaser.Plugin.Isometric.Body.prototype,"x",{get:function(){return this.position.x},set:function(a){this.position.x=a}});Object.defineProperty(Phaser.Plugin.Isometric.Body.prototype,"y",{get:function(){return this.position.y},set:function(a){this.position.y=a}});
Object.defineProperty(Phaser.Plugin.Isometric.Body.prototype,"z",{get:function(){return this.position.z},set:function(a){this.position.z=a}});
Phaser.Plugin.Isometric.Body.render=function(a,b,c,d){"undefined"===typeof d&&(d=!0);c=c||"rgba(0,255,0,0.4)";var e=[];e=b.getCorners();var f=-b.sprite.game.camera.x,g=-b.sprite.game.camera.y;if(d){e=[e[1],e[3],e[2],e[6],e[4],e[5],e[1]];e=e.map(function(a){a=b.sprite.game.iso.project(a);a.x+=f;a.y+=g;return a});a.beginPath();a.fillStyle=c;a.moveTo(e[0].x,e[0].y);for(c=1;c<e.length;c++)a.lineTo(e[c].x,e[c].y);a.fill()}else e=e.slice(0,e.length),e=e.map(function(a){a=b.sprite.game.iso.project(a);a.x+=
f;a.y+=g;return a}),a.moveTo(e[0].x,e[0].y),a.beginPath(),a.strokeStyle=c,a.lineTo(e[1].x,e[1].y),a.lineTo(e[3].x,e[3].y),a.lineTo(e[2].x,e[2].y),a.lineTo(e[6].x,e[6].y),a.lineTo(e[4].x,e[4].y),a.lineTo(e[5].x,e[5].y),a.lineTo(e[1].x,e[1].y),a.lineTo(e[0].x,e[0].y),a.lineTo(e[4].x,e[4].y),a.moveTo(e[0].x,e[0].y),a.lineTo(e[2].x,e[2].y),a.moveTo(e[3].x,e[3].y),a.lineTo(e[7].x,e[7].y),a.lineTo(e[6].x,e[6].y),a.moveTo(e[7].x,e[7].y),a.lineTo(e[5].x,e[5].y),a.stroke(),a.closePath()};
Phaser.Plugin.Isometric.Body.renderBodyInfo=function(a,b){a.line("x: "+b.x.toFixed(2),"y: "+b.y.toFixed(2),"z: "+b.z.toFixed(2),"widthX: "+b.widthX,"widthY: "+b.widthY,"height: "+b.height);a.line("velocity x: "+b.velocity.x.toFixed(2),"y: "+b.velocity.y.toFixed(2),"z: "+b.velocity.z.toFixed(2),"deltaX: "+b._dx.toFixed(2),"deltaY: "+b._dy.toFixed(2),"deltaZ: "+b._dz.toFixed(2));a.line("acceleration x: "+b.acceleration.x.toFixed(2),"y: "+b.acceleration.y.toFixed(2),"z: "+b.acceleration.z.toFixed(2),
"speed: "+b.speed.toFixed(2),"angle: "+b.angle.toFixed(2));a.line("gravity x: "+b.gravity.x,"y: "+b.gravity.y,"z: "+b.gravity.z);a.line("bounce x: "+b.bounce.x.toFixed(2),"y: "+b.bounce.y.toFixed(2),"z: "+b.bounce.z.toFixed(2));a.line("touching: ","frontX: "+(b.touching.frontX?1:0)+" frontY: "+(b.touching.frontY?1:0)+" backX: "+(b.touching.backX?1:0)+" backY: "+(b.touching.backY?1:0)+" up: "+(b.touching.up?1:0)+" down: "+(b.touching.down?1:0));a.line("blocked: ","frontX: "+(b.blocked.frontX?1:0)+
" frontY: "+(b.blocked.frontY?1:0)+" backX: "+(b.blocked.backX?1:0)+" backY: "+(b.blocked.backY?1:0)+" up: "+(b.blocked.up?1:0)+" down: "+(b.blocked.down?1:0))};Phaser.Plugin.Isometric.Body.prototype.constructor=Phaser.Plugin.Isometric.Body;
Phaser.Utils.Debug.prototype.body=function(a){return function(b,c,d,e){b.body&&b.body.type===Phaser.Plugin.Isometric.ISOARCADE&&(this.start(),Phaser.Plugin.Isometric.Body.render(this.context,b.body,c,d),e&&this.text(b.depth.toFixed(2),b.x,b.y,c,"12px Courier"),this.stop());return a.call(this,b,c,d)}}(Phaser.Utils.Debug.prototype.body);
Phaser.Utils.Debug.prototype.bodyInfo=function(a){return function(b,c,d,e){b.body&&b.body.type===Phaser.Plugin.Isometric.ISOARCADE&&(this.start(c,d,e,210),Phaser.Plugin.Isometric.Body.renderBodyInfo(this,b.body),this.stop());return a.call(this,b,c,d,e)}}(Phaser.Utils.Debug.prototype.bodyInfo);
Phaser.Plugin.Isometric.Arcade=function(a){this.game=a;this.gravity=new Phaser.Plugin.Isometric.Point3;this.bounds=new Phaser.Plugin.Isometric.Cube(0,0,0,.5*a.world.width,.5*a.world.width,a.world.height);this.checkCollision={up:!0,down:!0,frontX:!0,frontY:!0,backX:!0,backY:!0};this.maxObjects=10;this.OVERLAP_BIAS=this.maxLevels=4;this.useQuadTree=this.skipTree=this.forceXY=!1;this.quadTree=new Phaser.QuadTree(this.bounds.x,this.bounds.y,this.bounds.widthX,this.bounds.widthY,this.maxObjects,this.maxLevels);
this.octree=new Phaser.Plugin.Isometric.Octree(this.bounds.x,this.bounds.y,this.bounds.z,this.bounds.widthX,this.bounds.widthY,this.bounds.height,this.maxObjects,this.maxLevels);this._average=this._newVelocity2=this._newVelocity1=this._velocity2=this._velocity1=this._maxOverlap=this._overlap=0;this._mapData=[];this._result=!1;this._dz=this._dy=this._dx=this._angle=this._total=0};Phaser.Plugin.Isometric.Arcade.prototype.constructor=Phaser.Plugin.Isometric.Arcade;
Phaser.Plugin.Isometric.Arcade.prototype={setBounds:function(a,b,c,d,e,f){this.bounds.setTo(a,b,c,d,e,f)},setBoundsToWorld:function(){this.bounds.setTo(0,0,0,.5*this.game.world.width,.5*this.game.world.width,this.game.world.height)},enable:function(a,b){"undefined"===typeof b&&(b=!0);var c;if(Array.isArray(a))for(c=a.length;c--;)a[c]instanceof Phaser.Group?this.enable(a[c].children,b):(this.enableBody(a[c]),b&&a[c].hasOwnProperty("children")&&0<a[c].children.length&&this.enable(a[c],!0));else a instanceof
Phaser.Group?this.enable(a.children,b):(this.enableBody(a),b&&a.hasOwnProperty("children")&&0<a.children.length&&this.enable(a.children,!0))},enableBody:function(a){a.hasOwnProperty("body")&&null===a.body&&(a.body=new Phaser.Plugin.Isometric.Body(a))},updateMotion:function(a){this._velocityDelta=this.computeVelocity(0,a,a.angularVelocity,a.angularAcceleration,a.angularDrag,a.maxAngular)-a.angularVelocity;a.angularVelocity+=this._velocityDelta;a.rotation+=a.angularVelocity*this.game.time.physicsElapsed;
a.velocity.x=this.computeVelocity(1,a,a.velocity.x,a.acceleration.x,a.drag.x,a.maxVelocity.x);a.velocity.y=this.computeVelocity(2,a,a.velocity.y,a.acceleration.y,a.drag.y,a.maxVelocity.y);a.velocity.z=this.computeVelocity(3,a,a.velocity.z,a.acceleration.z,a.drag.z,a.maxVelocity.z)},computeVelocity:function(a,b,c,d,e,f){f=f||1E4;1===a&&b.allowGravity?c+=(this.gravity.x+b.gravity.x)*this.game.time.physicsElapsed:2===a&&b.allowGravity?c+=(this.gravity.y+b.gravity.y)*this.game.time.physicsElapsed:3===
a&&b.allowGravity&&(c+=(this.gravity.z+b.gravity.z)*this.game.time.physicsElapsed);d?c+=d*this.game.time.physicsElapsed:e&&(this._drag=e*this.game.time.physicsElapsed,c=0<c-this._drag?c-this._drag:0>c+this._drag?c+this._drag:0);c>f?c=f:c<-f&&(c=-f);return c},overlap:function(a,b,c,d,e){c=c||null;d=d||null;e=e||c;this._result=!1;this._total=0;if(Array.isArray(b))for(var f=0,g=b.length;f<g;f++)this.collideHandler(a,b[f],c,d,e,!0);else this.collideHandler(a,b,c,d,e,!0);return 0<this._total},collide:function(a,
b,c,d,e){c=c||null;d=d||null;e=e||c;this._result=!1;this._total=0;if(Array.isArray(b))for(var f=0,g=b.length;f<g;f++)this.collideHandler(a,b[f],c,d,e,!1);else this.collideHandler(a,b,c,d,e,!1);return 0<this._total},collideHandler:function(a,b,c,d,e,f){b||a.type!==Phaser.GROUP?a&&b&&a.exists&&b.exists&&(a.type===Phaser.Plugin.Isometric.ISOSPRITE?b.type===Phaser.Plugin.Isometric.ISOSPRITE?this.collideSpriteVsSprite(a,b,c,d,e,f):b.type===Phaser.GROUP&&this.collideSpriteVsGroup(a,b,c,d,e,f):a.type===
Phaser.GROUP&&(b.type===Phaser.Plugin.Isometric.ISOSPRITE?this.collideSpriteVsGroup(b,a,c,d,e,f):b.type===Phaser.GROUP&&this.collideGroupVsGroup(a,b,c,d,e,f))):this.collideGroupVsSelf(a,c,d,e,f)},collideSpriteVsSprite:function(a,b,c,d,e,f){if(!a.body||!b.body)return!1;this.separate(a.body,b.body,d,e,f)&&(c&&c.call(e,a,b),this._total++);return!0},collideSpriteVsGroup:function(a,b,c,d,e,f){var g;if(0!==b.length&&a.body)if(a.body.skipTree||this.skipTree){var h=0;for(g=b.children.length;h<g;h++)b.children[h]&&
b.children[h].exists&&this.collideSpriteVsSprite(a,b.children[h],c,d,e,f)}else for(this.useQuadTree?(this.quadTree.clear(),this.quadTree.reset(this.bounds.x,this.bounds.y,this.bounds.widthX,this.bounds.widthY,this.maxObjects,this.maxLevels),this.quadTree.populate(b),this._potentials=this.quadTree.retrieve(a)):(this.octree.clear(),this.octree.reset(this.bounds.x,this.bounds.y,this.bounds.z,this.bounds.widthX,this.bounds.widthY,this.bounds.height,this.maxObjects,this.maxLevels),this.octree.populate(b),
this._potentials=this.octree.retrieve(a)),h=0,g=this._potentials.length;h<g;h++)this.separate(a.body,this._potentials[h],d,e,f)&&(c&&c.call(e,a,this._potentials[h].sprite),this._total++)},collideGroupVsSelf:function(a,b,c,d,e){if(0!==a.length)for(var f=a.children.length,g=0;g<f;g++)for(var h=g+1;h<=f;h++)a.children[g]&&a.children[h]&&a.children[g].exists&&a.children[h].exists&&this.collideSpriteVsSprite(a.children[g],a.children[h],b,c,d,e)},collideGroupVsGroup:function(a,b,c,d,e,f){if(0!==a.length&&
0!==b.length)for(var g=0,h=a.children.length;g<h;g++)a.children[g].exists&&this.collideSpriteVsGroup(a.children[g],b,c,d,e,f)},separate:function(a,b,c,d,e){return!a.enable||!b.enable||!this.intersects(a,b)||c&&!1===c.call(d,a.sprite,b.sprite)?!1:e?!0:this._result=this.forceXY||Math.abs(this.gravity.z+a.gravity.z)<Math.abs(this.gravity.x+a.gravity.x)||Math.abs(this.gravity.z+a.gravity.z)<Math.abs(this.gravity.y+a.gravity.y)?this.separateX(a,b,e)||this.separateY(a,b,e)||this.separateZ(a,b,e):this.separateZ(a,
b,e)||this.separateX(a,b,e)||this.separateY(a,b,e)},intersects:function(a,b){return a.frontX<=b.x||a.frontY<=b.y||a.x>=b.frontX||a.y>=b.frontY||a.top<=b.z||a.z>=b.top?!1:!0},separateX:function(a,b,c){if(a.immovable&&b.immovable)return!1;this._overlap=0;if(this.intersects(a,b)&&(this._maxOverlap=a.deltaAbsX()+b.deltaAbsX()+this.OVERLAP_BIAS,0===a.deltaX()&&0===b.deltaX()?(a.embedded=!0,b.embedded=!0):a.deltaX()>b.deltaX()?(this._overlap=a.frontX-b.x,this._overlap>this._maxOverlap||!1===a.checkCollision.frontX||
!1===b.checkCollision.backX?this._overlap=0:(a.touching.none=!1,a.touching.frontX=!0,b.touching.none=!1,b.touching.backX=!0)):a.deltaX()<b.deltaX()&&(this._overlap=a.x-b.widthX-b.x,-this._overlap>this._maxOverlap||!1===a.checkCollision.backX||!1===b.checkCollision.frontX?this._overlap=0:(a.touching.none=!1,a.touching.backX=!0,b.touching.none=!1,b.touching.frontX=!0)),0!==this._overlap)){a.overlapX=this._overlap;b.overlapX=this._overlap;if(c||a.customSeparateX||b.customSeparateX)return!0;this._velocity1=
a.velocity.x;this._velocity2=b.velocity.x;a.immovable||b.immovable?a.immovable?b.immovable||(b.x+=this._overlap,b.velocity.x=this._velocity1-this._velocity2*b.bounce.x):(a.x-=this._overlap,a.velocity.x=this._velocity2-this._velocity1*a.bounce.x):(this._overlap*=.5,a.x-=this._overlap,b.x+=this._overlap,this._newVelocity1=Math.sqrt(this._velocity2*this._velocity2*b.mass/a.mass)*(0<this._velocity2?1:-1),this._newVelocity2=Math.sqrt(this._velocity1*this._velocity1*a.mass/b.mass)*(0<this._velocity1?1:
-1),this._average=.5*(this._newVelocity1+this._newVelocity2),this._newVelocity1-=this._average,this._newVelocity2-=this._average,a.velocity.x=this._average+this._newVelocity1*a.bounce.x,b.velocity.x=this._average+this._newVelocity2*b.bounce.x);return!0}return!1},separateY:function(a,b,c){if(a.immovable&&b.immovable)return!1;this._overlap=0;if(this.intersects(a,b)&&(this._maxOverlap=a.deltaAbsY()+b.deltaAbsY()+this.OVERLAP_BIAS,0===a.deltaY()&&0===b.deltaY()?(a.embedded=!0,b.embedded=!0):a.deltaY()>
b.deltaY()?(this._overlap=a.frontY-b.y,this._overlap>this._maxOverlap||!1===a.checkCollision.frontY||!1===b.checkCollision.backY?this._overlap=0:(a.touching.none=!1,a.touching.frontY=!0,b.touching.none=!1,b.touching.backY=!0)):a.deltaY()<b.deltaY()&&(this._overlap=a.y-b.widthY-b.y,-this._overlap>this._maxOverlap||!1===a.checkCollision.backY||!1===b.checkCollision.frontY?this._overlap=0:(a.touching.none=!1,a.touching.backY=!0,b.touching.none=!1,b.touching.frontY=!0)),0!==this._overlap)){a.overlapY=
this._overlap;b.overlapY=this._overlap;if(c||a.customSeparateY||b.customSeparateY)return!0;this._velocity1=a.velocity.y;this._velocity2=b.velocity.y;a.immovable||b.immovable?a.immovable?b.immovable||(b.y+=this._overlap,b.velocity.y=this._velocity1-this._velocity2*b.bounce.y):(a.y-=this._overlap,a.velocity.y=this._velocity2-this._velocity1*a.bounce.y):(this._overlap*=.5,a.y-=this._overlap,b.y+=this._overlap,this._newVelocity1=Math.sqrt(this._velocity2*this._velocity2*b.mass/a.mass)*(0<this._velocity2?
1:-1),this._newVelocity2=Math.sqrt(this._velocity1*this._velocity1*a.mass/b.mass)*(0<this._velocity1?1:-1),this._average=.5*(this._newVelocity1+this._newVelocity2),this._newVelocity1-=this._average,this._newVelocity2-=this._average,a.velocity.y=this._average+this._newVelocity1*a.bounce.y,b.velocity.y=this._average+this._newVelocity2*b.bounce.y);return!0}return!1},separateZ:function(a,b,c){if(a.immovable&&b.immovable)return!1;this._overlap=0;if(this.intersects(a,b)&&(this._maxOverlap=a.deltaAbsZ()+
b.deltaAbsZ()+this.OVERLAP_BIAS,0===a.deltaZ()&&0===b.deltaZ()?(a.embedded=!0,b.embedded=!0):a.deltaZ()>b.deltaZ()?(this._overlap=a.top-b.z,this._overlap>this._maxOverlap||!1===a.checkCollision.down||!1===b.checkCollision.up?this._overlap=0:(a.touching.none=!1,a.touching.down=!0,b.touching.none=!1,b.touching.up=!0)):a.deltaZ()<b.deltaZ()&&(this._overlap=a.z-b.top,-this._overlap>this._maxOverlap||!1===a.checkCollision.up||!1===b.checkCollision.down?this._overlap=0:(a.touching.none=!1,a.touching.up=
!0,b.touching.none=!1,b.touching.down=!0)),0!==this._overlap)){a.overlapZ=this._overlap;b.overlapZ=this._overlap;if(c||a.customSeparateY||b.customSeparateZ)return!0;this._velocity1=a.velocity.z;this._velocity2=b.velocity.z;a.immovable||b.immovable?a.immovable?b.immovable||(b.z+=this._overlap,b.velocity.z=this._velocity1-this._velocity2*b.bounce.z,a.moves&&(b.x+=a.x-a.prev.x,b.y+=a.y-a.prev.y)):(a.z-=this._overlap,a.velocity.z=this._velocity2-this._velocity1*a.bounce.z,b.moves&&(a.x+=b.x-b.prev.x,
a.y+=b.y-b.prev.y)):(this._overlap*=.5,a.z-=this._overlap,b.z+=this._overlap,this._newVelocity1=Math.sqrt(this._velocity2*this._velocity2*b.mass/a.mass)*(0<this._velocity2?1:-1),this._newVelocity2=Math.sqrt(this._velocity1*this._velocity1*a.mass/b.mass)*(0<this._velocity1?1:-1),this._average=.5*(this._newVelocity1+this._newVelocity2),this._newVelocity1-=this._average,this._newVelocity2-=this._average,a.velocity.z=this._average+this._newVelocity1*a.bounce.z,b.velocity.z=this._average+this._newVelocity2*
b.bounce.z);return!0}return!1},distanceBetween:function(a,b){this._dx=a.x-b.x;this._dy=a.y-b.y;this._dz=a.z-b.z;return Math.sqrt(this._dx*this._dx+this._dy*this._dy+this._dz*this._dz)},distanceToXY:function(a,b,c){this._dx=a.x-b;this._dy=a.y-c;return Math.sqrt(this._dx*this._dx+this._dy*this._dy)},distanceToXYZ:function(a,b,c,d){this._dx=a.x-b;this._dy=a.y-c;this._dz=a.z-d;return Math.sqrt(this._dx*this._dx+this._dy*this._dy+this._dz*this._dz)},distanceToPointer:function(a,b){b=b||this.game.input.activePointer;
b=this.game.iso.unproject(b.position,void 0,a.z);b.z=a.z;return this.anglesToXYZ(a,b.x,b.y,b.z).r},anglesToXYZ:function(a,b,c,d){var e=this.distanceToXYZ(a,b,c,d);return{r:e,theta:Math.atan2(c-a.y,b-a.x),phi:Math.acos((d-a.z)/e)}},angleToPointer:function(a,b){b=b||this.game.input.activePointer;b=this.game.iso.unproject(b.position,void 0,a.z);b.z=a.z;return this.anglesToXYZ(a,b.x,b.y,b.z).theta},velocityFromAngles:function(a,b,c,d){void 0===b&&(b=Math.sin(Math.PI/2));void 0===c&&(c=60);d||new Phaser.Point;
return new Phaser.Plugin.Isometric.Point3(Math.cos(a)*Math.sin(b)*c,Math.sin(a)*Math.sin(b)*c,Math.cos(b)*c)},accelerateToXYZ:function(a,b,c,d,e,f,g,h){void 0===e&&(e=60);void 0===f&&(f=500);void 0===g&&(g=500);void 0===h&&(h=500);b=this.anglesToXYZ(a.body,b,c,d);e=this.velocityFromAngles(b.theta,b.phi,e);a.body.acceleration.setTo(e.x,e.y,e.z);a.body.maxVelocity.setTo(f,g,h);return b.theta},moveToXYZ:function(a,b,c,d,e,f){"undefined"===typeof e&&(e=60);"undefined"===typeof f&&(f=0);0<f&&(e=this.distanceToXYZ(a.body,
b,c,d)/(f/1E3));b=this.anglesToXYZ(a.body,b,c,d);e=this.velocityFromAngles(b.theta,b.phi,e);a.body.velocity.copyFrom(e);return b.theta},moveToObject:function(a,b,c,d){return this.moveToXYZ(a,b.x,b.y,b.z,c,d)},moveToPointer:function(a,b,c,d){c=c||this.game.input.activePointer;c=this.game.iso.unproject(c.position,void 0,a.body.z);c.z=a.body.z;"undefined"===typeof b&&(b=60);"undefined"===typeof d&&(d=0);0<d&&(b=this.distanceToXYZ(a.body,c.x,c.y,c.z)/(d/1E3));d=this.anglesToXYZ(a.body,c.x,c.y,c.z);b=
this.velocityFromAngles(d.theta,d.phi,b);a.body.velocity.x=b.x;a.body.velocity.y=b.y;return d.theta}};Phaser.Physics.prototype.isoArcade=null;Phaser.Physics.prototype.parseConfig=function(a){return function(){this.config.hasOwnProperty("isoArcade")&&!0===this.config.isoArcade&&Phaser.Plugin.Isometric.hasOwnProperty("IsoArcade")&&(this.isoArcade=new Phaser.Plugin.Isometric(this.game,this.config));return a.call(this)}}(Phaser.Physics.prototype.parseConfig);
Phaser.Physics.prototype.startSystem=function(a){return function(b){b===Phaser.Plugin.Isometric.ISOARCADE&&null===this.isoArcade&&(this.isoArcade=new Phaser.Plugin.Isometric.Arcade(this.game),this.setBoundsToWorld());return a.call(this,b)}}(Phaser.Physics.prototype.startSystem);Phaser.Physics.prototype.enable=function(a){return function(b,c){c===Phaser.Plugin.Isometric.ISOARCADE&&this.isoArcade&&this.isoArcade.enable(b);return a.call(this,b,c)}}(Phaser.Physics.prototype.enable);
Phaser.Physics.prototype.setBoundsToWorld=function(a){return function(){this.isoArcade&&this.isoArcade.setBoundsToWorld();return a.call(this)}}(Phaser.Physics.prototype.setBoundsToWorld);Phaser.Physics.prototype.destroy=function(a){return function(){this.isoArcade=null;return a.call(this)}}(Phaser.Physics.prototype.destroy);

7685
mar/phaser.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

4
mar/phaser.min.js vendored Normal file

File diff suppressed because one or more lines are too long

398
mar/phaser.plugin.isometric.d.ts vendored Normal file
View File

@ -0,0 +1,398 @@
//debug octreee is missing - Octree
//debug isoSprite is missing - IsoSprite
//gameobjectcreator isoSprite missing - IsoSprite
//gameobjectfactory isoSprite missing - IsoSprite
//debug body missing - Body
//debug bodyInfo missing -Body
declare module Phaser {
interface Physics {
isoArcade: Phaser.Plugin.Isometric.Arcade;
}
}
declare module Phaser.Plugin {
class Isometric extends Phaser.Plugin {
static CLASSIC: number;
static ISOMETRIC: number;
static MILITARY: number;
static VERSION: string;
static UP: number;
static DOWN: number;
static FORWARDX: number;
static FORWARDY: number;
static BACKWARDX: number;
static BACKWARDY: number;
static ISOSPRITE: number;
static ISOARCADE: number;
projector: Phaser.Plugin.Isometric.Projector;
constructor(game: Phaser.Game, parent?: any);
addIsoSprite(x: number, y: number, z: number, key?: any, frame?: any, group?: Phaser.Group): Phaser.Plugin.Isometric.IsoSprite;
}
module Isometric {
class Projector {
game: Phaser.Game;
anchor: Phaser.Point;
projectionAngle: number;
project(point3: Phaser.Plugin.Isometric.Point3, out?: Phaser.Point): Phaser.Point;
projectXY(point3: Phaser.Plugin.Isometric.Point3, out?: Phaser.Point): Phaser.Point;
unproject(point: Phaser.Point, out?: Phaser.Plugin.Isometric.Point3, z?: number): Phaser.Plugin.Isometric.Point3;
simpleSort(group: Phaser.Group): void;
topologicalSort(group: Phaser.Group, padding?: number, prop?: string): void;
}
class Point3 {
static add(a: Phaser.Plugin.Isometric.Point3, b: Phaser.Plugin.Isometric.Point3, out?: Phaser.Plugin.Isometric.Point3): Phaser.Plugin.Isometric.Point3;
static subtract(a: Phaser.Plugin.Isometric.Point3, b: Phaser.Plugin.Isometric.Point3, out?: Phaser.Plugin.Isometric.Point3): Phaser.Plugin.Isometric.Point3;
static multiply(a: Phaser.Plugin.Isometric.Point3, b: Phaser.Plugin.Isometric.Point3, out?: Phaser.Plugin.Isometric.Point3): Phaser.Plugin.Isometric.Point3;
static divide(a: Phaser.Plugin.Isometric.Point3, b: Phaser.Plugin.Isometric.Point3, out?: Phaser.Plugin.Isometric.Point3): Phaser.Plugin.Isometric.Point3;
static equals(a: Phaser.Plugin.Isometric.Point3, b: Phaser.Plugin.Isometric.Point3): boolean;
x: number;
y: number;
z: number;
constructor(x?: number, y?: number, z?: number);
copyFrom(source: any): Phaser.Plugin.Isometric.Point3;
copyto(dest: any): any;
equals(a: any): boolean;
set(x?: number, y?: number, z?: number): Phaser.Plugin.Isometric.Point3;
setTo(x?: number, y?: number, z?: number): Phaser.Plugin.Isometric.Point3;
add(x?: number, y?: number): Phaser.Plugin.Isometric.Point3;
subtract(x?: number, y?: number, z?: number): Phaser.Plugin.Isometric.Point3;
multiply(x?: number, y?: number, z?: number): Phaser.Plugin.Isometric.Point3;
divide(x?: number, y?: number, z?: number): Phaser.Plugin.Isometric.Point3;
containsXY(x?: number, y?: number);
}
class Octree {
maxObjects: number;
maxLevels: number;
level: number;
bounds: any;
objects: any[];
nodes: any[];
constructor(x: number, y: number, z: number, widthX: number, widthY: number, height: number, maxObject?: number, maxLevels?: number, level?: number);
reset(x: number, y: number, z: number, widthX: number, widthY: number, height: number, maxObject?: number, maxLevels?: number, level?: number): void;
populate(group: Phaser.Group): void;
populateHandler(sprite: Phaser.Plugin.Isometric.IsoSprite): void;
populateHandler(sprite: any): void;
split(): void;
insert(body: Phaser.Plugin.Isometric.Body): void;
insert(body: Phaser.Plugin.Isometric.Cube): void;
insert(body: any): void;
getIndex(cube: Phaser.Plugin.Isometric.Cube): number;
getIndex(cube: any): number;
retrieve(source: Phaser.Plugin.Isometric.IsoSprite): any[];
retrieve(source: Phaser.Plugin.Isometric.Cube): any[];
clear(): void;
}
class IsoSprite extends Phaser.Sprite {
snap: number;
isoX: number;
isoY: number;
isoZ: number;
isoPosition: Phaser.Plugin.Isometric.Point3;
isoBounds: Phaser.Plugin.Isometric.Point3;
depth: number;
constructor(game: Phaser.Game, x: number, y: number, z: number, key?: any, frame?: any);
resetIsoBounds(): void;
}
class Cube {
static size(a: Phaser.Plugin.Isometric.Cube, output?: Phaser.Plugin.Isometric.Point3): Phaser.Plugin.Isometric.Point3;
static clone(a: Phaser.Plugin.Isometric.Cube, output?: Phaser.Plugin.Isometric.Cube): Phaser.Plugin.Isometric.Cube;
static contains(a: Phaser.Plugin.Isometric.Cube, x: number, y: number, z: number): boolean;
static containsXY(a: Phaser.Plugin.Isometric.Cube, x: number, y: number): boolean;
static containsPoint3(a: Phaser.Plugin.Isometric.Cube, point3: Phaser.Plugin.Isometric.Point3): boolean;
static containsCube(a: Phaser.Plugin.Isometric.Cube, b: Phaser.Plugin.Isometric.Cube): boolean;
static intersects(a: Phaser.Plugin.Isometric.Cube, b: Phaser.Plugin.Isometric.Cube): boolean;
x: number;
y: number;
z: number;
widthX: number;
widthY: number;
height: number;
halfWidthX: number;
halfWidthY: number;
halfHeight: number;
bottom: number;
top: number;
backX: number;
backY: number;
frontX: number;
frontY: number;
volume: number;
centerX: number;
centerY: number;
centerZ: number;
randomX: number;
randomY: number;
randomZ: number;
empty: boolean;
constructor(x?: number, y?: number, z?: number, widthX?: number, widthY?: number, height?: number);
setTo(x?: number, y?: number, z?: number, widthX?: number, widthY?: number, height?: number): Phaser.Plugin.Isometric.Cube;
copyFrom(source: any): Phaser.Plugin.Isometric.Cube;
copyTo(dest: any): Phaser.Plugin.Isometric.Cube;
size(output?: Phaser.Plugin.Isometric.Point3): Phaser.Plugin.Isometric.Point3;
contains(x: number, y: number, z: number): boolean;
containsXY(x: number, y: number): boolean;
clone(output?: Phaser.Plugin.Isometric.Cube): Phaser.Plugin.Isometric.Cube;
intersects(b: Phaser.Plugin.Isometric.Cube): boolean;
getCorners(): Phaser.Plugin.Isometric.Point3[];
toString(): string;
}
class Body {
static render(context: any, body: Phaser.Plugin.Isometric.Body, color?: string, filled?: boolean): void;
static renderBodyInfo(debug: any, body: Phaser.Plugin.Isometric.Body): void; //togo debug?
sprite: Phaser.Plugin.Isometric.IsoSprite;
game: Phaser.Game;
type: number;
enable: boolean;
offset: Phaser.Plugin.Isometric.Point3;
position: Phaser.Plugin.Isometric.Point3;
prev: Phaser.Plugin.Isometric.Point3;
allowRotation: boolean;
rotation: number;
preRotation: number;
sourceWidthX: number;
sourceWidthY: number;
sourceHeight: number;
widthX: number;
widthY: number;
height: number;
halfWidthX: number;
halfWidthY: number;
halfHeight: number;
center: Phaser.Plugin.Isometric.Point3;
velocity: Phaser.Plugin.Isometric.Point3;
newVelocity: Phaser.Plugin.Isometric.Point3;
deltaMax: Phaser.Plugin.Isometric.Point3;
acceleration: Phaser.Plugin.Isometric.Point3;
drag: Phaser.Plugin.Isometric.Point3;
allowGravity: boolean;
gravity: Phaser.Plugin.Isometric.Point3;
bounce: Phaser.Plugin.Isometric.Point3;
maxVelocity: Phaser.Plugin.Isometric.Point3;
angularVelocity: number;
angularAcceleration: number;
angularDrag: number;
maxAngular: number;
mass: number;
angle: number;
speed: number;
facing: number;
immovable: boolean;
moves: boolean;
customSeparateX: boolean;
customSeparateY: boolean;
customSeparateZ: boolean;
overlapX: number;
overlapY: number;
overlayZ: number;
embedded: boolean;
collideWorldBounds: boolean;
checkCollision: {
none: boolean;
any: boolean;
up: boolean;
down: boolean;
frontX: number;
frontY: number;
backX: number;
backY: number;
};
touching: {
none: boolean;
up: boolean;
down: boolean;
frontX: number;
frontY: number;
backX: number;
backY: number;
};
wasTouching: {
none: boolean;
up: boolean;
down: boolean;
frontX: number;
frontY: number;
backX: number;
backY: number;
};
blocked: {
up: boolean;
down: boolean;
frontX: number;
frontY: number;
backX: number;
backY: number;
};
phase: number;
skipTree: boolean;
top: number;
frontX: number;
right: number;
frontY: number;
bottom: number;
x: number;
y: number;
z: number;
constructor(sprite: Phaser.Plugin.Isometric.IsoSprite);
destroy(): void;
setSize(widthX: number, widthY: number, height: number, offsetX?: number, offsetY?: number, offsetZ?: number): void;
reset(x: number, y: number, z: number): void;
hitText(x: number, y: number, z: number): boolean;
onFloor(): boolean;
onWall(): boolean;
deltaAbsX(): number;
deltaAbsY(): number;
deltaAbsZ(): number;
deltaX(): number;
deltaY(): number;
deltaZ(): number;
deltaR(): number;
getCorners(): Phaser.Plugin.Isometric.Point3[];
}
class Arcade {
game: Phaser.Game;
gravity: Phaser.Plugin.Isometric.Point3;
bounds: Phaser.Plugin.Isometric.Cube;
checkCollision: {
up: boolean;
down: boolean;
frontX: boolean;
frontY: boolean;
backX: boolean;
backY: boolean;
};
maxObjects: number;
maxLevels: number;
OVERLAP_BIAS: number;
forceXY: boolean;
skipTree: boolean;
useQuadTree: boolean;
quadTree: Phaser.QuadTree;
octree: Phaser.Plugin.Isometric.Octree;
constructor(game: Phaser.Game);
setBounds(x: number, y: number, z: number, widthX: number, widthY: number, height: number): void;
setBoundsToWorld(): void;
enable(object: any, children?: boolean): void;
enableBody(object: any): void;
updateMotion(body: Phaser.Plugin.Isometric.Body): void;
computeVelocity(axis: number, body: Phaser.Plugin.Isometric.Body, velocity: number, acceleration: number, drag: number, max?: number): number;
overlap(object1: any, object2: any, overlapCallback?: Function, processCallback?: Function, callbackContext?: any): boolean;
collide(object1: any, object2: any, overlapCallback?: Function, processCallback?: Function, callbackContext?: any): boolean;
intersects(body1: Phaser.Plugin.Isometric.Body): boolean;
distanceBetween(source: any, target: any): number;
distanceToXY(displayObject: any, x: number, y: number): number;
distanceToXYZ(displayObject: any, x: number, y: number, z: number): number;
}
}
}

File diff suppressed because it is too large Load Diff

57
mar/phaser/mar.min.js vendored
View File

@ -1,57 +0,0 @@
DIR_NORTH=0;DIR_EAST=1;DIR_SOUTH=2;DIR_WEST=3;WORLD_HEIGHT=WORLD_WIDTH=16;var colorScheme={tileTint:16777215,wallTint:14540253,cubotHoverTint:65280,cubotTint:16777215,textFill:"#FFFFFF",textStroke:"#9298a8",biomassTint:6535263,biomassHoverTint:65280,tileHoverTint:65280,itemIron:4408129,itemCopper:13139256,hologramFill:"#0aced6",hologramStroke:"#12FFB0",hologramAlpha:.9},mar={kbBuffer:[],kbBufferText:"",animationFrames:{},controlledUnitVisible:!1,lastLines:""};
CUBOT_WALK_FRAMES={south:240,north:194,west:254,east:164};HARVESTER_WALK_FRAMES={south:347,north:317,west:377,east:287};LOW_ENERGY=100;fullscreen?(RENDERER_WIDTH=window.innerWidth-4,RENDERER_HEIGHT=window.innerHeight-4):(RENDERER_WIDTH=document.getElementById("game").clientWidth,RENDERER_HEIGHT=window.innerHeight/1.25);var game=new Phaser.Game(RENDERER_WIDTH,RENDERER_HEIGHT,Phaser.AUTO,"game",null,!0,!1);
function dispatchTileLeave(a,b){for(var c=0;c<mar.world.tiles.length;c++){var d=mar.world.tiles[c].tileX,f=mar.world.tiles[c].tileY;mar.world.tiles[c].isWall&&(d===a&&f-1===b||d-1===a&&f-1===b||d-1===a&&f===b)&&1!==mar.world.tiles[c].alpha&&game.add.tween(mar.world.tiles[c]).to({alpha:1},175,Phaser.Easing.Quadratic.In,!0)}}
function dispatchTileEnter(a,b){for(var c=0;c<mar.world.tiles.length;c++){var d=mar.world.tiles[c].tileX,f=mar.world.tiles[c].tileY;mar.world.tiles[c].isWall&&(d===a&&f-1===b||d-1===a&&f-1===b||d-1===a&&f===b)&&game.add.tween(mar.world.tiles[c]).to({alpha:.6},300,Phaser.Easing.Quadratic.In,!0)}}
function Word(a){var b=this;b.tiles=[];b.objects=[];setupWorldArrows();this.setTerrain=function(a){for(var d=0;d<WORLD_HEIGHT;d++)for(var c=0;c<WORLD_HEIGHT;c++){var e=a[c*WORLD_WIDTH+d];if(1===e)e=game.add.isoSprite(getIsoX(d),getIsoY(c),0,"sheet","tiles/bigTile",isoGroup),e.baseZ=0,e.baseTint=colorScheme.wallTint,e.anchor.set(.5,.2),e.isWall=!0;else{if(2===e)e=game.add.isoSprite(getIsoX(d),getIsoY(c),0,"sheet","tiles/tile",isoGroup),g=game.make.text(0,16,"Iron",{fontSize:22,fill:"#434341",stroke:"#FFFFFF",
strokeThickness:1,font:"fixedsys"}),g.alpha=.6,g.anchor.set(.5,0),e.addChild(g),e.baseZ=0,e.baseTint=15987699;else if(3===e){e=game.add.isoSprite(getIsoX(d),getIsoY(c),0,"sheet","tiles/tile",isoGroup);var g=game.make.text(0,16,"Copper",{fontSize:22,fill:"#C87D38",stroke:"#FFFFFF",strokeThickness:1,font:"fixedsys"});g.alpha=.6;g.anchor.set(.5,0);e.addChild(g);e.baseZ=0;e.baseTint=15987699}else e=game.add.isoSprite(getIsoX(d),getIsoY(c),0,"sheet","tiles/tile",isoGroup),e.baseZ=0,e.baseTint=colorScheme.tileTint;
e.anchor.set(.5,0)}e.isTile=!0;e.tileX=d;e.tileY=c;e.tint=e.baseTint;b.tiles.push(e)}};this.setTerrain(a);this.update=function(a){for(var b=0;b<mar.world.objects.length;b++)mar.world.objects[b].destroy();for(b=0;b<mar.world.tiles.length;b++)mar.world.tiles[b].destroy();mar.world.objects=[];mar.world.tiles=[];this.setTerrain(a);game.iso.topologicalSort(isoGroup)};this.getObject=function(a){for(var d=0;d<b.objects.length;d++)if(b.objects[d].id===a)return b.objects[d];return null};this.updateObjects=
function(a){for(d=0;d<b.objects.length;d++)b.objects[d].updated=!1;for(var d=0;d<a.length;d++){var c=b.getObject(a[d].i);null!==c?(c.updated=!0,updateGameObject(c,a[d])):(c=createGameObject(a[d]),c.updated=!0,b.objects.push(c))}for(d=0;d<b.objects.length;d++)b.objects[d].updated||("guest"!==mar.client.username&&1===b.objects[d].type&&b.objects[d].username===mar.client.username&&(findMyRobot(),console.log("Following Cubot "+mar.client.username)),b.objects[d].destroy(),dispatchTileLeave(b.objects[d].tileX,
b.objects[d].tileY),b.objects.splice(d,1))}}
function updateGameObject(a,b){a.direction=b.direction;if(1===a.type){a.action=b.action;a.energy=b.energy;if(a.tileX!==b.x||a.tileY!==b.y)dispatchTileLeave(a.tileX,a.tileY),a.tileX=b.x,a.tileY=b.y,cubotWalk(a,a.direction,void 0,CUBOT_WALK_FRAMES);a.heldItem!==b.heldItem&&(void 0!==a.inventory&&a.inventory.destroy(),a.inventory=createInventory([b.heldItem]),a.addChild(a.inventory),a.heldItem=b.heldItem);a.tint!==colorScheme.cubotHoverTint&&(a.tint=a.energy<=LOW_ENERGY?16711680:16777215);switch(a.direction){case DIR_NORTH:a.animations.frame=
194;break;case DIR_EAST:a.animations.frame=164;break;case DIR_SOUTH:a.animations.frame=240;break;case DIR_WEST:a.animations.frame=254}void 0!==a.hologram&&a.hologram.destroy();var c=!1;b.holoC&&(c="#"+Number(b.holoC&16777215).toString(16));1===b.holoMode?(a.hologram=game.make.text(0,32,"0x"+("0000"+Number(b.holo).toString(16).toUpperCase()).slice(-4),{fontSize:32,fill:c?c:colorScheme.hologramFill,stroke:colorScheme.hologramStroke,strokeThickness:1,font:"fixedsys"}),console.log(Number(c).toString(16))):
2===b.holoMode?a.hologram=game.make.text(0,32,b.holoStr,{fontSize:27,fill:c?c:colorScheme.hologramFill,stroke:colorScheme.hologramStroke,strokeThickness:1,font:"fixedsys"}):3===b.holoMode&&(a.hologram=game.make.text(0,32,Number(b.holo).toString(),{fontSize:32,fill:c?c:colorScheme.hologramFill,stroke:colorScheme.hologramStroke,strokeThickness:1,font:"fixedsys"}));void 0!==a.hologram&&(a.hologram.alpha=colorScheme.hologramAlpha,a.hologram.anchor.set(.5,0),a.addChild(a.hologram),game.add.tween(a.hologram).to({tint:16777200,
alpha:colorScheme.hologramAlpha-.1},mar.client.tickLength,Phaser.Easing.Bounce.In,!0));1===a.action&&cubotDig(a,a.direction)}else if(10===a.type){a.action=b.action;if(a.tileX!==b.x||a.tileY!==b.y)dispatchTileLeave(a.tileX,a.tileY),a.tileX=b.x,a.tileY=b.y,cubotWalk(a,a.direction,void 0,HARVESTER_WALK_FRAMES);switch(a.direction){case DIR_NORTH:a.animations.frame=HARVESTER_WALK_FRAMES.north;break;case DIR_EAST:a.animations.frame=HARVESTER_WALK_FRAMES.east;break;case DIR_SOUTH:a.animations.frame=HARVESTER_WALK_FRAMES.south;
break;case DIR_WEST:a.animations.frame=HARVESTER_WALK_FRAMES.west}}}function itemColor(a){switch(a){case 1:return colorScheme.biomassTint;case 3:return colorScheme.itemIron;case 4:return colorScheme.itemCopper}}
function createInventory(a){var b=game.make.group();switch(a.length){case 0:return b;case 1:if(0!==a[0]){var c=game.make.sprite(0,0,"sheet","inventory/inv1x1");c.anchor.set(.5,.1);c.alpha=.5;var d=game.make.sprite(0,0,"sheet","inventory/item");d.anchor.set(.5,.1);d.tint=itemColor(a[0]);b.addChild(c);b.addChild(d)}return b}for(b=0;b<a.length;b++);}
function createGameObject(a){if(1===a.t){var b=game.add.isoSprite(getIsoX(a.x),getIsoY(a.y),15,"sheet",null,isoGroup);b.anchor.set(.5,0);b.inputEnabled=!0;b.events.onInputDown.add(function(){debugObj="Cubot: "+b.tileX+", "+b.tileY});b.events.onInputOver.add(function(){document.body.style.cursor="pointer"});b.events.onInputOut.add(function(){document.body.style.cursor="default"});b.id=a.i;b.type=1;b.tileX=a.x;b.tileY=a.y;b.username=a.parent;b.heldItem=a.heldItem;b.direction=a.direction;b.action=a.action;
b.energy=a.energy;b.inventory=createInventory([b.heldItem]);b.addChild(b.inventory);dispatchTileEnter(a.x,a.y);b.isAt=function(a,b){return this.tileX===a&&this.tileY===b};b.onTileHover=function(){game.add.tween(this).to({isoZ:45},200,Phaser.Easing.Quadratic.InOut,!0);game.add.tween(this.scale).to({x:1.2,y:1.2},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotHoverTint};b.onTileOut=function(){document.body.style.cursor="default";game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,
!0);game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=16777215};b.energy<=LOW_ENERGY&&(b.tint=13369344);b.animations.add("walk_w",mar.animationFrames.walk_w,!0);b.animations.add("walk_s",mar.animationFrames.walk_s,!0);b.animations.add("walk_e",mar.animationFrames.walk_e,!0);b.animations.add("walk_n",mar.animationFrames.walk_n,!0);b.animations.add("dig_w",mar.animationFrames.dig_w,!1);b.animations.add("dig_s",mar.animationFrames.dig_s,!1);b.animations.add("dig_e",
mar.animationFrames.dig_e,!1);b.animations.add("dig_n",mar.animationFrames.dig_n,!1);b.queuedAnims=[];switch(b.direction){case DIR_NORTH:b.animations.frame=194;break;case DIR_EAST:b.animations.frame=164;break;case DIR_SOUTH:b.animations.frame=240;break;case DIR_WEST:b.animations.frame=254}a=game.make.text(0,-24,b.username,{fontSize:22,fill:colorScheme.textFill,stroke:colorScheme.textStroke,strokeThickness:2,font:"fixedsys"});a.alpha=.85;a.anchor.set(.5,0);b.username===mar.client.username?a.tint=16469258:
b.alpha=.6;b.addChild(a);return b}if(2===a.t){var c=game.add.isoSprite(getIsoX(a.x),getIsoY(a.y),10,"sheet",1,isoGroup);c.animations.add("idle",mar.animationFrames.biomassIdle,!0);c.anchor.set(.5,0);c.type=2;c.tileX=a.x;c.tileY=a.y;c.id=a.i;c.tint=colorScheme.biomassTint;c.hoverText=game.make.text(0,0,"Biomass",{fontSize:22,fill:colorScheme.textFill,stroke:colorScheme.textStroke,strokeThickness:2,font:"fixedsys"});c.hoverText.alpha=0;c.hoverText.anchor.set(.5,0);c.addChild(c.hoverText);c.isAt=function(a,
b){return this.tileX===a&&this.tileY===b};c.isAt=function(a,b){return this.tileX===a&&this.tileY===b};c.onTileHover=function(){game.tweens.removeFrom(this);document.body.style.cursor="pointer";game.add.tween(this).to({isoZ:45},200,Phaser.Easing.Quadratic.InOut,!0);this.tint=colorScheme.biomassHoverTint;game.add.tween(this.scale).to({x:1.2,y:1.2},200,Phaser.Easing.Linear.None,!0);game.add.tween(this.hoverText).to({alpha:.9},200,Phaser.Easing.Quadratic.In,!0);c.hoverText.visible=!0};c.onTileOut=function(){game.tweens.removeFrom(this);
document.body.style.cursor="default";game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,!0);game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.biomassTint;game.add.tween(this.hoverText).to({alpha:0},200,Phaser.Easing.Quadratic.Out,!0)};c.animations.play("idle",45,!0);return c}if(10===a.t){var d=game.add.isoSprite(getIsoX(a.x),getIsoY(a.y),15,"sheet",null,isoGroup);d.anchor.set(.5,0);d.id=a.i;d.type=10;d.tileX=a.x;d.tileY=a.y;d.direction=a.direction;
d.action=a.action;dispatchTileEnter(a.x,a.y);d.isAt=function(a,b){return this.tileX===a&&this.tileY===b};d.onTileHover=function(){game.add.tween(this).to({isoZ:45},200,Phaser.Easing.Quadratic.InOut,!0);game.add.tween(this.scale).to({x:1.2,y:1.2},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotHoverTint};d.onTileOut=function(){game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,!0);game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotTint};
d.animations.add("walk_w",mar.animationFrames.harvester_walk_w,!0);d.animations.add("walk_s",mar.animationFrames.harvester_walk_s,!0);d.animations.add("walk_e",mar.animationFrames.harvester_walk_e,!0);d.animations.add("walk_n",mar.animationFrames.harvester_walk_n,!0);d.queuedAnims=[];switch(d.direction){case DIR_NORTH:d.animations.frame=HARVESTER_WALK_FRAMES.north;break;case DIR_EAST:d.animations.frame=HARVESTER_WALK_FRAMES.east;break;case DIR_SOUTH:d.animations.frame=HARVESTER_WALK_FRAMES.south;
break;case DIR_WEST:d.animations.frame=HARVESTER_WALK_FRAMES.west}return d}if(3===a.t){var f=game.add.isoSprite(getIsoX(a.x),getIsoY(a.y),15,"sheet","objects/factory",isoGroup);f.anchor.set(.5,.25);f.id=a.i;f.type=3;f.tileX=a.x;f.tileY=a.y;f.hoverText=game.make.text(0,0,"Factory",{fontSize:22,fill:colorScheme.textFill,stroke:colorScheme.textStroke,strokeThickness:2,font:"fixedsys"});f.hoverText.alpha=0;f.hoverText.anchor.set(.5,0);f.addChild(f.hoverText);f.isAt=function(a,b){return(this.tileX===a||
this.tileX+1===a)&&(this.tileY+1===b||this.tileY===b)};f.onTileHover=function(){game.tweens.removeFrom(this);game.add.tween(this).to({isoZ:25},200,Phaser.Easing.Quadratic.InOut,!0);game.add.tween(this.scale).to({x:1.06,y:1.06},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotHoverTint;game.add.tween(this.hoverText).to({alpha:.9},200,Phaser.Easing.Quadratic.In,!0);f.hoverText.visible=!0};f.onTileOut=function(){game.tweens.removeFrom(this);game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,
!0);game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotTint;game.add.tween(this.hoverText).to({alpha:0},200,Phaser.Easing.Quadratic.Out,!0)};return f}if(4===a.t){var e=game.add.isoSprite(getIsoX(a.x),getIsoY(a.y),15,"sheet","objects/RadioTower",isoGroup);e.anchor.set(.5,.64);e.id=a.i;e.type=4;e.tileX=a.x;e.tileY=a.y;e.hoverText=game.make.text(0,0,"Radio Tower",{fontSize:22,fill:colorScheme.textFill,stroke:colorScheme.textStroke,strokeThickness:2,font:"fixedsys"});
e.hoverText.alpha=0;e.hoverText.anchor.set(.5,0);e.addChild(e.hoverText);e.isAt=function(a,b){return this.tileX===a&&this.tileY===b};e.onTileHover=function(){game.tweens.removeFrom(this);game.add.tween(this).to({isoZ:45},200,Phaser.Easing.Quadratic.InOut,!0);game.add.tween(this.scale).to({x:1.15,y:1.15},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotHoverTint;game.add.tween(this.hoverText).to({alpha:.9},200,Phaser.Easing.Quadratic.In,!0);e.hoverText.visible=!0};e.onTileOut=function(){game.tweens.removeFrom(this);
game.add.tween(this).to({isoZ:15},400,Phaser.Easing.Bounce.Out,!0);game.add.tween(this.scale).to({x:1,y:1},200,Phaser.Easing.Linear.None,!0);this.tint=colorScheme.cubotTint;game.add.tween(this.hoverText).to({alpha:0},200,Phaser.Easing.Quadratic.Out,!0)};return e}}function manhanttanDistance(a,b,c,d){return Math.abs(a-c)+Math.abs(b-d)}function codeListener(a){"code"===a.t&&ace.edit("editor").setValue(a.code)}
function authListener(a){"auth"===a.t&&("ok"===a.m?(console.log("Auth successful"),mar.client.requestUserInfo()):alert("Authentication failed. Please make sure you are logged in and reload the page."))}function codeResponseListener(a){"codeResponse"===a.t&&alert("Uploaded and assembled "+a.bytes+" bytes")}function userInfoListener(a){"userInfo"===a.t&&(console.log(a),mar.worldX=a.worldX,mar.worldY=a.worldY,mar.maxWidth=a.maxWidth,mar.client.requestTerrain())}
function terrainListener(a){"terrain"===a.t&&(void 0!==mar.world?(mar.client.socket.send(JSON.stringify({t:"object",x:mar.worldX,y:mar.worldY})),mar.world.update(a.terrain)):(mar.world=new Word(a.terrain),console.log("Gameloop started"),game.input.keyboard.onDownCallback=function(a){document.activeElement===document.getElementById("game")&&((37<=a.keyCode&&40>=a.keyCode||116===a.keyCode||32===a.keyCode)&&a.preventDefault(),"guest"!==mar.client.username&&16>=mar.kbBuffer.length&&(mar.client.sendKeypress(a.keyCode),
mar.kbBuffer.push(a.keyCode),mar.kbBufferText=formattedKeyBuffer(mar.kbBuffer)))},game.input.onDown.add(function(){document.getElementById("game").focus()})))}function objectListener(a){"object"===a.t&&mar.world.updateObjects(a.objects)}function floppyListener(a){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")}
function tickListener(a){if("tick"===a.t){mar.client.socket.send(JSON.stringify({t:"object",x:mar.worldX,y:mar.worldY}));void 0!==a.keys&&(mar.kbBuffer=a.keys,mar.kbBufferText=formattedKeyBuffer(mar.kbBuffer));var b=document.getElementById("console");0===a.cm&&(b.innerHTML="",mar.lastLines="");if(void 0!==a.c){for(var c=mar.lastLines,d=0;d<a.c.length;d++)c+=a.c[d];a=b.innerHTML="";var f=c.split("\n");for(d=0;d<f.length;d++)if(40<=f[d].length)for(var e=f[d].match(/.{1,40}/g),g=0;g<e.length;g++)g!==
e.length-1&&(a+="\n");else a+=f[d]+"\n";b.innerHTML=a;mar.lastLines=c;b.scrollTop=b.scrollHeight}}}
var GameClient=function(a){var b=this,c=[],d=new XMLHttpRequest;d.open("GET","./getServerInfo.php",!0);d.onreadystatechange=function(){4===d.readyState&&200===d.status&&(console.log("Received server info "+d.responseText),setTimeout(function(){var f=JSON.parse(d.responseText);console.log(f.address);b.socket=new WebSocket(f.address);b.username=f.username;b.tickLength=f.tickLength;b.serverName=f.serverName;mar.client.socket.binaryType="arraybuffer";b.socket.onopen=function(){b.socket.send(f.token);
c.push(authListener);c.push(userInfoListener);c.push(terrainListener);c.push(tickListener);c.push(objectListener);c.push(codeListener);c.push(codeResponseListener);mar.client.socket.onmessage=function(a){try{var b=JSON.parse(a.data)}catch(h){console.log(h),floppyListener(a)}for(a=0;a<c.length;a++)c[a](b)};b.reloadCode();void 0!==a&&a()};b.socket.onerror=function(a){alert("Can't connect to game server at address "+f.address);console.log(a)};b.socket.onclose=function(a){alert("Disconnected from server");
console.log(a)}},100))};d.send(null);this.requestUserInfo=function(){this.socket.send(JSON.stringify({t:"userInfo"}))};this.requestTerrain=function(){this.socket.send(JSON.stringify({t:"terrain",x:mar.worldX,y:mar.worldY}))};this.uploadCode=function(a){console.log("Uploaded code");this.socket.send(JSON.stringify({t:"uploadCode",code:a}))};this.reloadCode=function(){this.socket.send(JSON.stringify({t:"codeRequest"}))};this.sendKeypress=function(a){0!==a&&this.socket.send(JSON.stringify({t:"k",k:a}))};
this.requestFloppy=function(){document.getElementById("floppyDown").innerHTML='<i class="fa fa-cog fa-spin fa-fw"></i>';this.socket.send(JSON.stringify({t:"floppyDown"}))};this.notifyFloppyUp=function(){this.socket.send(JSON.stringify({t:"floppyUp"}))}};function dispatchTileHover(a,b){for(var c in mar.world.objects){var d=mar.world.objects[c];if(d.isAt(a,b))d.onTileHover()}}function dispatchTileOut(a,b){for(var c in mar.world.objects){var d=mar.world.objects[c];if(d.isAt(a,b))d.onTileOut()}}
var count=0,BasicGame=function(a){};BasicGame.Boot=function(a){};var isoGroup,cursorPos,cursor,debugTile,debugObj,objectsGroup,cursors,tmpLine;
BasicGame.Boot.prototype={preload:function(){game.load.atlasJSONHash("sheet","./mar/sprites.png","./mar/sprites.json");game.time.advancedTiming=!0;game.plugins.add(new Phaser.Plugin.Isometric(game));game.iso.anchor.setTo(.5,0);game.world.setBounds(0,0,2200,1100);game.camera.x=280;game.camera.y=90;game.stage.disableVisibilityChange=!0},create:function(){isoGroup=game.add.group();objectsGroup=game.add.group();initialiseAnimations();this.spawnTiles();cursorPos=new Phaser.Plugin.Isometric.Point3;cursors=
game.input.keyboard.createCursorKeys()},update:function(){game.iso.unproject(game.input.activePointer.position,cursorPos);isoGroup.forEach(function(a){if(a.isTile){var b=a.isoBounds.containsXY(cursorPos.x,cursorPos.y);!a.selected&&b?(a.selected=!0,a.tint=colorScheme.tileHoverTint,debugTile=a.tileX+", "+a.tileY,dispatchTileHover(a.tileX,a.tileY),game.add.tween(a).to({isoZ:a.baseZ+8},200,Phaser.Easing.Quadratic.InOut,!0)):a.selected&&!b&&(dispatchTileOut(a.tileX,a.tileY),a.selected=!1,a.tint=a.baseTint,
game.add.tween(a).to({isoZ:a.baseZ},200,Phaser.Easing.Quadratic.InOut,!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;count++;0===count%10&&game.iso.topologicalSort(isoGroup)},render:function(){void 0!==
mar.worldX?game.debug.text("World: ("+Number(mar.worldX).toString(16)+", "+Number(mar.worldY).toString(16)+")",10,20):game.debug.text("World: (?,?)",10,20);debugTile&&game.debug.text(debugTile,10,40);"guest"!==mar.client.username&&game.debug.text(mar.kbBufferText,210,20);void 0!==tmpLine&&(game.debug.geom(tmpLine),game.debug.lineInfo(tmpLine,32,32))},spawnTiles:function(){mar.client=new GameClient}};
function setupWorldArrows(){var a=game.make.isoSprite(528,-10,10,"sheet","ui/arrow_north",isoGroup);a.inputEnabled=!0;a.events.onInputDown.add(function(){0===mar.worldY?mar.worldY=mar.maxWidth:mar.worldY--;mar.client.requestTerrain()});a.events.onInputOver.add(function(){a.tint=65280;document.body.style.cursor="pointer"});a.events.onInputOut.add(function(){a.tint=16777215;document.body.style.cursor="default"});isoGroup.addChild(a);var b=game.make.isoSprite(1115,587,10,"sheet","ui/arrow_east",isoGroup);
b.inputEnabled=!0;b.events.onInputDown.add(function(){mar.worldX===mar.maxWidth?mar.worldX=0:mar.worldX++;mar.client.requestTerrain()});b.events.onInputOver.add(function(){b.tint=65280;document.body.style.cursor="pointer"});b.events.onInputOut.add(function(){b.tint=16777215;document.body.style.cursor="default"});isoGroup.addChild(b);var c=game.make.isoSprite(528,1170,10,"sheet","ui/arrow_south",isoGroup);c.inputEnabled=!0;c.events.onInputDown.add(function(){mar.worldY===mar.maxWidth?mar.worldY=0:
mar.worldY++;mar.client.requestTerrain()});c.events.onInputOver.add(function(){c.tint=65280;document.body.style.cursor="pointer"});c.events.onInputOut.add(function(){c.tint=16777215;document.body.style.cursor="default"});isoGroup.addChild(c);var d=game.make.isoSprite(-60,587,10,"sheet","ui/arrow_west",isoGroup);d.inputEnabled=!0;d.events.onInputDown.add(function(){0===mar.worldX?mar.worldX=mar.maxWidth:mar.worldX--;mar.client.requestTerrain()});d.events.onInputOver.add(function(){d.tint=65280;document.body.style.cursor=
"pointer"});d.events.onInputOut.add(function(){d.tint=16777215;document.body.style.cursor="default"});isoGroup.addChild(d)}function cubotDig(a,b,c){b===DIR_NORTH?a.animations.play("dig_n",45):b===DIR_EAST?a.animations.play("dig_e",45):b===DIR_SOUTH?a.animations.play("dig_s",45):b===DIR_WEST&&a.animations.play("dig_w",45)}
function cubotWalk(a,b,c,d){var f;if(b===DIR_SOUTH)var e=function(b){a.animations.play("walk_s",60,!0);f=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0);dispatchTileEnter(a.tileX,a.tileY);f.onComplete.add(function(){a.animations.stop();a.animations.frame=d.south;a.onTileOut();a.isoX=getIsoX(a.tileX);a.isoY=getIsoY(a.tileY);void 0!==c&&c();for(var b=0;b<a.queuedAnims.length;b++)a.queuedAnims[b](500),a.queuedAnims.splice(b,1)})};else b===DIR_NORTH?
e=function(b){a.animations.play("walk_n",60,!0);f=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0);dispatchTileEnter(a.tileX,a.tileY);f.onComplete.add(function(){a.animations.stop();a.animations.frame=d.north;a.onTileOut();a.isoX=getIsoX(a.tileX);a.isoY=getIsoY(a.tileY);void 0!==c&&c();for(var b=0;b<a.queuedAnims.length;b++)a.queuedAnims[b](500),a.queuedAnims.splice(b,1)})}:b===DIR_WEST?e=function(b){a.animations.play("walk_w",60,!0);f=game.add.tween(a).to({isoX:getIsoX(a.tileX),
isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0);dispatchTileEnter(a.tileX,a.tileY);f.onComplete.add(function(){a.animations.stop();a.animations.frame=d.west;a.onTileOut();a.isoX=getIsoX(a.tileX);a.isoY=getIsoY(a.tileY);void 0!==c&&c();for(var b=0;b<a.queuedAnims.length;b++)a.queuedAnims[b](500),a.queuedAnims.splice(b,1)})}:b===DIR_EAST&&(e=function(b){a.animations.play("walk_e",60,!0);f=game.add.tween(a).to({isoX:getIsoX(a.tileX),isoY:getIsoY(a.tileY)},b,Phaser.Easing.Linear.None,!0);dispatchTileEnter(a.tileX,
a.tileY);f.onComplete.add(function(){a.animations.stop();a.animations.frame=d.east;a.onTileOut();a.isoX=getIsoX(a.tileX);a.isoY=getIsoY(a.tileY);void 0!==c&&c();for(var b=0;b<a.queuedAnims.length;b++)a.queuedAnims[b](500),a.queuedAnims.splice(b,1)})});a.animations.currentAnim.isPlaying?(a.queuedAnims.push(e),console.log("Queued Animation")):e(800)}
function initialiseAnimations(){mar.animationFrames.walk_e_start=[];for(var a=0;10>a;a++)mar.animationFrames.walk_e_start.push("cubot/walk_e/"+("0000"+a).slice(-4));mar.animationFrames.walk_e=[];for(a=10;30>a;a++)mar.animationFrames.walk_e.push("cubot/walk_e/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_e_start=[];for(a=0;10>a;a++)mar.animationFrames.harvester_walk_e_start.push("harvester/walk_e/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_e=[];for(a=10;30>a;a++)mar.animationFrames.harvester_walk_e.push("harvester/walk_e/"+
("0000"+a).slice(-4));mar.animationFrames.walk_n_start=[];for(a=0;10>a;a++)mar.animationFrames.walk_n_start.push("cubot/walk_n/"+("0000"+a).slice(-4));mar.animationFrames.walk_n=[];for(a=10;30>a;a++)mar.animationFrames.walk_n.push("cubot/walk_n/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_n_start=[];for(a=0;10>a;a++)mar.animationFrames.harvester_walk_n_start.push("harvester/walk_n/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_n=[];for(a=10;30>a;a++)mar.animationFrames.harvester_walk_n.push("harvester/walk_n/"+
("0000"+a).slice(-4));mar.animationFrames.walk_s_start=[];for(a=0;10>a;a++)mar.animationFrames.walk_s_start.push("cubot/walk_s/"+("0000"+a).slice(-4));mar.animationFrames.walk_s=[];for(a=10;30>a;a++)mar.animationFrames.walk_s.push("cubot/walk_s/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_s_start=[];for(a=0;10>a;a++)mar.animationFrames.harvester_walk_s_start.push("harvester/walk_s/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_s=[];for(a=10;30>a;a++)mar.animationFrames.harvester_walk_s.push("harvester/walk_s/"+
("0000"+a).slice(-4));mar.animationFrames.walk_w_start=[];for(a=0;10>a;a++)mar.animationFrames.walk_w_start.push("cubot/walk_w/"+("0000"+a).slice(-4));mar.animationFrames.walk_w=[];for(a=10;30>a;a++)mar.animationFrames.walk_w.push("cubot/walk_w/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_w_start=[];for(a=0;10>a;a++)mar.animationFrames.harvester_walk_w_start.push("harvester/walk_w/"+("0000"+a).slice(-4));mar.animationFrames.harvester_walk_w=[];for(a=10;30>a;a++)mar.animationFrames.harvester_walk_w.push("harvester/walk_w/"+
("0000"+a).slice(-4));mar.animationFrames.dig_e=[];for(a=1;41>=a;a++)mar.animationFrames.dig_e.push("cubot/dig_e/"+("0000"+a).slice(-4));mar.animationFrames.dig_n=[];for(a=1;41>=a;a++)mar.animationFrames.dig_n.push("cubot/dig_n/"+("0000"+a).slice(-4));mar.animationFrames.dig_s=[];for(a=1;41>=a;a++)mar.animationFrames.dig_s.push("cubot/dig_s/"+("0000"+a).slice(-4));mar.animationFrames.dig_w=[];for(a=1;41>=a;a++)mar.animationFrames.dig_w.push("cubot/dig_w/"+("0000"+a).slice(-4));mar.animationFrames.biomassIdle=
[];for(a=1;60>a;a++)mar.animationFrames.biomassIdle.push("objects/biomass/idle/"+("0000"+a).slice(-4))}function getIsoX(a){return 71.5*a}function getIsoY(a){return 71.5*a}function findMyRobot(){"guest"===mar.client.username?alert("You are not logged in!"):mar.client.requestUserInfo()}function formattedKeyBuffer(a){for(var b="KB: ",c=0;16>c;c++)b=void 0!==a[c]?b+(a[c].toString(16)+" "):b+"__ ";return b}game.state.add("Boot",BasicGame.Boot);game.state.start("Boot");

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1060
mar/pixi.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -4221,7 +4221,7 @@
"sourceSize": {"w":128,"h":70},
"pivot": {"x":0.5,"y":0.5}
},
"objects/factory":
"objects/factory":
{
"frame": {"x":256,"y":1050,"w":256,"h":192},
"rotated": false,
@ -4275,52 +4275,76 @@
"sourceSize": {"w":64,"h":64},
"pivot": {"x":0.5,"y":0.5}
},
"objects/RadioTower": {
"frame": {
"x": 904,
"y": 1050,
"w": 128,
"h": 210
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 128,
"h": 210
},
"sourceSize": {
"w": 128,
"h": 210
},
"pivot": {
"x": 0.5,
"y": 0.5
}
},
"objects/RadioTower": {
"frame": {
"x": 904,
"y": 1050,
"w": 168,
"h": 237
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 168,
"h": 237
},
"sourceSize": {
"w": 168,
"h": 237
},
"pivot": {
"x": 0.5,
"y": 0.5
}
},
"objects/rocket":
{
"frame": {
"x": 1032,
"y": 1050,
"w": 135,
"h": 189
},
"frame": {
"x": 1072,
"y": 1050,
"w": 135,
"h": 189
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":135,"h":189},
"sourceSize": {"w":135,"h":189},
"pivot": {"x":0.5,"y":0.5}
},
"objects/VaultDoor": {
"frame": {
"x": 1207,
"y": 1050,
"w": 196,
"h": 196
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 196,
"h": 196
},
"sourceSize": {
"w": 196,
"h": 196
},
"pivot": {
"x": 0.5,
"y": 0.5
}
},
"tiles/bigTile":
{
"frame": {
"x": 1167,
"y": 1050,
"w": 128,
"h": 140
},
"frame": {
"x": 1403,
"y": 1050,
"w": 128,
"h": 140
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":128,"h":140},
@ -4329,12 +4353,12 @@
},
"tiles/copper":
{
"frame": {
"x": 1295,
"y": 1050,
"w": 128,
"h": 64
},
"frame": {
"x": 1531,
"y": 1050,
"w": 128,
"h": 64
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":128,"h":64},
@ -4343,12 +4367,12 @@
},
"tiles/iron":
{
"frame": {
"x": 1423,
"y": 1050,
"w": 128,
"h": 64
},
"frame": {
"x": 1659,
"y": 1050,
"w": 128,
"h": 64
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":128,"h":64},
@ -4357,12 +4381,12 @@
},
"tiles/plain":
{
"frame": {
"x": 1551,
"y": 1050,
"w": 128,
"h": 64
},
"frame": {
"x": 1787,
"y": 1050,
"w": 128,
"h": 64
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":128,"h":64},
@ -4371,12 +4395,12 @@
},
"tiles/plain_s":
{
"frame": {
"x": 1679,
"y": 1050,
"w": 128,
"h": 64
},
"frame": {
"x": 1915,
"y": 1050,
"w": 128,
"h": 64
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":128,"h":64},
@ -4385,12 +4409,12 @@
},
"tiles/tile":
{
"frame": {
"x": 1807,
"y": 1050,
"w": 128,
"h": 114
},
"frame": {
"x": 2043,
"y": 1050,
"w": 128,
"h": 114
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":128,"h":114},
@ -4399,12 +4423,12 @@
},
"tiles/wall":
{
"frame": {
"x": 1935,
"y": 1050,
"w": 128,
"h": 103
},
"frame": {
"x": 2171,
"y": 1050,
"w": 128,
"h": 103
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":128,"h":103},
@ -4413,12 +4437,12 @@
},
"tiles/wall_s":
{
"frame": {
"x": 2063,
"y": 1050,
"w": 128,
"h": 103
},
"frame": {
"x": 2299,
"y": 1050,
"w": 128,
"h": 103
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":128,"h":103},
@ -4427,12 +4451,12 @@
},
"ui/arrow_east":
{
"frame": {
"x": 2191,
"y": 1050,
"w": 102,
"h": 51
},
"frame": {
"x": 2427,
"y": 1050,
"w": 102,
"h": 51
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":102,"h":51},
@ -4441,12 +4465,12 @@
},
"ui/arrow_east_s":
{
"frame": {
"x": 2293,
"y": 1050,
"w": 102,
"h": 51
},
"frame": {
"x": 2529,
"y": 1050,
"w": 102,
"h": 51
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":102,"h":51},
@ -4455,12 +4479,12 @@
},
"ui/arrow_north":
{
"frame": {
"x": 2395,
"y": 1050,
"w": 102,
"h": 51
},
"frame": {
"x": 2631,
"y": 1050,
"w": 102,
"h": 51
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":102,"h":51},
@ -4469,12 +4493,12 @@
},
"ui/arrow_north_s":
{
"frame": {
"x": 2497,
"y": 1050,
"w": 102,
"h": 51
},
"frame": {
"x": 2733,
"y": 1050,
"w": 102,
"h": 51
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":102,"h":51},
@ -4483,12 +4507,12 @@
},
"ui/arrow_south":
{
"frame": {
"x": 2599,
"y": 1050,
"w": 102,
"h": 51
},
"frame": {
"x": 2835,
"y": 1050,
"w": 102,
"h": 51
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":102,"h":51},
@ -4497,12 +4521,12 @@
},
"ui/arrow_south_s":
{
"frame": {
"x": 2701,
"y": 1050,
"w": 102,
"h": 51
},
"frame": {
"x": 2937,
"y": 1050,
"w": 102,
"h": 51
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":102,"h":51},
@ -4511,12 +4535,12 @@
},
"ui/arrow_west":
{
"frame": {
"x": 2803,
"y": 1050,
"w": 102,
"h": 51
},
"frame": {
"x": 3039,
"y": 1050,
"w": 102,
"h": 51
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":102,"h":51},
@ -4525,28 +4549,52 @@
},
"ui/arrow_west_s":
{
"frame": {
"x": 2905,
"y": 1050,
"w": 102,
"h": 51
},
"frame": {
"x": 3141,
"y": 1050,
"w": 102,
"h": 51
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":102,"h":51},
"sourceSize": {"w":102,"h":51},
"pivot": {"x":0.5,"y":0.5}
},
"ui/compass": {
"frame": {
"x": 3243,
"y": 1050,
"w": 162,
"h": 147
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 162,
"h": 147
},
"sourceSize": {
"w": 162,
"h": 147
},
"pivot": {
"x": 0.5,
"y": 0.5
}
}},
"meta": {
"app": "http://www.codeandweb.com/texturepacker",
"version": "1.0",
"image": "sprites.png",
"format": "RGBA8888",
"size": {
"w": 3968,
"h": 1260
},
"size": {
"w": 3968,
"h": 1287
},
"scale": "1",
"smartupdate": "$TexturePacker:SmartUpdate:9033aea0c9a897c0ef813d508f6a34d4:37c604a593bacba7edbc1e4826db2c6e:1eabdf11f75e3a4fe3147baf7b5be24b$"
"smartupdate": "$TexturePacker:SmartUpdate:2412f7b54f5052f26d527831b1731f90:0555c9ab081ab700e85a408b539476a7:1eabdf11f75e3a4fe3147baf7b5be24b$"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 589 KiB

After

Width:  |  Height:  |  Size: 597 KiB

19
mar/tsconfig.json Normal file
View File

@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "es5",
"outFile": "./app.js"
},
"exclude": [
"node_modules"
],
"files": [
"phaser.d.ts",
"phaser.plugin.isometric.d.ts",
"MarGame.ts",
"mar.ts",
"GameClient.ts",
"GameObject.ts",
"World.ts",
"Console.ts"
]
}

View File

@ -26,7 +26,7 @@ $user = SessionManager::get();
@font-face {
font-family: 'fixedsys';
src: url("./mar/fonts/FSEX301-L2.ttf");
src: url("assets/fonts/FSEX301-L2.ttf");
}
</style>