Best JavaScript code snippet using playwright-internal
app.js
Source:app.js
1var Helper;2(function (Helper) {3 "use strict";4 /**5 * A class to define constants used throughout WebLogo6 */7 class Constants {8 }9 // These are used as keys in the Compiler's mainDict10 Constants.COLLISIONS = "Collisions";11 Constants.PROCEDURES = "Procedures";12 Constants.EVERYONE = "Everyone";13 Constants.WORLD = "The World";14 Constants.MAPSIZE = 50.5;15 Constants.MAPCEILING = 50;16 ////////////////////Agent Information:////////////////////////////17 Constants.DEFAULT_TRAIT_NAMES = new Set([18 "id", "breed", "x", "y", "z", "heading", "color", "shape", "size",19 ]);20 Constants.DEFAULT_TRAITS = [21 { "name": "x", "traitType": "data", "defaultValue": "0" },22 { "name": "y", "traitType": "data", "defaultValue": "0" },23 { "name": "z", "traitType": "data", "defaultValue": "0" },24 { "name": "heading", "traitType": "data", "defaultValue": "0" },25 { "name": "color", "traitType": "data", "defaultValue": "#ff0000" },26 { "name": "shape", "traitType": "data", "defaultValue": "cube" },27 { "name": "size", "traitType": "data", "defaultValue": "1" },28 ];29 Constants.AST_DONE = -1;30 Constants.AST_YIELD = -2;31 Constants.AST_YIELD_REPEAT = -3;32 Constants.AST_YIELD_REPEAT_NO_BRANCH = -4;33 Constants.AST_REPEAT = -5;34 Constants.AST_PROC_CALL = -6;35 Constants.AST_PROC_RET = -7;36 Constants.YIELD_NORMAL = "YIELD NORMAL";37 Constants.YIELD_INTERRUPT = "YIELD INTERRUPT";38 Constants.LIST_BEGINNING = 0;39 Constants.LIST_END = 1;40 Constants.LIST_INDEX = 2;41 Constants.THREAD_RUN_NOCHECK = 0;42 Constants.THREAD_RUN_IFOK = 1;43 Helper.Constants = Constants;44})(Helper || (Helper = {}));45/// <reference path="../Helper/Constants.ts" />46var Common;47(function (Common) {48 "use strict";49})(Common || (Common = {}));50var Common;51(function (Common) {52 "use strict";53 class Trait {54 constructor(id, name, dataType, defaultValue) {55 this.id = id;56 this.name = name;57 this.dataType = dataType;58 this.defaultValue = defaultValue;59 }60 }61 Common.Trait = Trait;62})(Common || (Common = {}));63/// <reference path="Trait.ts" />64var Common;65(function (Common) {66 "use strict";67 var Trait = Common.Trait;68 class Breed {69 constructor(name, shape) {70 this.traits = new Array();71 this.customTraits = new Array();72 this.traitIDBase = 0;73 this.namedTraits = new Map();74 this.id = Breed.idBase++;75 this.name = name;76 this.shape = shape || "cube";77 }78 getReadableTraits() {79 var readableTraits = ["id", "breed", "x", "y", "z", "heading", "color", "shape", "size"];80 for (var i = 0; i < this.traits.length; i++) {81 if (this.traits[i] !== undefined) {82 readableTraits.push(this.traits[i].name);83 }84 }85 return readableTraits;86 }87 getChangeableTraits() {88 var changeableTraits = [];89 // the World's built-in traits can't be modified90 // (change this if some eventually can be!)91 if (this.name != Helper.Constants.WORLD) {92 changeableTraits = ["x", "y", "z", "heading", "color", "shape", "size"];93 }94 for (var i = 0; i < this.traits.length; i++) {95 if (this.traits[i] !== undefined) {96 changeableTraits.push(this.traits[i].name);97 }98 }99 return changeableTraits;100 }101 getCustomTraits() {102 var customTraits = [];103 for (var i = 0; i < this.traits.length; i++) {104 if (this.traits[i] !== undefined) {105 customTraits.push(this.traits[i].name);106 }107 }108 return customTraits;109 }110 getTraitID(name) {111 return this.namedTraits.get(name).id;112 }113 addTrait(name, dataType, defaultValue) {114 if (this.namedTraits.has(name)) {115 return false;116 }117 var trait = new Trait(this.traitIDBase++, name, dataType, defaultValue);118 this.namedTraits.set(trait.name, trait);119 this.traits[trait.id] = trait;120 this.customTraits[trait.id] = trait;121 return true;122 }123 renameTrait(oldName, newName, defaultValue) {124 if (!this.namedTraits.has(oldName) || this.namedTraits.has(newName)) {125 return false;126 }127 var trait = this.namedTraits.get(oldName);128 trait.name = newName;129 if (defaultValue) {130 trait.defaultValue = defaultValue;131 }132 return true;133 }134 removeTrait(name) {135 if (!this.namedTraits.has(name)) {136 return false;137 }138 var trait = this.namedTraits.get(name);139 this.namedTraits.delete(name);140 delete (this.traits[trait.id]);141 delete (this.customTraits[trait.id]);142 return true;143 }144 }145 Breed.idBase = 0;146 Common.Breed = Breed;147})(Common || (Common = {}));148var Execution;149(function (Execution) {150 "use strict";151 class AgentState {152 constructor(x, y, z, heading, color, size, shape) {153 this.x = x || 0;154 this.y = y || 0;155 this.z = z || 0;156 this.heading = heading || 0;157 this.color = (color === undefined) ? 0xffffff : color;158 this.size = (size === undefined) ? 1 : size;159 this.shape = (shape === undefined) ? "cube" : shape;160 }161 copy() {162 return new Execution.AgentState(this.x, this.y, this.z, this.heading, this.color, this.size, this.shape);163 }164 copyFrom(state) {165 this.x = state.x;166 this.y = state.y;167 this.z = state.z;168 this.heading = state.heading;169 this.color = state.color;170 this.size = state.size;171 this.shape = state.shape;172 }173 }174 Execution.AgentState = AgentState;175})(Execution || (Execution = {}));176/// <reference path="../Common/Agent.ts" />177var DataStructures;178(function (DataStructures) {179 "use strict";180 class Bin {181 constructor(minX, maxX, minY, maxY, id) {182 /**183 * All the agents in the bin184 * NOTE: should this be replaced with a weak-reference dictionary185 * so that any agents that are removed elsewhere will automatically disappear?186 */187 this.contents = new Set();188 this.xMin = minX;189 this.xMax = maxX;190 this.yMin = minY;191 this.yMax = maxY;192 this.xMid = (this.xMin + this.xMax) / 2;193 this.yMid = (this.yMin + this.yMax) / 2;194 this.xWidth = this.xMax - this.xMin;195 this.yHeight = this.yMax - this.yMin;196 this.id = id;197 }198 /**199 * Puts an agent in a bin.200 * Returns true if the agent was successfully added,201 * false, if the agent does not belong in this bin202 */203 insert(agent) {204 this.contents.add(agent);205 return true;206 }207 remove(agent) {208 this.contents.delete(agent);209 }210 }211 DataStructures.Bin = Bin;212})(DataStructures || (DataStructures = {}));213/// <reference path="../Common/Thread.ts" />214/// <reference path="../Common/Breed.ts" />215/// <reference path="../Execution/AgentState.ts" />216/// <reference path="../DataStructures/Bin.ts" />217var Common;218(function (Common) {219 "use strict";220})(Common || (Common = {}));221var Helper;222(function (Helper) {223 "use strict";224 class Comparison {225 static equals(a, b) {226 var EPSILON = Number(0.000000001);227 if (a === b) {228 return true;229 }230 else if (!isNaN(Number(a)) && !isNaN(Number(b))) {231 if (Math.abs(Number(a) - Number(b)) <= EPSILON) {232 return true;233 }234 else {235 return false;236 }237 }238 else if (String(a) === String(b)) {239 return true;240 }241 else if (a !== undefined && a.hasOwnProperty("equals") && a.equals(b)) {242 return true;243 }244 else if (b !== undefined && b.hasOwnProperty("equals") && b.equals(a)) {245 return true;246 }247 else {248 return false;249 }250 }251 static lt(a, b) {252 var n1 = Number(a);253 var n2 = Number(b);254 if (isNaN(n1) || isNaN(n2)) {255 return String(a) < String(b);256 }257 else {258 return n1 < n2;259 }260 }261 static lte(a, b) {262 var n1 = Number(a);263 var n2 = Number(b);264 if (isNaN(n1) || isNaN(n2)) {265 return (String(a) <= String(b)) || Helper.Comparison.equals(a, b);266 }267 else {268 return n1 <= n2;269 }270 }271 static gt(a, b) {272 var n1 = Number(a);273 var n2 = Number(b);274 if (isNaN(n1) || isNaN(n2)) {275 return String(a) > String(b);276 }277 else {278 return n1 > n2;279 }280 }281 static gte(a, b) {282 var n1 = Number(a);283 var n2 = Number(b);284 if (isNaN(n1) || isNaN(n2)) {285 return (String(a) >= String(b)) || Helper.Comparison.equals(a, b);286 }287 else {288 return n1 >= n2;289 }290 }291 }292 Helper.Comparison = Comparison;293})(Helper || (Helper = {}));294/// <reference path="../Common/Agent.ts" />295/// <reference path="../Common/Thread.ts" />296/// <reference path="Comparison.ts" />297/// <reference path="Constants.ts" />298var Helper;299(function (Helper) {300 "use strict";301 var Comparison = Helper.Comparison;302 var Constants = Helper.Constants;303 class Utils {304 static init() {305 for (var i = 0; i < Utils.tableLength; i++) {306 Utils.sinTable[i] = Math.sin(2 * Math.PI * i / Utils.tableLength);307 Utils.cosTable[i] = Math.cos(2 * Math.PI * i / Utils.tableLength);308 }309 }310 static fastCos(d) {311 return Utils.cosTable[Math.round(d * 100)];312 }313 static fastSin(d) {314 return Utils.sinTable[Math.round(d * 100)];315 }316 // hash fn from http://stackoverflow.com/a/7616484317 // effectively computes Java's String.hashCode318 static hash(str) {319 var hash = 0;320 if (str.length === 0) {321 return hash;322 }323 for (var i = 0; i < str.length; i++) {324 var chr = str.charCodeAt(i);325 /* tslint:disable no-bitwise */326 hash = ((hash << 5) - hash) + chr;327 hash |= 0; // Convert to 32bit integer328 }329 return hash;330 }331 static getTrait(a, t) {332 if (a === undefined || !a.isAgent) {333 return undefined;334 }335 else {336 return a.getTrait(t);337 }338 }339 static isNumeric(n) {340 return !isNaN(parseFloat(n)) && isFinite(n);341 }342 static random() {343 // return Math.random();344 // deterministic prng for testing: http://stackoverflow.com/a/19303725345 var x = Math.sin(Utils.randomSeed++) * 10000;346 return x - Math.floor(x);347 }348 static randomInteger(lower, upper) {349 return Math.floor((Utils.random() * (upper + 1 - lower)) + lower);350 }351 static round(num, places) {352 var base = Math.pow(10, places);353 return Math.round(num * base) / base;354 }355 static maxmin(name, a, b) {356 if (name === "larger of") {357 return Math.max(a, b);358 }359 else {360 return Math.min(a, b);361 }362 }363 static trig(name, x) {364 switch (name) {365 case "cos": return Math.cos(x * Math.PI / 180);366 case "sin": return Math.sin(x * Math.PI / 180);367 case "tan": return Math.tan(x * Math.PI / 180);368 case "arccos": return Math.acos(x) * 180 / Math.PI;369 case "arcsin": return Math.asin(x) * 180 / Math.PI;370 case "arctan": return Math.atan(x) * 180 / Math.PI;371 default: {372 throw new Error(`Unexpected trig function name: ${name}`);373 }374 }375 }376 static limit(n, lower, upper) {377 return Math.max(lower, Math.min(upper, n));378 }379 static listContains(haystack, needle) {380 if (haystack.indexOf(needle) !== -1) {381 return true;382 }383 else {384 for (var candidate of haystack) {385 if (Comparison.equals(needle, candidate)) {386 return true;387 }388 }389 return false;390 }391 }392 static listSplice(mode, index, toInsert, listInto) {393 if (mode === Constants.LIST_BEGINNING) {394 return toInsert.concat(listInto);395 }396 else if (mode === Constants.LIST_END) {397 return listInto.concat(toInsert);398 }399 else {400 var firstPartInto = listInto;401 var lastPartInto = firstPartInto.splice(index);402 var newList = firstPartInto.concat(toInsert);403 return newList.concat(lastPartInto);404 }405 }406 static listInsert(mode, index, item, list) {407 if (mode === Constants.LIST_BEGINNING) {408 list.splice(0, 0, item);409 }410 else if (mode === Constants.LIST_END) {411 list.splice(list.length, 0, item);412 }413 else {414 list.splice(index, 0, item);415 }416 return list;417 }418 static isValidDataType(dataType) {419 return (dataType === "data" || dataType === "agent" || dataType === "list");420 }421 static toColor(input) {422 if (input === "random_color") {423 return Utils.random() * 0xFFFFFF;424 }425 else {426 return Number(input);427 }428 }429 static guessType(input) {430 if (isNaN(Number(input))) {431 return input;432 }433 else {434 return Number(input);435 }436 }437 static isGeneratorSupported() {438 // http://stackoverflow.com/a/24966392439 /* tslint:disable no-eval */440 try {441 eval("(function*(){})()");442 return true;443 }444 catch (_) {445 return false;446 }447 /* tslint:enable no-eval */448 }449 }450 Utils.tableLength = 36000;451 Utils.sinTable = new Array(Utils.tableLength);452 Utils.cosTable = new Array(Utils.tableLength);453 Utils.randomSeed = 0;454 Helper.Utils = Utils;455})(Helper || (Helper = {}));456/// <reference path="../Helper/Utils.ts" />457/// <reference path="Agent.ts" />458/// <reference path="Thread.ts" />459var Common;460(function (Common) {461 "use strict";462})(Common || (Common = {}));463/// <reference path="../Helper/Utils.ts" />464/// <reference path="ASTNode.ts" />465/// <reference path="Breed.ts" />466var Common;467(function (Common) {468 "use strict";469 class State {470 static reset(hard) {471 Common.State.runnable = false;472 Common.State.collisionsLastRun = false;473 Common.State.pushedButtons.clear();474 Common.State.toggledButtons.clear();475 Common.State.pushButtonRunning.clear();476 Common.State.buttonMap = new Array();477 Common.State.procedureRoots = new Map();478 Common.State.procedureGenerators = new Map();479 Common.State.procedureFunctions = new Map();480 Common.State.collisionsOn = false;481 Common.State.binningOn = false;482 Common.State.collisionDict = new Map();483 Common.State.collisionFunctions = new Map();484 Common.State.collidingBreeds = new Set();485 Common.State.collidedBreeds = new Map();486 Common.State.jsGenerators = new Map();487 Common.State.jsFunctions = new Map();488 Common.State.jsBtnNames = new Map();489 Common.State.variables = new Map();490 if (hard) {491 Common.State.clock = 0;492 Common.State.lastRunTime = (new Date()).getTime();493 }494 }495 }496 State.isTest = false;497 State.iterationLimit = 10000;498 State.runnable = false;499 State.collisionsLastRun = false;500 State.pushedButtons = new Set();501 State.toggledButtons = new Set();502 State.pushButtonRunning = new Map();503 State.buttonMap = new Array();504 /** This dictionary stores the locations of each procedure list and logic sublist505 * in the procedureList506 */507 State.procedureRoots = new Map();508 State.procedureGenerators = new Map();509 State.procedureFunctions = new Map();510 // The collisionDict stores the IASTNodes associated with each collision block.511 State.collisionsOn = false;512 State.binningOn = false;513 State.collisionDict = new Map();514 State.collisionFunctions = new Map();515 State.collidingBreeds = new Set();516 State.collidedBreeds = new Map();517 State.jsGenerators = new Map();518 State.jsFunctions = new Map();519 State.jsBtnNames = new Map();520 State.clock = 0;521 State.lastRunTime = (new Date()).getTime();522 State.hasSmell = false;523 // Map of variable name to the initial value524 State.variables = new Map();525 Common.State = State;526})(Common || (Common = {}));527var DataStructures;528(function (DataStructures) {529 "use strict";530 class BlockPacket {531 /**532 * BlockPacket stores the information read from the JavaScript533 * to create a block in ActionScript534 * @param name:String the name of the block535 * @param id:int the JS ID of the block536 * @param label:String the label of the block, null if block is uneditable537 */538 constructor(name, id, label) {539 this.name = name;540 this.id = id;541 this.label = label;542 }543 getName() {544 return this.name;545 }546 getID() {547 return this.id;548 }549 /**550 * @returns the label of an editable block, e.g. the number typed in a number block551 */552 getLabel() {553 return this.label;554 }555 }556 DataStructures.BlockPacket = BlockPacket;557})(DataStructures || (DataStructures = {}));558var Helper;559(function (Helper) {560 "use strict";561 class Logger {562 static enable() {563 Helper.Logger.enabled = true;564 }565 static disable() {566 Helper.Logger.enabled = false;567 }568 static log(output) {569 if (Helper.Logger.enabled) {570 console.log(output);571 }572 }573 static mustLog(output) {574 console.log(output);575 Helper.Logger.lastBlockPrint = output;576 Helper.Logger.allPrinted.push(output);577 }578 static debug(output) {579 console.debug(output);580 }581 static error(output) {582 console.error(output);583 }584 static assert(test) {585 console.assert(test);586 }587 }588 Logger.allPrinted = new Array();589 Logger.enabled = false;590 Helper.Logger = Logger;591})(Helper || (Helper = {}));592/// <reference path="../../Common/Agent.ts" />593/// <reference path="../../Common/Thread.ts" />594/// <reference path="../../Helper/Logger.ts" />595/// <reference path="../../Helper/Utils.ts" />596var Execution;597(function (Execution) {598 var Threads;599 (function (Threads) {600 "use strict";601 var Logger = Helper.Logger;602 class FunctionRepeatThread {603 constructor(agent, buttonName, fun) {604 this.yielded = false;605 this.agent = agent;606 this.buttonName = buttonName;607 this.fun = fun;608 this.scope = new Map();609 }610 step() {611 // Logger.log(`Stepping through thread ${this} of agent ${this.agent}`);612 this.fun(this.agent, this);613 return false;614 }615 restart() {616 // Logger.log(`Restarting thread ${this} for agent ${this.agent}`);617 }618 }619 Threads.FunctionRepeatThread = FunctionRepeatThread;620 })(Threads = Execution.Threads || (Execution.Threads = {}));621})(Execution || (Execution = {}));622/// <reference path="../../Common/Agent.ts" />623/// <reference path="../../Common/State.ts" />624/// <reference path="../../Common/Thread.ts" />625/// <reference path="../../Helper/Logger.ts" />626/// <reference path="../../Helper/Utils.ts" />627var Execution;628(function (Execution) {629 var Threads;630 (function (Threads) {631 "use strict";632 var Logger = Helper.Logger;633 var State = Common.State;634 class GeneratorRepeatThread {635 constructor(agent, buttonName, genFunc) {636 this.yielded = false;637 this.buttonName = buttonName;638 this.agent = agent;639 this.scope = new Map();640 this.genFunc = genFunc;641 this.gen = genFunc(agent, this);642 }643 step() {644 // Logger.log(`Stepping through thread ${this} of agent ${this.agent}`);645 var out = this.gen[Symbol.iterator]().next();646 // Logger.log(`done: ${out.done}, value: ${out.value}`);647 if (out.done) {648 this.gen = this.genFunc(this.agent, this);649 this.yielded = false;650 }651 else {652 this.yielded = true;653 State.pushButtonRunning.set(this.buttonName, true);654 }655 return false;656 }657 restart() {658 this.gen = this.genFunc(this.agent, this);659 this.yielded = false;660 }661 }662 Threads.GeneratorRepeatThread = GeneratorRepeatThread;663 })(Threads = Execution.Threads || (Execution.Threads = {}));664})(Execution || (Execution = {}));665/// <reference path="../../Common/Agent.ts" />666/// <reference path="../../Helper/Utils.ts" />667var Execution;668(function (Execution) {669 var Threads;670 (function (Threads) {671 "use strict";672 class CollisionThread {673 constructor(agent, genFunc, collidee) {674 this.yielded = true;675 this.buttonName = "__wl_collision";676 this.scope = new Map();677 this.agent = agent;678 this.collidee = collidee;679 this.gen = genFunc(agent, this);680 }681 step() {682 this.agent.collidee = this.collidee;683 var out = this.gen[Symbol.iterator]().next();684 this.agent.collidee = undefined;685 return out.done;686 }687 }688 Threads.CollisionThread = CollisionThread;689 })(Threads = Execution.Threads || (Execution.Threads = {}));690})(Execution || (Execution = {}));691/// <reference path="../Common/Agent.ts" />692/// <reference path="../Common/ASTNode.ts" />693/// <reference path="../Common/Thread.ts" />694/// <reference path="../Common/State.ts" />695/// <reference path="../Execution/Threads/FunctionRepeatThread.ts" />696/// <reference path="../Execution/Threads/GeneratorRepeatThread.ts" />697/// <reference path="../Execution/Threads/CollisionThread.ts" />698/// <reference path="../Helper/Constants.ts" />699/// <reference path="../Helper/Logger.ts" />700/// <reference path="../Helper/Utils.ts" />701var DataStructures;702(function (DataStructures) {703 "use strict";704 var State = Common.State;705 var CollisionThread = Execution.Threads.CollisionThread;706 var Constants = Helper.Constants;707 var Logger = Helper.Logger;708 var Utils = Helper.Utils;709 class ASTList {710 constructor(n) {711 this.data = new Array(n || 0);712 }713 setup() {714 for (var idx = 0; idx < this.data.length; idx++) {715 var node = this[idx];716 if (node === undefined) {717 this[idx] = new UtilEvalData("", true);718 }719 else {720 node.setup();721 }722 }723 }724 check(lists, nodes) {725 // Logger.assert(!lists.has(this));726 for (var node of this.data) {727 node.check(lists, nodes);728 }729 }730 can_yield(procs) {731 for (var node of this.data) {732 if (node !== undefined && node.can_yield(procs)) {733 return true;734 }735 }736 return false;737 }738 to_js() {739 var statements = new Array();740 for (var node of this.data) {741 if (node.can_yield(new Set())) {742 statements.push(node.to_js_setup());743 statements.push(node.to_js_final());744 }745 else {746 statements.push(node.to_js_no_yield());747 }748 }749 return statements.join(";\n") + ";";750 }751 }752 DataStructures.ASTList = ASTList;753 class ASTNode {754 constructor(numArgs, numBranches) {755 this.id = ++ASTNode.idBase;756 this.numArgs = numArgs;757 this.numBranches = numBranches;758 this.args = new ASTList(numArgs);759 this.branches = new Array(numBranches);760 for (var i = 0; i < numBranches; i++) {761 this.branches[i] = new ASTList(0);762 }763 }764 can_yield(procs) {765 if (!State.generatorSupported) {766 return false;767 }768 if (this.args.can_yield(procs)) {769 return true;770 }771 for (var branch of this.branches) {772 if (branch.can_yield(procs)) {773 return true;774 }775 }776 return false;777 }778 // rets is an array of length 2 [retval, retcode]779 // retval is the return value of the function (undefined if the function is void)780 // if retcode >= 0, we run the (retcode)th branch781 // if retcode == Constants.AST_REPEAT (-1), we rerun this function (useful for looping)782 // if retcode == Constants.AST_SLEEP (-2), we put this function to sleep783 fn(a, scope, args, rets) {784 throw new Error("unimplemented fn for ${this.constructor.name}");785 }786 ;787 to_js_no_yield() {788 throw new Error(`unimplemented to_js_no_yield for ${this.constructor.name}`);789 }790 to_js_setup() {791 throw new Error(`unimplemented to_js_setup for ${this.constructor.name}`);792 }793 to_js_final() {794 throw new Error(`unimplemented to_js_final for ${this.constructor.name}`);795 }796 setup() {797 this.args.setup();798 for (var branch of this.branches) {799 branch.setup();800 }801 }802 check(lists, nodes) {803 if (lists === undefined) {804 lists = new Set();805 }806 if (nodes === undefined) {807 nodes = new Set();808 }809 // Logger.assert(this.numArgs === this.args.data.length);810 // Logger.assert(this.numBranches === this.branches.length);811 // Logger.assert(!nodes.has(this));812 this.args.check(lists, nodes);813 for (var branch of this.branches) {814 branch.check(lists, nodes);815 }816 }817 make_collision_thread(a, b) {818 // Logger.assert(this.yields === true);819 return new CollisionThread(a, State.jsGenerators.get(this), b);820 }821 make_function() {822 var f;823 /* tslint:disable no-eval */824 eval(`f = function(__wl_agt, __wl_thd){ ${this.to_js_no_yield()};}`);825 /* tslint:enable no-eval */826 return f;827 }828 make_generator() {829 var g;830 /* tslint:disable no-eval */831 eval(`g = function*(__wl_agt, __wl_thd){ ${this.to_js_setup()}; ${this.to_js_final()};}`);832 /* tslint:enable no-eval */833 return g;834 }835 }836 ASTNode.state = new Map();837 ASTNode.idBase = 0;838 DataStructures.ASTNode = ASTNode;839 class UtilEvalData extends ASTNode {840 constructor(data, error) {841 super(0, 0); // numArgs = 0, numBranches = 0842 this.data = data;843 this.error = error;844 }845 fn(a, scope, args, rets) {846 if (this.error) {847 Logger.error("Empty socket");848 }849 rets[0] = this.data;850 rets[1] = Constants.AST_DONE;851 }852 to_js_no_yield() {853 if (Utils.isNumeric(this.data)) {854 return `${Number(this.data)}`;855 }856 else {857 return `"${this.data}"`;858 }859 }860 to_js_setup() {861 return "";862 }863 to_js_final() {864 if (Utils.isNumeric(this.data)) {865 return `${Number(this.data)}`;866 }867 else {868 return `"${this.data}"`;869 }870 }871 getData() {872 if (Utils.isNumeric(this.data)) {873 return Number(this.data);874 }875 else {876 return this.data;877 }878 }879 }880 DataStructures.UtilEvalData = UtilEvalData;881})(DataStructures || (DataStructures = {}));882/// <reference path="../../Common/Agent.ts" />883/// <reference path="../../Common/State.ts" />884/// <reference path="../../Common/Thread.ts" />885/// <reference path="../../Helper/Logger.ts" />886var Execution;887(function (Execution) {888 var Threads;889 (function (Threads) {890 "use strict";891 var State = Common.State;892 var Logger = Helper.Logger;893 class SetupThread {894 constructor(agent, genFunc, parentThread) {895 this.yielded = true;896 this.buttonName = "__wl_setup";897 this.buttonName = parentThread.buttonName;898 this.gen = genFunc(agent, this);899 this.agent = agent;900 this.scope = parentThread.scope;901 }902 step() {903 // Logger.log(`Stepping through setup thread ${this} of agent ${this.agent}`);904 var out = this.gen[Symbol.iterator]().next();905 if (!out.done) {906 State.pushButtonRunning.set(this.buttonName, true);907 }908 // Logger.log(`done: ${out.done}, value: ${out.value}`);909 return out.done;910 }911 }912 Threads.SetupThread = SetupThread;913 })(Threads = Execution.Threads || (Execution.Threads = {}));914})(Execution || (Execution = {}));915/// <reference path="../../Common/Thread.ts" />916var Execution;917(function (Execution) {918 var Threads;919 (function (Threads) {920 "use strict";921 class SingleFunctionThread {922 constructor(parentThread) {923 this.yielded = false;924 if (parentThread !== undefined) {925 this.buttonName = parentThread.buttonName;926 this.scope = parentThread.scope;927 }928 }929 step() {930 throw new Error("unimplemented");931 }932 }933 Threads.SingleFunctionThread = SingleFunctionThread;934 })(Threads = Execution.Threads || (Execution.Threads = {}));935})(Execution || (Execution = {}));936/// <reference path="../DataStructures/AST.ts" />937/// <reference path="../Execution/Threads/SetupThread.ts" />938/// <reference path="../Execution/Threads/SingleFunctionThread.ts" />939/// <reference path="../Execution/AgentState.ts" />940/// <reference path="../Common/Agent.ts" />941/// <reference path="../Common/Thread.ts" />942/// <reference path="../Common/Breed.ts" />943/// <reference path="../Common/Trait.ts" />944/// <reference path="../Helper/Constants.ts" />945/// <reference path="../Helper/Utils.ts" />946var Execution;947(function (Execution) {948 "use strict";949 var Breed = Common.Breed;950 var SetupThread = Execution.Threads.SetupThread;951 var SingleFunctionThread = Execution.Threads.SingleFunctionThread;952 var Constants = Helper.Constants;953 class AgentController {954 constructor() {955 throw new Error("Cannot instantiate static class");956 }957 static insert(agent) {958 var index = Execution.AgentController.numAgents;959 if (Execution.AgentController.numAgents >= Execution.AgentController.data.length) {960 Execution.AgentController.data.length *= 2;961 Execution.AgentController.states.length *= 2;962 Execution.AgentController.prevStates.length *= 2;963 }964 Execution.AgentController.breedList[agent.breed.id].add(agent);965 Execution.AgentController.data[index] = agent;966 Execution.AgentController.states[index] = agent.state;967 Execution.AgentController.prevStates[index] = agent.prevState;968 Execution.AgentController.indexMap.set(agent, index);969 Execution.AgentController.numAgents++;970 }971 static spawn(a, n, b, t, g) {972 var interval = 360. / n;973 for (var i = 0; i < n; i++) {974 var child = a.clone(b);975 child.safeSetHeading(i * interval);976 child.prevState.heading = child.state.heading;977 if (g) {978 var childThread = new SetupThread(child, g, t);979 var done = childThread.step();980 if (!done) {981 child.jsthreads.push(childThread);982 }983 }984 child.updateBin();985 }986 }987 static spawn_fun(a, n, b, t, f) {988 var interval = 360. / n;989 var sft = new SingleFunctionThread(t);990 for (var i = 0; i < n; i++) {991 var child = a.clone(b);992 child.state.heading += i * interval;993 child.prevState.heading = child.state.heading;994 if (f !== undefined) {995 f(child, sft);996 }997 child.updateBin();998 }999 }1000 static remove(agent) {1001 Execution.AgentController.deadAgents.push(agent);1002 Execution.Collisions.remove(agent);1003 }1004 static clearDead() {1005 /* tslint:disable no-var-keyword */1006 for (var i = 0; i < Execution.AgentController.deadAgents.length; i++) {1007 var agent = Execution.AgentController.deadAgents[i];1008 /* tslint:disable no-var-keyword */1009 var index = Execution.AgentController.indexMap.get(agent);1010 var lastIndex = Execution.AgentController.numAgents - 1;1011 var lastAgent = Execution.AgentController.data[lastIndex];1012 if (index !== lastIndex) {1013 Execution.AgentController.indexMap.set(lastAgent, index);1014 Execution.AgentController.data[index] = lastAgent;1015 Execution.AgentController.states[index] = lastAgent.state;1016 Execution.AgentController.prevStates[index] = lastAgent.prevState;1017 }1018 Execution.AgentController.data[lastIndex] = undefined;1019 Execution.AgentController.states[lastIndex] = undefined;1020 Execution.AgentController.prevStates[lastIndex] = undefined;1021 Execution.AgentController.indexMap.delete(agent);1022 var breedList = Execution.AgentController.breedList[agent.breed.id];1023 breedList.delete(agent);1024 Execution.AgentController.numAgents--;1025 }1026 Execution.AgentController.deadAgents = new Array();1027 if (Execution.AgentController.numAgents <= Execution.AgentController.data.length / 2 && Execution.AgentController.numAgents > 1024) {1028 Execution.AgentController.data.length /= 2;1029 Execution.AgentController.states.length /= 2;1030 Execution.AgentController.prevStates.length /= 2;1031 }1032 }1033 static reset(hard) {1034 Execution.Collisions.reset();1035 Execution.AgentController.data = new Array(1024);1036 Execution.AgentController.states.splice(1);1037 Execution.AgentController.states.length = 1024;1038 Execution.AgentController.prevStates.splice(1);1039 Execution.AgentController.prevStates.length = 1024;1040 Execution.AgentController.numAgents = 1;1041 Execution.AgentController.worldInstance.jsthreads = [];1042 Execution.AgentController.data[0] = Execution.AgentController.worldInstance;1043 Execution.AgentController.states[0] = Execution.AgentController.worldInstance.state;1044 Execution.AgentController.prevStates[0] = Execution.AgentController.worldInstance.prevState;1045 if (hard) {1046 Execution.AgentController.breedList = [new Set(), new Set()];1047 Execution.AgentController.namedBreeds = new Map([1048 [Execution.AgentController.EVERYONE.name, Execution.AgentController.EVERYONE],1049 [Execution.AgentController.WORLD.name, Execution.AgentController.WORLD],1050 ]);1051 Execution.AgentController.breeds = new Map([1052 [Execution.AgentController.EVERYONE.id, Execution.AgentController.EVERYONE],1053 [Execution.AgentController.WORLD.id, Execution.AgentController.WORLD],1054 ]);1055 }1056 }1057 static getAllAgents(skipWorld, breed) {1058 if (breed !== undefined) {1059 if (Execution.AgentController.breedList[breed.id] !== undefined) {1060 return Array.from(Execution.AgentController.breedList[breed.id]);1061 }1062 else {1063 return [];1064 }1065 }1066 var allAgents = new Array();1067 var worldID = Execution.AgentController.worldInstance.id;1068 for (var i = 0, len = Execution.AgentController.data.length; i < len; i++) {1069 var agent = Execution.AgentController.data[i];1070 if (agent !== undefined) {1071 if (!skipWorld || agent.id !== worldID) {1072 allAgents.push(agent);1073 }1074 }1075 }1076 return allAgents;1077 }1078 static scatterAllAgents() {1079 for (var a of Execution.AgentController.getAllAgents(true)) {1080 a.scatter();1081 }1082 }1083 static getByName(name) {1084 return Execution.AgentController.namedBreeds.get(name);1085 }1086 static getBreeds() {1087 return Array.from(Execution.AgentController.namedBreeds.keys());1088 }1089 static getBreedIDs(includeAll) {1090 var breedIDs = Array.from(Execution.AgentController.breeds.keys());1091 if (!includeAll) {1092 breedIDs.splice(breedIDs.indexOf(Execution.AgentController.WORLD.id), 1);1093 breedIDs.splice(breedIDs.indexOf(Execution.AgentController.EVERYONE.id), 1);1094 }1095 return breedIDs;1096 }1097 static getReadableTraits(breedName) {1098 var breed = Execution.AgentController.getByName(breedName);1099 var traits = breed.getReadableTraits();1100 return traits;1101 }1102 static getChangeableTraits(breedName) {1103 var breed = Execution.AgentController.getByName(breedName);1104 var traits = breed.getChangeableTraits();1105 return traits;1106 }1107 static getCustomTraits(breedName) {1108 var breed = Execution.AgentController.getByName(breedName);1109 var traits = breed.getCustomTraits();1110 return traits;1111 }1112 // Adds a new trait to a breed, and all members of that breed1113 // @return true if the trait was added, false if the trait already existed or could not be added1114 static addTrait(breedName, trait, dataType, dv) {1115 var breed = Execution.AgentController.getByName(breedName);1116 var success = breed.addTrait(trait, dataType, dv);1117 if (success) {1118 var traitID = breed.getTraitID(trait);1119 for (var agent of Execution.AgentController.getAllAgents(false, breed)) {1120 agent.traits[traitID] = dv;1121 }1122 }1123 return success;1124 }1125 static renameTrait(breedName, oldName, newName, dv) {1126 var breed = Execution.AgentController.getByName(breedName);1127 return breed.renameTrait(oldName, newName, dv);1128 }1129 static removeTrait(breedName, trait) {1130 var breed = Execution.AgentController.getByName(breedName);1131 var traitID = breed.getTraitID(trait);1132 var success = breed.removeTrait(trait);1133 if (success) {1134 for (var agent of Execution.AgentController.getAllAgents(false, breed)) {1135 delete (agent.traits[traitID]);1136 }1137 }1138 return success;1139 }1140 static addBreed(breedName) {1141 if (breedName === "" || Execution.AgentController.namedBreeds.has(breedName)) {1142 return undefined;1143 }1144 var breed = new Breed(breedName);1145 Execution.AgentController.breeds.set(breed.id, breed);1146 Execution.AgentController.namedBreeds.set(breed.name, breed);1147 Execution.AgentController.breedList[breed.id] = new Set();1148 return breed.id;1149 }1150 // Rename the trait from oldName to newName, if possible1151 static renameBreed(oldName, newName) {1152 // only rename if the old breed exists and the new one doesn't yet1153 if (!Execution.AgentController.namedBreeds.has(oldName) || Execution.AgentController.namedBreeds.has(newName) || newName === "") {1154 return false;1155 }1156 var breed = Execution.AgentController.getByName(oldName);1157 Execution.AgentController.namedBreeds.delete(oldName);1158 breed.name = newName;1159 Execution.AgentController.namedBreeds.set(newName, breed);1160 return true;1161 }1162 // Attempts to remove the given breed from existence, including deleting1163 // all agents of the breed and all traits associated with it.1164 static removeBreed(breedName) {1165 if (!Execution.AgentController.namedBreeds.has(breedName)) {1166 return undefined;1167 }1168 var breed = Execution.AgentController.getByName(breedName);1169 for (var agent of Execution.AgentController.getAllAgents(false, breed)) {1170 agent.die();1171 }1172 Execution.AgentController.namedBreeds.delete(breed.name);1173 Execution.AgentController.breeds.delete(breed.id);1174 return breed.id;1175 }1176 }1177 AgentController.WORLD = new Breed(Constants.WORLD);1178 AgentController.EVERYONE = new Breed(Constants.EVERYONE);1179 AgentController.namedBreeds = new Map([1180 [AgentController.EVERYONE.name, AgentController.EVERYONE],1181 [AgentController.WORLD.name, AgentController.WORLD],1182 ]);1183 AgentController.breeds = new Map([1184 [AgentController.EVERYONE.id, AgentController.EVERYONE],1185 [AgentController.WORLD.id, AgentController.WORLD],1186 ]);1187 AgentController.breedList = [new Set(), new Set()];1188 AgentController.deadAgents = new Array();1189 AgentController.indexMap = new Map();1190 AgentController.numAgents = 0;1191 AgentController.data = new Array(1024);1192 AgentController.states = new Array(1024);1193 AgentController.prevStates = new Array(1024);1194 Execution.AgentController = AgentController;1195})(Execution || (Execution = {}));1196/// <reference path="../DataStructures/BlockPacket.ts" />1197var Common;1198(function (Common) {1199 "use strict";1200})(Common || (Common = {}));1201/// <reference path="../DataStructures/BlockPacket.ts" />1202/// <reference path="../Helper/Logger.ts" />1203/// <reference path="../Common/IWebLogo.ts" />1204var Compilation;1205(function (Compilation) {1206 "use strict";1207 var BlockPacket = DataStructures.BlockPacket;1208 var Logger = Helper.Logger;1209 class BlocksReader {1210 /**1211 * Returns the page names from the main application1212 */1213 static getPages() {1214 return Compilation.BlocksReader.app.appGetPages();1215 }1216 /**1217 * Returns the top block packets in the JS, i.e. packets of blocks without parents1218 * @returns A list of the top blocks, in BlockPacket form1219 */1220 static getTopBlocks() {1221 var blocks = new Array();1222 for (var packet of Compilation.BlocksReader.app.appGetTopBlocks()) {1223 blocks.push(packet);1224 }1225 return blocks;1226 }1227 /**1228 * Returns a list of all block packets with the given name1229 * @param blockName:String the block name to search for on the canvas1230 */1231 static getNamedBlocks(blockName) {1232 return Compilation.BlocksReader.app.appGetNamedBlocks(blockName);1233 }1234 /**1235 * Returns the child block of a given block at a given socket and position.1236 * @param blockID: Block the parent block1237 * @param socket: number which socket to look into1238 * @param socketIndex: number the position of the desired block in the given socket, defaults to 01239 * @param isOptional: Boolean defaults to false, but must be true if an argument can be undefined without error1240 * @returns Block the desired child block of the given parent block, or undefined if it doesn't exist1241 * @throws EmptySocketError if the requested socket is required, but undefined1242 */1243 static getSB(blockID, socket, isOptional, socketIndex) {1244 socketIndex = socketIndex || 0;1245 // Logger.log("Starting getSB. blockID: <${blockID}>; socket: <${socket}>; socketIndex: <${socketIndex}>");1246 var socketPacket = Compilation.BlocksReader.app.appGetSB(blockID, socket, socketIndex);1247 /*1248 IWebLogo.printToJSConsole("Name is " + socketPacket.getName())1249 IWebLogo.printToJSConsole("Label is " + socketPacket.getLabel())1250 IWebLogo.printToJSConsole("ID is " + socketPacket.getID())1251 */1252 if (socketPacket && socketPacket.getName() === "emptyCommand") {1253 // Logger.log("In the if");1254 var page = Compilation.BlocksReader.app.appGetPageName(blockID);1255 // Logger.log(`block: <${blockID}> socket: <${socket}> in page: <${page}>`);1256 // var e:EmptySocketError = new EmptySocketError(blockID, page);1257 // throw e;1258 return undefined;1259 }1260 else if (isOptional || socketPacket !== undefined) {1261 // Logger.log("In the else if");1262 return socketPacket;1263 }1264 else {1265 var page = Compilation.BlocksReader.app.appGetPageName(blockID);1266 // Logger.log("Testing page " + page);1267 if (page === undefined || page === "undefined" || !page) {1268 // Logger.log("In the if " + Compilation.BlocksReader.app.appGetCurrentPage());1269 page = Compilation.BlocksReader.app.appGetCurrentPage();1270 }1271 // Logger.log("page is now " + page);1272 /*let e:EmptySocketError = new EmptySocketError(blockID, page);1273 IWebLogo.printToJSConsole("block: " + blockID + " socket: " + socket + " in page: " + page);1274 throw e;*/1275 var blockName = Compilation.BlocksReader.app.appGetBlock(blockID).getName();1276 // Logger.log("In the else");1277 return new BlockPacket("error", -Number(String(blockID) + String(socket)), blockName + "$" + page);1278 }1279 }1280 /**1281 * Returns the number of sockets in a given block1282 * @param blockID: ID of the block searching for1283 */1284 static getSBLength(blockID) {1285 return Compilation.BlocksReader.app.appGetSBLength(blockID);1286 }1287 static getBlock(blockID) {1288 return Compilation.BlocksReader.app.appGetBlock(blockID);1289 }1290 /**1291 * Returns the block after the given block1292 * @param block: the block above the desired block1293 * @returns Block representing the after block, or undefined if there is no block1294 * after the given one1295 */1296 static getAfterBlock(blockPacket) {1297 return Compilation.BlocksReader.app.appGetAfterBlock(blockPacket.getID());1298 }1299 /**1300 * Returns the block before the given block1301 * @param block: the block below the desired block1302 * @returns Block representing the before block, or undefined if there is no block1303 * before the given one1304 */1305 static getBeforeBlock(blockPacket) {1306 var beforePacket = Compilation.BlocksReader.app.appGetBeforeBlock(blockPacket.getID());1307 if (beforePacket !== undefined) {1308 return beforePacket;1309 }1310 return undefined;1311 }1312 /**1313 * Returns the block that is the parent of the given block1314 * @param block: the block1315 * @returns Block representing the parent block, or undefined if there is no block1316 */1317 static getParentBlock(blockPacket) {1318 var parentPacket = Compilation.BlocksReader.app.appGetParent(blockPacket.getID());1319 if (parentPacket !== undefined) {1320 return parentPacket;1321 }1322 return undefined;1323 }1324 /**1325 * @returns the name of the page this block is on, or "" if no page1326 */1327 static getPageName(blockPacket) {1328 var name = Compilation.BlocksReader.app.appGetPageName(blockPacket.getID());1329 if (name === "") {1330 // Logger.log("no page name for: " + blockPacket.toString());1331 }1332 return name;1333 }1334 static setApp(app) {1335 Compilation.BlocksReader.app = app;1336 }1337 /**1338 * Returns the argument inside an internal argument1339 * @param blockID: number the id of the block with the parameter1340 * @param socketIndex: number the socket number within the block1341 */1342 static getInternalArg(blockID, socketIndex) {1343 var arg = Compilation.BlocksReader.app.appGetInternalArg(blockID, socketIndex);1344 return arg;1345 }1346 /**1347 * Returns the label of the given block1348 * @param blockID: number the block of which the label will be returned1349 * @returns String the label of the block1350 */1351 static getLabel(blockID, socket) {1352 return Compilation.BlocksReader.app.appGetLabel(blockID, socket);1353 }1354 /**1355 * Alerts ScriptBlocks of changes that occurred in WebLogo and affect blocks or pages1356 * @param args: Map<string, any> contains any arguments ScriptBlocks needs to handle the dispatched event. Keys include1357 * "category":"breed", "trait", "widget" for a changing object1358 * "event":"add", "delete", "change" for the type of change occurring1359 * "name/breed/oldName/newName" to specify the details of the change1360 */1361 static dispatchEvent(args) {1362 Compilation.BlocksReader.app.dispatchToJS(args);1363 }1364 }1365 Compilation.BlocksReader = BlocksReader;1366})(Compilation || (Compilation = {}));1367/// <reference path="../DataStructures/BlockPacket.ts" />1368/// <reference path="../DataStructures/AST.ts" />1369/// <reference path="../Compilation/BlocksReader.ts" />1370var Common;1371(function (Common) {1372 "use strict";1373 var BlocksReader = Compilation.BlocksReader;1374 class Procedure {1375 constructor(name) {1376 this.params = new Array();1377 this.calls = new Set();1378 this.id = ++Procedure.idBase;1379 this.name = name;1380 }1381 static makeNew(name) {1382 var proc = new Common.Procedure(name);1383 Common.Procedure.namedProcedures.set(name, proc);1384 Common.Procedure.procedures.set(proc.id, proc);1385 return proc;1386 }1387 static getByName(name) {1388 return Common.Procedure.namedProcedures.get(name);1389 }1390 static rename(oldName, newName) {1391 if (oldName === newName) {1392 return;1393 }1394 if (!Common.Procedure.namedProcedures.has(oldName) || Common.Procedure.namedProcedures.has(newName)) {1395 throw new Error("Error renaming procedure");1396 }1397 var procedure = Common.Procedure.namedProcedures.get(oldName);1398 procedure.name = newName;1399 Common.Procedure.namedProcedures.set(newName, procedure);1400 }1401 getNewParams(blockID) {1402 var sbLength = BlocksReader.getSBLength(blockID);1403 var paramNames = [];1404 for (var idx = 0; idx < Math.floor(sbLength / 3) - 1; idx++) {1405 var socketIdx = 2 + 3 * idx;1406 paramNames.push(BlocksReader.getSB(blockID, socketIdx).getLabel());1407 }1408 return paramNames;1409 }1410 getNewLabels(blockID) {1411 var sbLength = BlocksReader.getSBLength(blockID);1412 var frontLabels = sbLength - (sbLength % 3) - 1;1413 var labels = new Array(frontLabels);1414 for (var idx = 0; idx < frontLabels; idx++) {1415 var bp = BlocksReader.getSB(blockID, idx);1416 if (bp !== undefined) {1417 labels[idx] = bp.getLabel();1418 }1419 }1420 if (sbLength % 3 === 2) {1421 var bp = BlocksReader.getSB(blockID, sbLength - 1);1422 labels.push(bp.getLabel());1423 }1424 return labels;1425 }1426 }1427 Procedure.idBase = 0;1428 Procedure.namedProcedures = new Map();1429 Procedure.procedures = new Map();1430 Common.Procedure = Procedure;1431})(Common || (Common = {}));1432/// <reference path="../../Helper/Constants.ts" />1433/// <reference path="../../Common/Agent.ts" />1434/// <reference path="../../DataStructures/AST.ts" />1435var Compilation;1436(function (Compilation) {1437 var Instructions;1438 (function (Instructions) {1439 "use strict";1440 var ASTNode = DataStructures.ASTNode;1441 var Constants = Helper.Constants;1442 class AgtCreate extends ASTNode {1443 constructor() {1444 super(2, 0); // numArgs = 2, numBranches = 01445 }1446 fn(a, scope, args, rets) {1447 var numAgents = Number(args[0]);1448 var breed = String(args[1]);1449 var interval = 360. / numAgents;1450 for (var i = 0; i < numAgents; i++) {1451 var child = a.clone(breed);1452 // Give them evenly spaced headings1453 child.safeSetHeading(i * interval);1454 // don't tween the heading change; they're "born" facing this way1455 child.prevState.heading = child.state.heading;1456 }1457 rets[1] = Constants.AST_DONE;1458 }1459 to_js_no_yield() {1460 return `1461 Execution.AgentController.spawn(__wl_agt,1462 ${this.args.data[0].to_js_no_yield()},1463 ${this.args.data[1].to_js_no_yield()})1464 `;1465 }1466 to_js_setup() {1467 return `1468 ${this.args.data[0].to_js_setup()};1469 ${this.args.data[1].to_js_setup()};1470 var __wl_${this.id}_num_agents = ${this.args.data[0].to_js_final()};1471 var __wl_${this.id}_breed = ${this.args.data[1].to_js_final()};1472 `;1473 }1474 to_js_final() {1475 return `1476 Execution.AgentController.spawn(__wl_agt, __wl_${this.id}_num_agents, __wl_${this.id}_breed);1477 `;1478 }1479 }1480 Instructions.AgtCreate = AgtCreate;1481 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));1482})(Compilation || (Compilation = {}));1483/// <reference path="../../DataStructures/AST.ts" />1484/// <reference path="../../Common/Agent.ts" />1485var Compilation;1486(function (Compilation) {1487 var Instructions;1488 (function (Instructions) {1489 "use strict";1490 var ASTNode = DataStructures.ASTNode;1491 class SingleBranch extends ASTNode {1492 constructor(branch) {1493 super(0, 1); // numArgs = 0, numBranches = 11494 this.branches[0] = branch;1495 }1496 fn(a, scope, args, rets) {1497 rets[0] = 0;1498 rets[1] = 0;1499 }1500 to_js_no_yield() {1501 return `1502 ${this.branches[0].to_js()}1503 `;1504 }1505 to_js_setup() {1506 return ``;1507 }1508 to_js_final() {1509 return `1510 ${this.branches[0].to_js()};1511 `;1512 }1513 }1514 Instructions.SingleBranch = SingleBranch;1515 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));1516})(Compilation || (Compilation = {}));1517/// <reference path="../../Helper/Constants.ts" />1518/// <reference path="../../Helper/Utils.ts" />1519/// <reference path="../../DataStructures/AST.ts" />1520/// <reference path="../../Common/Agent.ts" />1521/// <reference path="../../Execution/AgentController.ts" />1522/// <reference path="SingleBranch" />1523var Compilation;1524(function (Compilation) {1525 var Instructions;1526 (function (Instructions) {1527 "use strict";1528 var ASTNode = DataStructures.ASTNode;1529 var Constants = Helper.Constants;1530 var SingleBranch = Compilation.Instructions.SingleBranch;1531 class AgtCreateDo extends ASTNode {1532 constructor() {1533 super(2, 1); // numArgs = 2, numBranches = 11534 }1535 fn(a, scope, args, rets) {1536 var numAgents = Number(args[0]);1537 var breed = String(args[1]);1538 var interval = 360. / numAgents;1539 for (var i = 0; i < numAgents; i++) {1540 var child = a.clone(breed);1541 // Give them evenly spaced headings1542 child.safeSetHeading(a.state.heading + (i * interval));1543 // don't tween the heading change; they're "born" facing this way1544 child.prevState.heading = child.state.heading;1545 }1546 rets[1] = Constants.AST_DONE;1547 }1548 to_js_no_yield() {1549 var fun = (new SingleBranch(this.branches[0])).make_function();1550 return `1551 Execution.AgentController.spawn_fun(__wl_agt, ${this.args.data[0].to_js_no_yield()},1552 ${this.args.data[1].to_js_no_yield()}, __wl_thd, ${fun});1553 `;1554 }1555 to_js_setup() {1556 return `1557 ${this.args.data[0].to_js_setup()};1558 ${this.args.data[1].to_js_setup()};1559 var __wl_${this.id}_agts = ${this.args.data[0].to_js_final()};1560 var __wl_${this.id}_breed = ${this.args.data[1].to_js_final()};1561 `;1562 }1563 to_js_final() {1564 var gen = (new SingleBranch(this.branches[0])).make_generator();1565 return `1566 Execution.AgentController.spawn(__wl_agt, __wl_${this.id}_agts, __wl_${this.id}_breed,1567 __wl_thd, ${gen});1568 `;1569 }1570 }1571 Instructions.AgtCreateDo = AgtCreateDo;1572 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));1573})(Compilation || (Compilation = {}));1574/// <reference path="../../Helper/Constants.ts" />1575/// <reference path="../../DataStructures/AST.ts" />1576/// <reference path="../../Common/Agent.ts" />1577var Compilation;1578(function (Compilation) {1579 var Instructions;1580 (function (Instructions) {1581 "use strict";1582 var ASTNode = DataStructures.ASTNode;1583 var Constants = Helper.Constants;1584 class AgtDelete extends ASTNode {1585 constructor() {1586 super(0, 0); // numArgs = 0, numBranches = 01587 }1588 fn(a, scope, args, rets) {1589 a.die();1590 rets[1] = Constants.AST_DONE;1591 }1592 to_js_no_yield() {1593 return `1594 __wl_agt.die()1595 `;1596 }1597 to_js_setup() {1598 return ``;1599 }1600 to_js_final() {1601 return `1602 __wl_agt.die()1603 `;1604 }1605 }1606 Instructions.AgtDelete = AgtDelete;1607 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));1608})(Compilation || (Compilation = {}));1609/// <reference path="../../Helper/Constants.ts" />1610/// <reference path="../../DataStructures/AST.ts" />1611/// <reference path="../../Common/Agent.ts" />1612var Compilation;1613(function (Compilation) {1614 var Instructions;1615 (function (Instructions) {1616 "use strict";1617 var ASTNode = DataStructures.ASTNode;1618 var Constants = Helper.Constants;1619 class AgtDeleteAgent extends ASTNode {1620 constructor() {1621 super(1, 0); // numArgs = 1, numBranches = 01622 }1623 fn(a, scope, args, rets) {1624 var target = args[0]; // this may be a copy of the agent so we need to get the original1625 if (target.isSnapshot) {1626 target.original.die();1627 }1628 else {1629 target.die();1630 }1631 rets[1] = Constants.AST_DONE;1632 }1633 to_js_no_yield() {1634 return `1635 var __wl_${this.id}_target = ${this.args.data[0].to_js_no_yield()};1636 if (__wl_${this.id}_target !== undefined && __wl_${this.id}_target.isAgent) {1637 if (__wl_${this.id}_target.isSnapshot) {1638 __wl_${this.id}_target.original.die();1639 } else {1640 __wl_${this.id}_target.die();1641 }1642 }1643 `;1644 }1645 to_js_setup() {1646 return `1647 ${this.args.data[0].to_js_setup()};1648 var __wl_${this.id}_target = ${this.args.data[0].to_js_no_yield()};1649 `;1650 }1651 to_js_final() {1652 return `1653 if (__wl_${this.id}_target !== undefined && __wl_${this.id}_target.isAgent) {1654 if (__wl_${this.id}_target.isSnapshot) {1655 __wl_${this.id}_target.original.die();1656 } else {1657 __wl_${this.id}_target.die();1658 }1659 }1660 `;1661 }1662 }1663 Instructions.AgtDeleteAgent = AgtDeleteAgent;1664 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));1665})(Compilation || (Compilation = {}));1666/// <reference path="../../Helper/Constants.ts" />1667/// <reference path="../../DataStructures/AST.ts" />1668/// <reference path="../../Common/Agent.ts" />1669/// <reference path="../../Execution/AgentController.ts" />1670var Compilation;1671(function (Compilation) {1672 var Instructions;1673 (function (Instructions) {1674 "use strict";1675 var ASTNode = DataStructures.ASTNode;1676 var Constants = Helper.Constants;1677 var AgentController = Execution.AgentController;1678 class AgtDeleteEveryone extends ASTNode {1679 constructor() {1680 super(0, 0); // numArgs = 0, numBranches = 01681 }1682 fn(a, scope, args, rets) {1683 var skipWorld = true;1684 for (var agt of AgentController.getAllAgents(skipWorld)) {1685 agt.die();1686 }1687 rets[1] = Constants.AST_DONE;1688 }1689 to_js_no_yield() {1690 return `1691 for (var agt of Execution.AgentController.getAllAgents(true)) {1692 agt.die();1693 }1694 `;1695 }1696 to_js_setup() {1697 return ``;1698 }1699 to_js_final() {1700 return `1701 var __wl_${this.id}_skip_world: boolean = true;1702 for (var agt of Execution.AgentController.getAllAgents(__wl_${this.id}_skip_world)) {1703 agt.die();1704 }1705 `;1706 }1707 }1708 Instructions.AgtDeleteEveryone = AgtDeleteEveryone;1709 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));1710})(Compilation || (Compilation = {}));1711/// <reference path="../../Helper/Constants.ts" />1712/// <reference path="../../DataStructures/AST.ts" />1713/// <reference path="../../Common/Agent.ts" />1714var Compilation;1715(function (Compilation) {1716 var Instructions;1717 (function (Instructions) {1718 "use strict";1719 var ASTNode = DataStructures.ASTNode;1720 var Constants = Helper.Constants;1721 class AgtMe extends ASTNode {1722 constructor() {1723 super(0, 0); // numArgs = 0, numBranches = 01724 }1725 fn(a, scope, args, rets) {1726 rets[0] = a;1727 rets[1] = Constants.AST_DONE;1728 }1729 to_js_no_yield() {1730 return `1731 __wl_agt1732 `;1733 }1734 to_js_setup() {1735 return ``;1736 }1737 to_js_final() {1738 return `1739 __wl_agt1740 `;1741 }1742 }1743 Instructions.AgtMe = AgtMe;1744 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));1745})(Compilation || (Compilation = {}));1746/// <reference path="../../Helper/Constants.ts" />1747/// <reference path="../../DataStructures/AST.ts" />1748/// <reference path="../../Common/Agent.ts" />1749var Compilation;1750(function (Compilation) {1751 var Instructions;1752 (function (Instructions) {1753 "use strict";1754 var ASTNode = DataStructures.ASTNode;1755 var Constants = Helper.Constants;1756 class AgtMyParent extends ASTNode {1757 constructor() {1758 super(0, 0); // numArgs = 0, numBranches = 01759 }1760 fn(a, scope, args, rets) {1761 rets[0] = a.parent;1762 rets[1] = Constants.AST_DONE;1763 }1764 to_js_no_yield() {1765 return `1766 __wl_agt.parent1767 `;1768 }1769 to_js_setup() {1770 return ``;1771 }1772 to_js_final() {1773 return `1774 __wl_agt.parent1775 `;1776 }1777 }1778 Instructions.AgtMyParent = AgtMyParent;1779 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));1780})(Compilation || (Compilation = {}));1781/// <reference path="../../Helper/Constants.ts" />1782/// <reference path="../../DataStructures/AST.ts" />1783/// <reference path="../../Common/Agent.ts" />1784var Compilation;1785(function (Compilation) {1786 var Instructions;1787 (function (Instructions) {1788 "use strict";1789 var ASTNode = DataStructures.ASTNode;1790 var Constants = Helper.Constants;1791 class CalcAbs extends ASTNode {1792 constructor() {1793 super(1, 0); // numArgs = 1, numBranches = 01794 }1795 fn(a, scope, args, rets) {1796 var n = Number(args[0]);1797 rets[0] = Math.abs(n);1798 rets[1] = Constants.AST_DONE;1799 }1800 to_js_no_yield() {1801 return `1802 Math.abs(${this.args.data[0].to_js_no_yield()})1803 `;1804 }1805 to_js_setup() {1806 return `1807 ${this.args.data[0].to_js_setup()};1808 var __wl_${this.id}_x = ${this.args.data[0].to_js_final()};1809 `;1810 }1811 to_js_final() {1812 return `1813 Math.abs(__wl_${this.id}_x)1814 `;1815 }1816 }1817 Instructions.CalcAbs = CalcAbs;1818 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));1819})(Compilation || (Compilation = {}));1820/// <reference path="../../Helper/Constants.ts" />1821/// <reference path="../../DataStructures/AST.ts" />1822/// <reference path="../../Common/Agent.ts" />1823var Compilation;1824(function (Compilation) {1825 var Instructions;1826 (function (Instructions) {1827 "use strict";1828 var ASTNode = DataStructures.ASTNode;1829 var Constants = Helper.Constants;1830 class CalcArcSinCosTan extends ASTNode {1831 constructor() {1832 super(2, 0); // numArgs = 2, numBranches = 01833 }1834 fn(a, scope, args, rets) {1835 var mode = String(args[0]);1836 var n = Number(args[1]);1837 if (mode === "arcsin") {1838 rets[0] = Math.asin(n) * 180 / Math.PI;1839 }1840 else if (mode === "arccos") {1841 rets[0] = Math.acos(n) * 180 / Math.PI;1842 }1843 else if (mode === "arctan") {1844 rets[0] = Math.atan(n) * 180 / Math.PI;1845 }1846 else {1847 throw new Error(`Invalid mode: ${mode}`);1848 }1849 rets[1] = Constants.AST_DONE;1850 }1851 to_js_no_yield() {1852 return `1853 Helper.Utils.trig(${this.args.data[0].to_js_no_yield()}, ${this.args.data[1].to_js_no_yield()})1854 `;1855 }1856 to_js_setup() {1857 return `1858 ${this.args.data[0].to_js_setup()};1859 ${this.args.data[1].to_js_setup()};1860 var __wl_${this.id}_fn_name = ${this.args.data[0].to_js_final()};1861 var __wl_${this.id}_x = ${this.args.data[1].to_js_final()};1862 var __wl_${this.id}_fn;1863 if (__wl_${this.id}_fn_name === "arccos") {1864 __wl_${this.id}_fn = Math.acos;1865 } else if (__wl_${this.id}_fn_name === "arcsin") {1866 __wl_${this.id}_fn = Math.asin;1867 } else if (__wl_${this.id}_fn_name === "arctan") {1868 __wl_${this.id}_fn = Math.atan;1869 }1870 `;1871 }1872 to_js_final() {1873 return `1874 __wl_${this.id}_fn(__wl_${this.id}_x) * 180 / Math.PI1875 `;1876 }1877 }1878 Instructions.CalcArcSinCosTan = CalcArcSinCosTan;1879 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));1880})(Compilation || (Compilation = {}));1881/// <reference path="../../Helper/Constants.ts" />1882/// <reference path="../../DataStructures/AST.ts" />1883/// <reference path="../../Common/Agent.ts" />1884var Compilation;1885(function (Compilation) {1886 var Instructions;1887 (function (Instructions) {1888 "use strict";1889 var ASTNode = DataStructures.ASTNode;1890 var Constants = Helper.Constants;1891 class CalcDifference extends ASTNode {1892 constructor() {1893 super(2, 0); // numArgs = 2, numBranches = 01894 }1895 fn(a, scope, args, rets) {1896 rets[0] = args[0] - args[1];1897 rets[1] = Constants.AST_DONE;1898 }1899 to_js_no_yield() {1900 return `1901 (${this.args.data[0].to_js_no_yield()} - ${this.args.data[1].to_js_no_yield()})1902 `;1903 }1904 to_js_setup() {1905 return `1906 ${this.args.data[0].to_js_setup()};1907 ${this.args.data[1].to_js_setup()};1908 var __wl_${this.id}_a = ${this.args.data[0].to_js_final()};1909 var __wl_${this.id}_b = ${this.args.data[1].to_js_final()};1910 `;1911 }1912 to_js_final() {1913 return `1914 __wl_${this.id}_a - __wl_${this.id}_b1915 `;1916 }1917 }1918 Instructions.CalcDifference = CalcDifference;1919 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));1920})(Compilation || (Compilation = {}));1921/// <reference path="../../Helper/Constants.ts" />1922/// <reference path="../../DataStructures/AST.ts" />1923/// <reference path="../../Common/Agent.ts" />1924var Compilation;1925(function (Compilation) {1926 var Instructions;1927 (function (Instructions) {1928 "use strict";1929 var ASTNode = DataStructures.ASTNode;1930 var Constants = Helper.Constants;1931 class CalcLn extends ASTNode {1932 constructor() {1933 super(1, 0); // numArgs = 1, numBranches = 01934 }1935 fn(a, scope, args, rets) {1936 rets[0] = Math.log(args[0]);1937 rets[1] = Constants.AST_DONE;1938 }1939 to_js_no_yield() {1940 return `1941 Math.log(${this.args.data[0].to_js_no_yield()})1942 `;1943 }1944 to_js_setup() {1945 return `1946 ${this.args.data[0].to_js_setup()};1947 var __wl_${this.id}_n = ${this.args.data[0].to_js_final()};1948 `;1949 }1950 to_js_final() {1951 return `1952 Math.log(__wl_${this.id}_n)1953 `;1954 }1955 }1956 Instructions.CalcLn = CalcLn;1957 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));1958})(Compilation || (Compilation = {}));1959/// <reference path="../../Helper/Constants.ts" />1960/// <reference path="../../DataStructures/AST.ts" />1961/// <reference path="../../Common/Agent.ts" />1962var Compilation;1963(function (Compilation) {1964 var Instructions;1965 (function (Instructions) {1966 "use strict";1967 var ASTNode = DataStructures.ASTNode;1968 var Constants = Helper.Constants;1969 class CalcLog extends ASTNode {1970 constructor() {1971 super(1, 0); // numArgs = 1, numBranches = 01972 }1973 fn(a, scope, args, rets) {1974 var n = Number(args[0]);1975 rets[0] = Math.log10(n);1976 rets[1] = Constants.AST_DONE;1977 }1978 to_js_no_yield() {1979 return `1980 Math.log10(${this.args.data[0].to_js_no_yield()})1981 `;1982 }1983 to_js_setup() {1984 return `1985 ${this.args.data[0].to_js_setup()};1986 var __wl_${this.id}_n = ${this.args.data[0].to_js_final()};1987 `;1988 }1989 to_js_final() {1990 return `1991 Math.log10(__wl_${this.id}_n)1992 `;1993 }1994 }1995 Instructions.CalcLog = CalcLog;1996 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));1997})(Compilation || (Compilation = {}));1998/// <reference path="../../Helper/Constants.ts" />1999/// <reference path="../../DataStructures/AST.ts" />2000/// <reference path="../../Common/Agent.ts" />2001var Compilation;2002(function (Compilation) {2003 var Instructions;2004 (function (Instructions) {2005 "use strict";2006 var ASTNode = DataStructures.ASTNode;2007 var Constants = Helper.Constants;2008 class CalcMaxMin extends ASTNode {2009 constructor() {2010 super(3, 0); // numArgs = 3, numBranches = 02011 }2012 fn(a, scope, args, rets) {2013 var minMax = String(args[0]);2014 var n2 = Number(args[1]);2015 var n1 = Number(args[2]);2016 if (minMax === "larger of") {2017 rets[0] = Math.max(n1, n2);2018 }2019 else {2020 rets[0] = Math.min(n1, n2);2021 }2022 rets[1] = Constants.AST_DONE;2023 }2024 to_js_no_yield() {2025 return `2026 Helper.Utils.maxmin(${this.args.data[0].to_js_no_yield()},2027 ${this.args.data[1].to_js_no_yield()},2028 ${this.args.data[2].to_js_no_yield()})2029 `;2030 }2031 to_js_setup() {2032 return `2033 ${this.args.data[0].to_js_setup()};2034 ${this.args.data[1].to_js_setup()};2035 ${this.args.data[2].to_js_setup()};2036 var __wl_${this.id}_fn_name = ${this.args.data[0].to_js_final()};2037 var __wl_${this.id}_a = ${this.args.data[1].to_js_final()};2038 var __wl_${this.id}_b = ${this.args.data[2].to_js_final()};2039 var __wl_${this.id}_fn;2040 if (__wl_${this.id}_fn_name === "larger of") {2041 __wl_${this.id}_fn = Math.max;2042 } else {2043 __wl_${this.id}_fn = Math.min;2044 }2045 `;2046 }2047 to_js_final() {2048 return `2049 __wl_${this.id}_fn(__wl_${this.id}_a, __wl_${this.id}_b)2050 `;2051 }2052 }2053 Instructions.CalcMaxMin = CalcMaxMin;2054 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));2055})(Compilation || (Compilation = {}));2056/// <reference path="../../Helper/Constants.ts" />2057/// <reference path="../../DataStructures/AST.ts" />2058/// <reference path="../../Common/Agent.ts" />2059var Compilation;2060(function (Compilation) {2061 var Instructions;2062 (function (Instructions) {2063 "use strict";2064 var ASTNode = DataStructures.ASTNode;2065 var Constants = Helper.Constants;2066 class CalcPower extends ASTNode {2067 constructor() {2068 super(2, 0); // numArgs = 2, numBranches = 02069 }2070 fn(a, scope, args, rets) {2071 var n1 = args[0];2072 var n2 = args[1];2073 rets[0] = Math.pow(n1, n2);2074 rets[1] = Constants.AST_DONE;2075 }2076 to_js_no_yield() {2077 return `2078 Math.pow(${this.args.data[0].to_js_no_yield()}, ${this.args.data[1].to_js_no_yield()})2079 `;2080 }2081 to_js_setup() {2082 return `2083 ${this.args.data[0].to_js_setup()};2084 ${this.args.data[1].to_js_setup()};2085 var __wl_${this.id}_a = ${this.args.data[0].to_js_final()};2086 var __wl_${this.id}_b = ${this.args.data[1].to_js_final()};2087 `;2088 }2089 to_js_final() {2090 return `2091 Math.pow(__wl_${this.id}_a, __wl_${this.id}_b)2092 `;2093 }2094 }2095 Instructions.CalcPower = CalcPower;2096 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));2097})(Compilation || (Compilation = {}));2098/// <reference path="../../Helper/Constants.ts" />2099/// <reference path="../../DataStructures/AST.ts" />2100/// <reference path="../../Common/Agent.ts" />2101var Compilation;2102(function (Compilation) {2103 var Instructions;2104 (function (Instructions) {2105 "use strict";2106 var ASTNode = DataStructures.ASTNode;2107 var Constants = Helper.Constants;2108 class CalcProduct extends ASTNode {2109 constructor() {2110 super(2, 0); // numArgs = 2, numBranches = 02111 }2112 fn(a, scope, args, rets) {2113 var n1 = Number(args[0]);2114 var n2 = Number(args[1]);2115 rets[0] = n1 * n2;2116 rets[1] = Constants.AST_DONE;2117 }2118 to_js_no_yield() {2119 return `2120 (${this.args.data[0].to_js_no_yield()} * ${this.args.data[1].to_js_no_yield()})2121 `;2122 }2123 to_js_setup() {2124 return `2125 ${this.args.data[0].to_js_setup()};2126 ${this.args.data[1].to_js_setup()};2127 var __wl_${this.id}_a = ${this.args.data[0].to_js_final()};2128 var __wl_${this.id}_b = ${this.args.data[1].to_js_final()};2129 `;2130 }2131 to_js_final() {2132 return `2133 __wl_${this.id}_a * __wl_${this.id}_b2134 `;2135 }2136 }2137 Instructions.CalcProduct = CalcProduct;2138 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));2139})(Compilation || (Compilation = {}));2140/// <reference path="../../Helper/Constants.ts" />2141/// <reference path="../../DataStructures/AST.ts" />2142/// <reference path="../../Common/Agent.ts" />2143var Compilation;2144(function (Compilation) {2145 var Instructions;2146 (function (Instructions) {2147 "use strict";2148 var ASTNode = DataStructures.ASTNode;2149 var Constants = Helper.Constants;2150 class CalcQuotient extends ASTNode {2151 constructor() {2152 super(2, 0); // numArgs = 2, numBranches = 02153 }2154 fn(a, scope, args, rets) {2155 var n = Number(args[0]);2156 var d = Number(args[1]);2157 rets[0] = n / d;2158 rets[1] = Constants.AST_DONE;2159 }2160 to_js_no_yield() {2161 return `2162 (${this.args.data[0].to_js_no_yield()} / ${this.args.data[1].to_js_no_yield()})2163 `;2164 }2165 to_js_setup() {2166 return `2167 ${this.args.data[0].to_js_setup()};2168 ${this.args.data[1].to_js_setup()};2169 var __wl_${this.id}_a = ${this.args.data[0].to_js_final()};2170 var __wl_${this.id}_b = ${this.args.data[1].to_js_final()};2171 `;2172 }2173 to_js_final() {2174 return `2175 __wl_${this.id}_a / __wl_${this.id}_b2176 `;2177 }2178 }2179 Instructions.CalcQuotient = CalcQuotient;2180 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));2181})(Compilation || (Compilation = {}));2182/// <reference path="../../Helper/Constants.ts" />2183/// <reference path="../../DataStructures/AST.ts" />2184/// <reference path="../../Common/Agent.ts" />2185var Compilation;2186(function (Compilation) {2187 var Instructions;2188 (function (Instructions) {2189 "use strict";2190 var ASTNode = DataStructures.ASTNode;2191 var Constants = Helper.Constants;2192 class CalcRemainder extends ASTNode {2193 constructor() {2194 super(2, 0); // numArgs = 2, numBranches = 02195 }2196 fn(a, scope, args, rets) {2197 var n1 = Number(args[0]);2198 var n2 = Number(args[1]);2199 rets[0] = n1 % n2;2200 rets[1] = Constants.AST_DONE;2201 }2202 to_js_no_yield() {2203 return `2204 (${this.args.data[0].to_js_no_yield()} % ${this.args.data[1].to_js_no_yield()})2205 `;2206 }2207 to_js_setup() {2208 return `2209 ${this.args.data[0].to_js_setup()};2210 ${this.args.data[1].to_js_setup()};2211 var __wl_${this.id}_a = ${this.args.data[0].to_js_final()};2212 var __wl_${this.id}_b = ${this.args.data[1].to_js_final()};2213 `;2214 }2215 to_js_final() {2216 return `2217 __wl_${this.id}_a % __wl_${this.id}_b2218 `;2219 }2220 }2221 Instructions.CalcRemainder = CalcRemainder;2222 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));2223})(Compilation || (Compilation = {}));2224/// <reference path="../../Helper/Constants.ts" />2225/// <reference path="../../DataStructures/AST.ts" />2226/// <reference path="../../Common/Agent.ts" />2227var Compilation;2228(function (Compilation) {2229 var Instructions;2230 (function (Instructions) {2231 "use strict";2232 var ASTNode = DataStructures.ASTNode;2233 var Constants = Helper.Constants;2234 class CalcRound extends ASTNode {2235 constructor() {2236 super(2, 0); // numArgs = 2, numBranches = 02237 }2238 fn(a, scope, args, rets) {2239 var n = Number(args[0]);2240 var precision = Number(args[1]);2241 rets[0] = Math.round(n * Math.pow(10, precision)) / Math.pow(10, precision);2242 rets[1] = Constants.AST_DONE;2243 }2244 to_js_no_yield() {2245 return `2246 Helper.Utils.round(${this.args.data[0].to_js_no_yield()}, ${this.args.data[1].to_js_no_yield()})2247 `;2248 }2249 to_js_setup() {2250 return `2251 ${this.args.data[0].to_js_setup()};2252 ${this.args.data[1].to_js_setup()};2253 var __wl_${this.id}_x = ${this.args.data[0].to_js_final()};2254 var __wl_${this.id}_base = Math.pow(10, ${this.args.data[1].to_js_final()});2255 `;2256 }2257 to_js_final() {2258 return `2259 Math.round(__wl_${this.id}_x * __wl_${this.id}_base) / __wl_${this.id}_base;2260 `;2261 }2262 }2263 Instructions.CalcRound = CalcRound;2264 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));2265})(Compilation || (Compilation = {}));2266/// <reference path="../../Helper/Constants.ts" />2267/// <reference path="../../DataStructures/AST.ts" />2268/// <reference path="../../Common/Agent.ts" />2269var Compilation;2270(function (Compilation) {2271 var Instructions;2272 (function (Instructions) {2273 "use strict";2274 var ASTNode = DataStructures.ASTNode;2275 var Constants = Helper.Constants;2276 class CalcSquareRoot extends ASTNode {2277 constructor() {2278 super(1, 0); // numArgs = 1, numBranches = 02279 }2280 fn(a, scope, args, rets) {2281 var n = Number(args[0]);2282 rets[0] = Math.sqrt(n);2283 rets[1] = Constants.AST_DONE;2284 }2285 to_js_no_yield() {2286 return `2287 Math.sqrt(${this.args.data[0].to_js_no_yield()})2288 `;2289 }2290 to_js_setup() {2291 return `2292 ${this.args.data[0].to_js_setup()};2293 var __wl_${this.id}_x = ${this.args.data[0].to_js_final()};2294 `;2295 }2296 to_js_final() {2297 return `2298 Math.sqrt(__wl_${this.id}_x)2299 `;2300 }2301 }2302 Instructions.CalcSquareRoot = CalcSquareRoot;2303 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));2304})(Compilation || (Compilation = {}));2305/// <reference path="../../Helper/Constants.ts" />2306/// <reference path="../../DataStructures/AST.ts" />2307/// <reference path="../../Common/Agent.ts" />2308var Compilation;2309(function (Compilation) {2310 var Instructions;2311 (function (Instructions) {2312 "use strict";2313 var ASTNode = DataStructures.ASTNode;2314 var Constants = Helper.Constants;2315 class CalcSum extends ASTNode {2316 constructor() {2317 super(2, 0); // numArgs = 2, numBranches = 02318 }2319 fn(a, scope, args, rets) {2320 rets[0] = args[0] + args[1];2321 rets[1] = Constants.AST_DONE;2322 }2323 to_js_no_yield() {2324 return `2325 (${this.args.data[0].to_js_no_yield()} + ${this.args.data[1].to_js_no_yield()})2326 `;2327 }2328 to_js_setup() {2329 return `2330 ${this.args.data[0].to_js_setup()};2331 ${this.args.data[1].to_js_setup()};2332 var __wl_${this.id}_a = ${this.args.data[0].to_js_final()};2333 var __wl_${this.id}_b = ${this.args.data[1].to_js_final()};2334 `;2335 }2336 to_js_final() {2337 return `2338 __wl_${this.id}_a + __wl_${this.id}_b2339 `;2340 }2341 }2342 Instructions.CalcSum = CalcSum;2343 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));2344})(Compilation || (Compilation = {}));2345/// <reference path="../../Helper/Constants.ts" />2346/// <reference path="../../DataStructures/AST.ts" />2347/// <reference path="../../Common/Agent.ts" />2348var Compilation;2349(function (Compilation) {2350 var Instructions;2351 (function (Instructions) {2352 "use strict";2353 var ASTNode = DataStructures.ASTNode;2354 var Constants = Helper.Constants;2355 class CalcTrigSinCosTan extends ASTNode {2356 constructor() {2357 super(2, 0); // numArgs = 2, numBranches = 02358 }2359 fn(a, scope, args, rets) {2360 var mode = String(args[0]);2361 var n = Number(args[1]);2362 if (mode === "sin") {2363 rets[0] = Math.sin(n * Math.PI / 180);2364 }2365 else if (mode === "cos") {2366 rets[0] = Math.cos(n * Math.PI / 180);2367 }2368 else if (mode === "tan") {2369 rets[0] = Math.tan(n * Math.PI / 180);2370 }2371 else {2372 throw new Error(`Invalid mode: ${mode}`);2373 }2374 rets[1] = Constants.AST_DONE;2375 }2376 to_js_no_yield() {2377 return `2378 Helper.Utils.trig(${this.args.data[0].to_js_no_yield()}, ${this.args.data[1].to_js_no_yield()})2379 `;2380 }2381 to_js_setup() {2382 return `2383 ${this.args.data[0].to_js_setup()};2384 ${this.args.data[1].to_js_setup()};2385 var __wl_${this.id}_fn_name = ${this.args.data[0].to_js_final()};2386 var __wl_${this.id}_x = ${this.args.data[1].to_js_final()};2387 var __wl_${this.id}_fn;2388 if (__wl_${this.id}_fn_name === "cos") {2389 __wl_${this.id}_fn = Math.cos;2390 } else if (__wl_${this.id}_fn_name === "sin") {2391 __wl_${this.id}_fn = Math.sin;2392 } else if (__wl_${this.id}_fn_name === "tan") {2393 __wl_${this.id}_fn = Math.tan;2394 }2395 `;2396 }2397 to_js_final() {2398 return `2399 __wl_${this.id}_fn(__wl_${this.id}_x * Math.PI / 180)2400 `;2401 }2402 }2403 Instructions.CalcTrigSinCosTan = CalcTrigSinCosTan;2404 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));2405})(Compilation || (Compilation = {}));2406/// <reference path="../../Helper/Constants.ts" />2407/// <reference path="../../DataStructures/AST.ts" />2408/// <reference path="../../Common/Agent.ts" />2409/// <reference path="../../Common/State.ts" />2410var Compilation;2411(function (Compilation) {2412 var Instructions;2413 (function (Instructions) {2414 "use strict";2415 var ASTNode = DataStructures.ASTNode;2416 var Constants = Helper.Constants;2417 var State = Common.State;2418 class Clock extends ASTNode {2419 constructor() {2420 super(0, 0); // numArgs = 0, numBranches = 02421 }2422 fn(a, scope, args, rets) {2423 rets[0] = State.clock;2424 rets[1] = Constants.AST_DONE;2425 }2426 to_js_no_yield() {2427 return `2428 Common.State.clock2429 `;2430 }2431 to_js_setup() {2432 return ``;2433 }2434 to_js_final() {2435 return `2436 Common.State.clock2437 `;2438 }2439 }2440 Instructions.Clock = Clock;2441 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));2442})(Compilation || (Compilation = {}));2443/// <reference path="../../Helper/Constants.ts" />2444/// <reference path="../../DataStructures/AST.ts" />2445/// <reference path="../../Common/Agent.ts" />2446/// <reference path="../../Common/State.ts" />2447var Compilation;2448(function (Compilation) {2449 var Instructions;2450 (function (Instructions) {2451 "use strict";2452 var ASTNode = DataStructures.ASTNode;2453 var State = Common.State;2454 var Constants = Helper.Constants;2455 class ClockSet extends ASTNode {2456 constructor() {2457 super(1, 0); // numArgs = 1, numBranches = 02458 }2459 fn(a, scope, args, rets) {2460 State.clock = Number(args[0]);2461 rets[1] = Constants.AST_DONE;2462 }2463 to_js_no_yield() {2464 return `2465 Common.State.clock = ${this.args.data[0].to_js_no_yield()}2466 `;2467 }2468 to_js_setup() {2469 return `2470 ${this.args.data[0].to_js_setup()};2471 var __wl_${this.id}_clock = Number(${this.args.data[0].to_js_final()});2472 `;2473 }2474 to_js_final() {2475 return `2476 Common.State.clock = __wl_${this.id}_clock;2477 `;2478 }2479 }2480 Instructions.ClockSet = ClockSet;2481 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));2482})(Compilation || (Compilation = {}));2483/// <reference path="../../Helper/Constants.ts" />2484/// <reference path="../../DataStructures/AST.ts" />2485/// <reference path="../../Common/Agent.ts" />2486var Compilation;2487(function (Compilation) {2488 var Instructions;2489 (function (Instructions) {2490 "use strict";2491 var ASTNode = DataStructures.ASTNode;2492 var Constants = Helper.Constants;2493 class Collidee extends ASTNode {2494 constructor() {2495 super(0, 0); // numArgs = 0, numBranches = 02496 }2497 fn(a, scope, args, rets) {2498 rets[0] = a.collidee;2499 rets[1] = Constants.AST_DONE;2500 }2501 to_js_no_yield() {2502 return `2503 __wl_agt.collidee2504 `;2505 }2506 to_js_setup() {2507 return ``;2508 }2509 to_js_final() {2510 return `2511 __wl_agt.collidee2512 `;2513 }2514 }2515 Instructions.Collidee = Collidee;2516 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));2517})(Compilation || (Compilation = {}));2518/// <reference path="../../Helper/Constants.ts" />2519/// <reference path="../../Helper/Utils.ts" />2520/// <reference path="../../DataStructures/AST.ts" />2521/// <reference path="../../Common/Agent.ts" />2522var Compilation;2523(function (Compilation) {2524 var Instructions;2525 (function (Instructions) {2526 "use strict";2527 var ASTNode = DataStructures.ASTNode;2528 var Constants = Helper.Constants;2529 var Utils = Helper.Utils;2530 class ColorOptions extends ASTNode {2531 constructor() {2532 super(1, 0); // numArgs = 1, numBranches = 02533 }2534 fn(a, scope, args, rets) {2535 var option = String(args[0]);2536 if (option === "random_color") {2537 rets[0] = Utils.random() * 0xFFFFFF;2538 }2539 else {2540 rets[0] = option;2541 }2542 rets[1] = Constants.AST_DONE;2543 }2544 to_js_no_yield() {2545 return `2546 Helper.Utils.toColor(${this.args.data[0].to_js_no_yield()})2547 `;2548 }2549 to_js_setup() {2550 return `2551 ${this.args.data[0].to_js_setup()};2552 var __wl_${this.id}_option = String(${this.args.data[0].to_js_final()});2553 `;2554 }2555 to_js_final() {2556 return `2557 Helper.Utils.toColor(__wl_${this.id}_option)2558 `;2559 }2560 }2561 Instructions.ColorOptions = ColorOptions;2562 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));2563})(Compilation || (Compilation = {}));2564/// <reference path="../../Helper/Constants.ts" />2565/// <reference path="../../Helper/Utils.ts" />2566/// <reference path="../../DataStructures/AST.ts" />2567/// <reference path="../../Common/Agent.ts" />2568var Compilation;2569(function (Compilation) {2570 var Instructions;2571 (function (Instructions) {2572 "use strict";2573 var ASTNode = DataStructures.ASTNode;2574 var Constants = Helper.Constants;2575 var Utils = Helper.Utils;2576 class ColorRGB extends ASTNode {2577 constructor() {2578 super(3, 0); // numArgs = 3, numBranches = 02579 }2580 fn(a, scope, args, rets) {2581 var red = Utils.limit(args[0], 0, 255);2582 var green = Utils.limit(args[1], 0, 255);2583 var blue = Utils.limit(args[2], 0, 255);2584 /* tslint:disable no-bitwise */2585 var color = (red << 16) + (green << 8) + blue;2586 /* tslint:enable no-bitwise */2587 rets[0] = color;2588 rets[1] = Constants.AST_DONE;2589 }2590 to_js_no_yield() {2591 return `2592 ((Helper.Utils.limit(${this.args.data[0].to_js_no_yield()}, 0, 255) << 16)2593 + (Helper.Utils.limit(${this.args.data[1].to_js_no_yield()}, 0, 255) << 8)2594 + (Helper.Utils.limit(${this.args.data[2].to_js_no_yield()}, 0, 255) << 0)2595 )2596 `;2597 }2598 to_js_setup() {2599 return `2600 ${this.args.data[0].to_js_setup()};2601 ${this.args.data[1].to_js_setup()};2602 ${this.args.data[2].to_js_setup()};2603 var __wl_${this.id}_red = Helper.Utils.limit(${this.args.data[0].to_js_final()}, 0, 255);2604 var __wl_${this.id}_green = Helper.Utils.limit(${this.args.data[1].to_js_final()}, 0, 255);2605 var __wl_${this.id}_blue = Helper.Utils.limit(${this.args.data[2].to_js_final()}, 0, 255);2606 `;2607 }2608 to_js_final() {2609 return `2610 (__wl_${this.id}_red << 16) + (__wl_${this.id}_green << 8) + (__wl_${this.id}_blue)2611 `;2612 }2613 }2614 Instructions.ColorRGB = ColorRGB;2615 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));2616})(Compilation || (Compilation = {}));2617/// <reference path="../../Helper/Constants.ts" />2618/// <reference path="../../DataStructures/AST.ts" />2619/// <reference path="../../Common/Agent.ts" />2620var Compilation;2621(function (Compilation) {2622 var Instructions;2623 (function (Instructions) {2624 "use strict";2625 var ASTNode = DataStructures.ASTNode;2626 var Constants = Helper.Constants;2627 class CompAnd extends ASTNode {2628 constructor() {2629 super(2, 0); // numArgs = 2, numBranches = 02630 }2631 fn(a, scope, args, rets) {2632 rets[0] = args[0] && args[1];2633 rets[1] = Constants.AST_DONE;2634 }2635 to_js_no_yield() {2636 return `2637 (${this.args.data[0].to_js_no_yield()} && ${this.args.data[1].to_js_no_yield()})2638 `;2639 }2640 to_js_setup() {2641 // Short circuit evaluation of the second parameter if the first is false2642 return `2643 ${this.args.data[0].to_js_setup()};2644 var __wl_${this.id}_a = ${this.args.data[0].to_js_final()};2645 var __wl_${this.id}_b;2646 if (__wl_${this.id}_a) {2647 ${this.args.data[1].to_js_setup()};2648 __wl_${this.id}_b = ${this.args.data[1].to_js_final()};2649 }2650 `;2651 }2652 to_js_final() {2653 return `2654 __wl_${this.id}_a && __wl_${this.id}_b2655 `;2656 }2657 }2658 Instructions.CompAnd = CompAnd;2659 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));2660})(Compilation || (Compilation = {}));2661/// <reference path="../../Helper/Comparison.ts" />2662/// <reference path="../../Helper/Constants.ts" />2663/// <reference path="../../DataStructures/AST.ts" />2664/// <reference path="../../Common/Agent.ts" />2665var Compilation;2666(function (Compilation) {2667 var Instructions;2668 (function (Instructions) {2669 "use strict";2670 var ASTNode = DataStructures.ASTNode;2671 var Constants = Helper.Constants;2672 var Comparison = Helper.Comparison;2673 class CompEquals extends ASTNode {2674 constructor() {2675 super(2, 0); // numArgs = 2, numBranches = 02676 }2677 fn(a, scope, args, rets) {2678 rets[0] = Comparison.equals(args[0], args[1]);2679 rets[1] = Constants.AST_DONE;2680 }2681 to_js_no_yield() {2682 return `2683 Helper.Comparison.equals(${this.args.data[0].to_js_no_yield()}, ${this.args.data[1].to_js_no_yield()})2684 `;2685 }2686 to_js_setup() {2687 return `2688 ${this.args.data[0].to_js_setup()};2689 ${this.args.data[1].to_js_setup()};2690 var __wl_${this.id}_a = ${this.args.data[0].to_js_final()};2691 var __wl_${this.id}_b = ${this.args.data[1].to_js_final()};2692 `;2693 }2694 to_js_final() {2695 return `2696 Helper.Comparison.equals(__wl_${this.id}_a, __wl_${this.id}_b);2697 `;2698 }2699 }2700 Instructions.CompEquals = CompEquals;2701 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));2702})(Compilation || (Compilation = {}));2703/// <reference path="../../Helper/Comparison.ts" />2704/// <reference path="../../Helper/Constants.ts" />2705/// <reference path="../../DataStructures/AST.ts" />2706/// <reference path="../../Common/Agent.ts" />2707var Compilation;2708(function (Compilation) {2709 var Instructions;2710 (function (Instructions) {2711 "use strict";2712 var ASTNode = DataStructures.ASTNode;2713 var Constants = Helper.Constants;2714 var Comparison = Helper.Comparison;2715 class CompNotEquals extends ASTNode {2716 constructor() {2717 super(2, 0); // numArgs = 2, numBranches = 02718 }2719 fn(a, scope, args, rets) {2720 rets[0] = !Comparison.equals(args[0], args[1]);2721 rets[1] = Constants.AST_DONE;2722 }2723 to_js_no_yield() {2724 return `2725 !Helper.Comparison.equals(${this.args.data[0].to_js_no_yield()}, ${this.args.data[1].to_js_no_yield()})2726 `;2727 }2728 to_js_setup() {2729 return `2730 ${this.args.data[0].to_js_setup()};2731 ${this.args.data[1].to_js_setup()};2732 var __wl_${this.id}_a = ${this.args.data[0].to_js_final()};2733 var __wl_${this.id}_b = ${this.args.data[1].to_js_final()};2734 `;2735 }2736 to_js_final() {2737 return `2738 !Helper.Comparison.equals(__wl_${this.id}_a, __wl_${this.id}_b);2739 `;2740 }2741 }2742 Instructions.CompNotEquals = CompNotEquals;2743 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));2744})(Compilation || (Compilation = {}));2745/// <reference path="../../Helper/Comparison.ts" />2746/// <reference path="../../Helper/Constants.ts" />2747/// <reference path="../../DataStructures/AST.ts" />2748/// <reference path="../../Common/Agent.ts" />2749var Compilation;2750(function (Compilation) {2751 var Instructions;2752 (function (Instructions) {2753 "use strict";2754 var ASTNode = DataStructures.ASTNode;2755 var Comparison = Helper.Comparison;2756 var Constants = Helper.Constants;2757 class CompGreaterThan extends ASTNode {2758 constructor() {2759 super(2, 0); // numArgs = 2, numBranches = 02760 }2761 fn(a, scope, args, rets) {2762 var c1 = args[0];2763 var c2 = args[1];2764 rets[0] = Comparison.gt(c1, c2);2765 rets[1] = Constants.AST_DONE;2766 }2767 to_js_no_yield() {2768 return `2769 Helper.Comparison.gt(${this.args.data[0].to_js_no_yield()}, ${this.args.data[1].to_js_no_yield()})2770 `;2771 }2772 to_js_setup() {2773 return `2774 ${this.args.data[0].to_js_setup()};2775 ${this.args.data[1].to_js_setup()};2776 var __wl_${this.id}_a = ${this.args.data[0].to_js_final()};2777 var __wl_${this.id}_b = ${this.args.data[1].to_js_final()};2778 `;2779 }2780 to_js_final() {2781 return `2782 Helper.Comparison.gt(__wl_${this.id}_a, __wl_${this.id}_b)2783 `;2784 }2785 }2786 Instructions.CompGreaterThan = CompGreaterThan;2787 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));2788})(Compilation || (Compilation = {}));2789/// <reference path="../../Helper/Comparison.ts" />2790/// <reference path="../../Helper/Constants.ts" />2791/// <reference path="../../DataStructures/AST.ts" />2792/// <reference path="../../Common/Agent.ts" />2793var Compilation;2794(function (Compilation) {2795 var Instructions;2796 (function (Instructions) {2797 "use strict";2798 var ASTNode = DataStructures.ASTNode;2799 var Comparison = Helper.Comparison;2800 var Constants = Helper.Constants;2801 class CompGreaterThanOrEqualTo extends ASTNode {2802 constructor() {2803 super(2, 0); // numArgs = 2, numBranches = 02804 }2805 fn(a, scope, args, rets) {2806 var c1 = args[0];2807 var c2 = args[1];2808 rets[0] = Comparison.gte(c1, c2);2809 rets[1] = Constants.AST_DONE;2810 }2811 to_js_no_yield() {2812 return `2813 Helper.Comparison.gte(${this.args.data[0].to_js_no_yield()}, ${this.args.data[1].to_js_no_yield()})2814 `;2815 }2816 to_js_setup() {2817 return `2818 ${this.args.data[0].to_js_setup()};2819 ${this.args.data[1].to_js_setup()};2820 var __wl_${this.id}_a = ${this.args.data[0].to_js_final()};2821 var __wl_${this.id}_b = ${this.args.data[1].to_js_final()};2822 `;2823 }2824 to_js_final() {2825 return `2826 Helper.Comparison.gte(__wl_${this.id}_a, __wl_${this.id}_b)2827 `;2828 }2829 }2830 Instructions.CompGreaterThanOrEqualTo = CompGreaterThanOrEqualTo;2831 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));2832})(Compilation || (Compilation = {}));2833/// <reference path="../../Helper/Comparison.ts" />2834/// <reference path="../../Helper/Constants.ts" />2835/// <reference path="../../DataStructures/AST.ts" />2836/// <reference path="../../Common/Agent.ts" />2837var Compilation;2838(function (Compilation) {2839 var Instructions;2840 (function (Instructions) {2841 "use strict";2842 var ASTNode = DataStructures.ASTNode;2843 var Constants = Helper.Constants;2844 var Comparison = Helper.Comparison;2845 class CompLessThan extends ASTNode {2846 constructor() {2847 super(2, 0); // numArgs = 2, numBranches = 02848 }2849 fn(a, scope, args, rets) {2850 var c1 = args[0];2851 var c2 = args[1];2852 rets[0] = Comparison.lt(c1, c2);2853 rets[1] = Constants.AST_DONE;2854 }2855 to_js_no_yield() {2856 return `2857 Helper.Comparison.lt(${this.args.data[0].to_js_no_yield()}, ${this.args.data[1].to_js_no_yield()})2858 `;2859 }2860 to_js_setup() {2861 return `2862 ${this.args.data[0].to_js_setup()};2863 ${this.args.data[1].to_js_setup()};2864 var __wl_${this.id}_a = ${this.args.data[0].to_js_final()};2865 var __wl_${this.id}_b = ${this.args.data[1].to_js_final()};2866 `;2867 }2868 to_js_final() {2869 return `2870 Helper.Comparison.lt(__wl_${this.id}_a, __wl_${this.id}_b)2871 `;2872 }2873 }2874 Instructions.CompLessThan = CompLessThan;2875 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));2876})(Compilation || (Compilation = {}));2877/// <reference path="../../Helper/Constants.ts" />2878/// <reference path="../../Helper/Comparison.ts" />2879/// <reference path="../../DataStructures/AST.ts" />2880/// <reference path="../../Common/Agent.ts" />2881/// <reference path="../../Helper/Comparison.ts" />2882var Compilation;2883(function (Compilation) {2884 var Instructions;2885 (function (Instructions) {2886 "use strict";2887 var ASTNode = DataStructures.ASTNode;2888 var Comparison = Helper.Comparison;2889 var Constants = Helper.Constants;2890 class CompLessThanOrEqualTo extends ASTNode {2891 constructor() {2892 super(2, 0); // numArgs = 2, numBranches = 02893 }2894 fn(a, scope, args, rets) {2895 var c1 = args[0];2896 var c2 = args[1];2897 rets[0] = Comparison.lte(c1, c2);2898 rets[1] = Constants.AST_DONE;2899 }2900 to_js_no_yield() {2901 return `2902 Helper.Comparison.lte(${this.args.data[0].to_js_no_yield()}, ${this.args.data[1].to_js_no_yield()})2903 `;2904 }2905 to_js_setup() {2906 return `2907 ${this.args.data[0].to_js_setup()};2908 ${this.args.data[1].to_js_setup()};2909 var __wl_${this.id}_a = ${this.args.data[0].to_js_final()};2910 var __wl_${this.id}_b = ${this.args.data[1].to_js_final()};2911 `;2912 }2913 to_js_final() {2914 return `2915 Helper.Comparison.lte(__wl_${this.id}_a, __wl_${this.id}_b)2916 `;2917 }2918 }2919 Instructions.CompLessThanOrEqualTo = CompLessThanOrEqualTo;2920 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));2921})(Compilation || (Compilation = {}));2922/// <reference path="../../Helper/Constants.ts" />2923/// <reference path="../../DataStructures/AST.ts" />2924/// <reference path="../../Common/Agent.ts" />2925var Compilation;2926(function (Compilation) {2927 var Instructions;2928 (function (Instructions) {2929 "use strict";2930 var ASTNode = DataStructures.ASTNode;2931 var Constants = Helper.Constants;2932 class CompNot extends ASTNode {2933 constructor() {2934 super(1, 0); // numArgs = 1, numBranches = 02935 }2936 fn(a, scope, args, rets) {2937 rets[0] = Boolean(!args[0]);2938 rets[1] = Constants.AST_DONE;2939 }2940 to_js_no_yield() {2941 return `2942 !Boolean(${this.args.data[0].to_js_final()})2943 `;2944 }2945 to_js_setup() {2946 return `2947 ${this.args.data[0].to_js_setup()};2948 var __wl_${this.id}_b = Boolean(${this.args.data[0].to_js_final()});2949 `;2950 }2951 to_js_final() {2952 return `2953 !__wl_${this.id}_b2954 `;2955 }2956 }2957 Instructions.CompNot = CompNot;2958 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));2959})(Compilation || (Compilation = {}));2960/// <reference path="../../Helper/Constants.ts" />2961/// <reference path="../../DataStructures/AST.ts" />2962/// <reference path="../../Common/Agent.ts" />2963var Compilation;2964(function (Compilation) {2965 var Instructions;2966 (function (Instructions) {2967 "use strict";2968 var ASTNode = DataStructures.ASTNode;2969 var Constants = Helper.Constants;2970 class CompOr extends ASTNode {2971 constructor() {2972 super(2, 0); // numArgs = 2, numBranches = 02973 }2974 fn(a, scope, args, rets) {2975 rets[0] = args[0] || args[1];2976 rets[1] = Constants.AST_DONE;2977 }2978 to_js_no_yield() {2979 return `2980 (${this.args.data[0].to_js_no_yield()} || ${this.args.data[1].to_js_no_yield()})2981 `;2982 }2983 to_js_setup() {2984 // Short circuit evaluation of the second parameter if the first is true2985 return `2986 ${this.args.data[0].to_js_setup()};2987 var __wl_${this.id}_a = ${this.args.data[0].to_js_final()};2988 var __wl_${this.id}_b;2989 if (!__wl_${this.id}_a) {2990 ${this.args.data[1].to_js_setup()};2991 __wl_${this.id}_b = ${this.args.data[1].to_js_final()};2992 }2993 `;2994 }2995 to_js_final() {2996 return `2997 __wl_${this.id}_a || __wl_${this.id}_b2998 `;2999 }3000 }3001 Instructions.CompOr = CompOr;3002 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));3003})(Compilation || (Compilation = {}));3004/// <reference path="../../Helper/Constants.ts" />3005/// <reference path="../../DataStructures/AST.ts" />3006/// <reference path="../../Common/Agent.ts" />3007var Compilation;3008(function (Compilation) {3009 var Instructions;3010 (function (Instructions) {3011 "use strict";3012 var ASTNode = DataStructures.ASTNode;3013 var Constants = Helper.Constants;3014 class ConstantTrue extends ASTNode {3015 constructor() {3016 super(0, 0); // numArgs = 0, numBranches = 03017 }3018 fn(a, scope, args, rets) {3019 rets[0] = true;3020 rets[1] = Constants.AST_DONE;3021 }3022 to_js_no_yield() {3023 return `3024 true3025 `;3026 }3027 to_js_setup() {3028 return ``;3029 }3030 to_js_final() {3031 return `3032 true3033 `;3034 }3035 }3036 Instructions.ConstantTrue = ConstantTrue;3037 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));3038})(Compilation || (Compilation = {}));3039/// <reference path="../../Helper/Constants.ts" />3040/// <reference path="../../DataStructures/AST.ts" />3041/// <reference path="../../Common/Agent.ts" />3042var Compilation;3043(function (Compilation) {3044 var Instructions;3045 (function (Instructions) {3046 "use strict";3047 var ASTNode = DataStructures.ASTNode;3048 var Constants = Helper.Constants;3049 class ConstantFalse extends ASTNode {3050 constructor() {3051 super(0, 0); // numArgs = 0, numBranches = 03052 }3053 fn(a, scope, args, rets) {3054 rets[0] = false;3055 rets[1] = Constants.AST_DONE;3056 }3057 to_js_no_yield() {3058 return `3059 false3060 `;3061 }3062 to_js_setup() {3063 return ``;3064 }3065 to_js_final() {3066 return `3067 false3068 `;3069 }3070 }3071 Instructions.ConstantFalse = ConstantFalse;3072 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));3073})(Compilation || (Compilation = {}));3074/// <reference path="../../Helper/Constants.ts" />3075/// <reference path="../../DataStructures/AST.ts" />3076/// <reference path="../../Common/Agent.ts" />3077var Compilation;3078(function (Compilation) {3079 var Instructions;3080 (function (Instructions) {3081 "use strict";3082 var ASTNode = DataStructures.ASTNode;3083 var Constants = Helper.Constants;3084 class ConstantPi extends ASTNode {3085 constructor() {3086 super(0, 0); // numArgs = 0, numBranches = 03087 }3088 fn(_, scope, args, rets) {3089 rets[0] = Math.PI;3090 rets[1] = Constants.AST_DONE;3091 }3092 to_js_no_yield() {3093 return `3094 Math.PI3095 `;3096 }3097 to_js_setup() {3098 return ``;3099 }3100 to_js_final() {3101 return `3102 Math.PI3103 `;3104 }3105 }3106 Instructions.ConstantPi = ConstantPi;3107 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));3108})(Compilation || (Compilation = {}));3109/// <reference path="../../Helper/Constants.ts" />3110/// <reference path="../../DataStructures/AST.ts" />3111/// <reference path="../../Common/Agent.ts" />3112/// <reference path="../../dts/viewport.d.ts" />3113var Compilation;3114(function (Compilation) {3115 var Instructions;3116 (function (Instructions) {3117 "use strict";3118 var ASTNode = DataStructures.ASTNode;3119 var Constants = Helper.Constants;3120 class CameraTake extends ASTNode {3121 constructor() {3122 super(0, 0); // numArgs = 0, numBranches = 03123 }3124 fn(a, scope, args, rets) {3125 rets[0] = undefined;3126 rets[1] = Constants.AST_DONE;3127 viewport.setCameraAgent(a.state, a.prevState);3128 }3129 to_js_no_yield() {3130 return `3131 __wl_agt.hasCamera = true;3132 viewport.setCameraAgent(__wl_agt.state, __wl_agt.prevState);3133 `;3134 }3135 to_js_setup() {3136 return `3137 `;3138 }3139 to_js_final() {3140 return `3141 __wl_agt.hasCamera = true;3142 viewport.setCameraAgent(__wl_agt.state, __wl_agt.prevState);3143 `;3144 }3145 }3146 Instructions.CameraTake = CameraTake;3147 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));3148})(Compilation || (Compilation = {}));3149/// <reference path="../Common/Agent.ts" />3150/// <reference path="../Helper/Logger.ts" />3151var DataStructures;3152(function (DataStructures) {3153 "use strict";3154 var Logger = Helper.Logger;3155 class CollisionPair {3156 constructor(agentA, agentB) {3157 this.a = agentA;3158 this.b = agentB;3159 DataStructures.CollisionPair.existingPairs.get(this.a.id).set(this.b.id, this);3160 }3161 static findOrCreate(agentA, agentB) {3162 var a, b;3163 try {3164 if (agentA === agentB) {3165 throw new Error;3166 }3167 }3168 catch (e) {3169 Logger.error("Agent cannot collide with itself: ");3170 Logger.error(e.stack);3171 }3172 if (agentA.id < agentB.id) {3173 a = agentA;3174 b = agentB;3175 }3176 else if (agentB.id < agentA.id) {3177 a = agentB;3178 b = agentA;3179 }3180 // check to see if this pair has already been created.3181 // if so, return that existing object rather than3182 // creating a new one.3183 // if no, create the new one and save it before returning.3184 if (!DataStructures.CollisionPair.existingPairs.has(a.id)) {3185 DataStructures.CollisionPair.existingPairs.set(a.id, new Map());3186 }3187 var candidatePairs = DataStructures.CollisionPair.existingPairs.get(a.id);3188 if (candidatePairs.has(b.id)) {3189 return candidatePairs.get(b.id);3190 }3191 else {3192 return new DataStructures.CollisionPair(a, b);3193 }3194 }3195 /**3196 * returns true if the two pairs have the same elements3197 */3198 static equals(cp1, cp2) {3199 return ((cp1.a === cp2.a) && (cp1.b === cp2.b));3200 }3201 }3202 CollisionPair.existingPairs = new Map();3203 DataStructures.CollisionPair = CollisionPair;3204})(DataStructures || (DataStructures = {}));3205/// <reference path="../Common/Agent.ts" />3206/// <reference path="../Common/Breed.ts" />3207/// <reference path="../Common/State.ts" />3208/// <reference path="../Execution/AgentController.ts" />3209/// <reference path="../DataStructures/CollisionPair.ts" />3210/// <reference path="../Helper/Constants.ts" />3211/// <reference path="../Helper/Logger.ts" />3212/// <reference path="../Helper/Comparison.ts" />3213var Execution;3214(function (Execution) {3215 "use strict";3216 var State = Common.State;3217 var Constants = Helper.Constants;3218 var Comparison = Helper.Comparison;3219 var AgentController = Execution.AgentController;3220 var CollisionPair = DataStructures.CollisionPair;3221 class Collisions {3222 constructor() {3223 throw new Error("Static class cannot be instantiated");3224 }3225 static add(a) {3226 /* tslint:disable no-var-keyword */3227 var radius = a.state.size * .5;3228 var minX = Math.max(0, Math.floor((a.state.x - radius + Constants.MAPSIZE) / Execution.Collisions.binSize));3229 var maxX = Math.min(9, Math.floor((a.state.x + radius + Constants.MAPSIZE) / Execution.Collisions.binSize));3230 var minY = Math.max(0, Math.floor((a.state.y - radius + Constants.MAPSIZE) / Execution.Collisions.binSize));3231 var maxY = Math.min(9, Math.floor((a.state.y + radius + Constants.MAPSIZE) / Execution.Collisions.binSize));3232 for (var x = minX; x <= maxX; x++) {3233 for (var y = minY; y <= maxY; y++) {3234 Execution.Collisions.bins.get(a.breed.id)[x][y].push(a);3235 a.jbins.push([x, y]);3236 }3237 }3238 /* tslint:enable no-var-keyword */3239 }3240 static remove(a) {3241 /* tslint:disable no-var-keyword */3242 for (var i = 0; i < a.jbins.length; i++) {3243 var x = a.jbins[i][0];3244 var y = a.jbins[i][1];3245 var bin = Execution.Collisions.bins.get(a.breed.id)[x][y];3246 bin.splice(bin.indexOf(a), 1);3247 }3248 a.jbins = [];3249 /* tslint:enable no-var-keyword */3250 }3251 static update(a) {3252 Execution.Collisions.remove(a);3253 Execution.Collisions.add(a);3254 }3255 static getCollisions() {3256 /* tslint:disable no-var-keyword */3257 var collisions = [];3258 for (var i = 1; i < AgentController.numAgents; i++) {3259 var a = AgentController.data[i];3260 if (a === undefined || !State.collidingBreeds.has(a.breed.id) || a.isDead) {3261 continue;3262 }3263 for (var j = 0; j < a.jbins.length; j++) {3264 var x = a.jbins[j][0];3265 var y = a.jbins[j][1];3266 var collidedBreeds = State.collidedBreeds.get(a.breed.id);3267 for (var k = 0; k < collidedBreeds.length; k++) {3268 var otherBreed = collidedBreeds[k];3269 var bin = Execution.Collisions.bins.get(otherBreed)[x][y];3270 for (var l = 0; l < bin.length; l++) {3271 var b = bin[l];3272 if (a === b || (a.breed === b.breed && a.id > b.id)) {3273 continue;3274 }3275 var rSq = (a.state.size + b.state.size) * (a.state.size + b.state.size) / 4;3276 var dx = (a.state.x - b.state.x);3277 var dy = (a.state.y - b.state.y);3278 var dz = (a.state.z - b.state.z);3279 if ((dx * dx + dy * dy + dz * dz) < rSq) {3280 collisions.push(CollisionPair.findOrCreate(a, b));3281 }3282 }3283 }3284 }3285 }3286 return collisions;3287 /* tslint:enable no-var-keyword */3288 }3289 static count(a, breedName, radius, trait, val) {3290 /* tslint:disable no-var-keyword */3291 var breedID = AgentController.getByName(breedName).id;3292 var maxSize = 2 * Math.sqrt(2) * Constants.MAPSIZE;3293 if (radius > maxSize) {3294 if (breedID === AgentController.EVERYONE.id) {3295 return AgentController.numAgents;3296 }3297 var count = 0;3298 for (var i = 1; i < AgentController.numAgents; i++) {3299 var agent = AgentController.data[i];3300 if (agent.breed.id == breedID && (!trait || Comparison.equals(agent.getTrait(trait), val))) {3301 count++;3302 }3303 }3304 return count;3305 }3306 if (breedID === AgentController.EVERYONE.id) {3307 return Execution.Collisions.countEveryone(a, radius, trait, val);3308 }3309 var minX = Math.max(0, ~~((a.state.x - radius + Constants.MAPSIZE) / Execution.Collisions.binSize));3310 var maxX = Math.min(9, ~~((a.state.x + radius + Constants.MAPSIZE) / Execution.Collisions.binSize));3311 var minY = Math.max(0, ~~((a.state.y - radius + Constants.MAPSIZE) / Execution.Collisions.binSize));3312 var maxY = Math.min(9, ~~((a.state.y + radius + Constants.MAPSIZE) / Execution.Collisions.binSize));3313 var radiusSq = radius * radius;3314 var results = new Set();3315 var bins = Execution.Collisions.bins.get(breedID);3316 if (minX === maxX && minY === maxY) {3317 var bin = bins[minX][minY];3318 for (var i = 0; i < bin.length; i++) {3319 var b = bin[i];3320 if (!b.isDead && !results.has(b.id) && (!trait || Comparison.equals(b.getTrait(trait), val))) {3321 if (Execution.Collisions.distSq(a, b) <= radiusSq) {3322 results.add(b.id);3323 }3324 }3325 }3326 results.delete(a.id);3327 return results.size;3328 }3329 for (var x = minX; x <= maxX; x++) {3330 for (var y = minY; y <= maxY; y++) {3331 var bin = bins[x][y];3332 for (var i = 0; i < bin.length; i++) {3333 var b = bin[i];3334 if (!b.isDead && !results.has(b.id) && (!trait || Comparison.equals(b.getTrait(trait), val))) {3335 if (Execution.Collisions.distSq(a, b) <= radiusSq) {3336 results.add(b.id);3337 }3338 }3339 }3340 }3341 }3342 results.delete(a.id);3343 return results.size;3344 /* tslint:enable no-var-keyword */3345 }3346 static countEveryone(a, radius, trait, val) {3347 /* tslint:disable no-var-keyword */3348 var breedIDs = AgentController.getBreedIDs();3349 var results = new Set();3350 var minX = Math.max(0, Math.floor((a.state.x - radius + Constants.MAPSIZE) / Execution.Collisions.binSize));3351 var maxX = Math.min(9, Math.floor((a.state.x + radius + Constants.MAPSIZE) / Execution.Collisions.binSize));3352 var minY = Math.max(0, Math.floor((a.state.y - radius + Constants.MAPSIZE) / Execution.Collisions.binSize));3353 var maxY = Math.min(9, Math.floor((a.state.y + radius + Constants.MAPSIZE) / Execution.Collisions.binSize));3354 for (var i = 0; i < breedIDs.length; i++) {3355 var bid = breedIDs[i];3356 for (var x = minX; x <= maxX; x++) {3357 for (var y = minY; y <= maxY; y++) {3358 var bin = Execution.Collisions.bins.get(bid)[x][y];3359 for (var i = 0; i < bin.length; i++) {3360 var b = bin[i];3361 if (!results.has(b.id) && !b.isDead && (!trait || Comparison.equals(b.getTrait(trait), val))) {3362 if (Execution.Collisions.distSq(a, b) <= radius * radius) {3363 results.add(b.id);3364 }3365 }3366 }3367 }3368 }3369 }3370 results.delete(a.id);3371 return results.size;3372 /* tslint:enable no-var-keyword */3373 }3374 static nearest(a, breedName, radius, trait, val) {3375 var breedID = AgentController.getByName(breedName).id;3376 // search in concentric squares centered at a for nearest agent3377 var nLevels = Math.ceil(radius / Execution.Collisions.binSize);3378 var centerX = Math.round((a.state.x + Constants.MAPSIZE) / Execution.Collisions.binSize);3379 var centerY = Math.round((a.state.y + Constants.MAPSIZE) / Execution.Collisions.binSize);3380 var breedIDs;3381 if (breedID === AgentController.EVERYONE.id) {3382 breedIDs = AgentController.getBreedIDs();3383 }3384 else {3385 breedIDs = [breedID];3386 }3387 var bestAgent = undefined;3388 var bestDistSq = Infinity;3389 for (var i = 0; i < nLevels; i++) {3390 for (var j = 0; j < breedIDs.length; j++) {3391 var bid = breedIDs[j];3392 for (var x = Math.max(0, centerX - i); x <= Math.min(9, centerX + i); x++) {3393 for (var y = Math.max(0, centerY - i); y <= Math.min(9, centerY + i); y++) {3394 var bin = Execution.Collisions.bins.get(bid)[x][y];3395 for (var j = 0; j < bin.length; j++) {3396 var b = bin[j];3397 if (a !== b && bestAgent !== b && !b.isDead && (!trait || Comparison.equals(b.getTrait(trait), val))) {3398 var distSq = Execution.Collisions.distSq(a, b);3399 if (distSq < bestDistSq) {3400 bestAgent = b;3401 bestDistSq = distSq;3402 }3403 }3404 }3405 }3406 }3407 }3408 }3409 if (bestAgent !== undefined) {3410 return bestAgent;3411 }3412 return a;3413 }3414 static empty(breedID) {3415 var bins = Execution.Collisions.bins.get(breedID);3416 for (var i = 0; i < Execution.Collisions.binSize; i++) {3417 for (var j = 0; j < Execution.Collisions.binSize; j++) {3418 if (bins[i][j].length > 0) {3419 return false;3420 }3421 }3422 }3423 return true;3424 }3425 static reset() {3426 for (var bid of AgentController.getBreedIDs()) {3427 var bins = Execution.Collisions.bins.get(bid);3428 for (var i = 0; i < Execution.Collisions.binSize; i++) {3429 for (var j = 0; j < Execution.Collisions.binSize; j++) {3430 if (bins[i][j].length > 0) {3431 bins[i][j] = [];3432 }3433 }3434 }3435 }3436 }3437 static distSq(a, b) {3438 var dx = a.state.x - b.state.x;3439 var dy = a.state.y - b.state.y;3440 var dz = a.state.z - b.state.z;3441 return dx * dx + dy * dy + dz * dz;3442 }3443 }3444 Collisions.bins = new Map();3445 Collisions.binSize = 10;3446 Execution.Collisions = Collisions;3447})(Execution || (Execution = {}));3448/// <reference path="../../Helper/Constants.ts" />3449/// <reference path="../../DataStructures/AST.ts" />3450/// <reference path="../../Common/Agent.ts" />3451/// <reference path="../../Execution/Collisions.ts" />3452var Compilation;3453(function (Compilation) {3454 var Instructions;3455 (function (Instructions) {3456 "use strict";3457 var ASTNode = DataStructures.ASTNode;3458 var Constants = Helper.Constants;3459 var Collisions = Execution.Collisions;3460 class Count extends ASTNode {3461 constructor() {3462 super(2, 0); // numArgs = 2, numBranches = 03463 }3464 fn(a, scope, args, rets) {3465 var nearBreed = String(args[0]);3466 var radius = Number(args[1]);3467 rets[0] = Collisions.count(a, nearBreed, radius);3468 rets[1] = Constants.AST_DONE;3469 }3470 to_js_no_yield() {3471 return `3472 Execution.Collisions.count(__wl_agt, ${this.args.data[0].to_js_no_yield()},3473 ${this.args.data[1].to_js_no_yield()})3474 `;3475 }3476 to_js_setup() {3477 return `3478 ${this.args.data[0].to_js_setup()};3479 ${this.args.data[1].to_js_setup()};3480 var __wl_${this.id}_breed = String(${this.args.data[0].to_js_final()});3481 var __wl_${this.id}_radius = String(${this.args.data[1].to_js_final()});3482 `;3483 }3484 to_js_final() {3485 return `3486 Execution.Collisions.count(__wl_wgt, __wl_${this.id}_breed, __wl_${this.id}_radius)3487 `;3488 }3489 }3490 Instructions.Count = Count;3491 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));3492})(Compilation || (Compilation = {}));3493/// <reference path="../../DataStructures/AST.ts" />3494/// <reference path="../../Common/Agent.ts" />3495/// <reference path="../../Common/Trait.ts" />3496/// <reference path="../../Helper/Logger.ts" />3497var Compilation;3498(function (Compilation) {3499 var Instructions;3500 (function (Instructions) {3501 "use strict";3502 var ASTNode = DataStructures.ASTNode;3503 var Logger = Helper.Logger;3504 class UtilTraitHelper extends ASTNode {3505 traitHelper(a, trait) {3506 switch (trait) {3507 case "x":3508 return a.state.x;3509 case "y":3510 return a.state.y;3511 case "z":3512 return a.state.z;3513 case "color":3514 return a.state.color;3515 case "shape":3516 return a.state.shape;3517 case "heading":3518 return a.state.heading;3519 case "size":3520 return a.state.size;3521 case "breed":3522 return a.breed;3523 case "id":3524 return a.id;3525 default:3526 return this.customTraitHelper(a, trait);3527 }3528 }3529 customTraitHelper(a, trait) {3530 var traitID = a.breed.getTraitID(trait);3531 var value = a.traits[traitID];3532 if (!isNaN(Number(value))) {3533 return Number(value);3534 }3535 return value;3536 }3537 traitSetHelper(a, trait, value) {3538 switch (trait) {3539 case "x":3540 a.safeSetX(Number(value));3541 return;3542 case "y":3543 a.safeSetY(Number(value));3544 return;3545 case "z":3546 a.safeSetZ(Number(value));3547 return;3548 case "color":3549 a.safeSetColor(Number(value));3550 return;3551 case "shape":3552 a.safeSetShape(String(value));3553 return;3554 case "heading":3555 a.safeSetHeading(Number(value));3556 return;3557 case "size":3558 a.safeSetSize(Number(value));3559 return;3560 default:3561 this.customTraitSetHelper(a, trait, value);3562 return;3563 }3564 }3565 customTraitSetHelper(a, trait, value) {3566 var traitID = a.breed.getTraitID(trait);3567 var check = a.traits[traitID];3568 // if the trait exists, set it.3569 if (check !== undefined) {3570 a.setTrait(trait, value);3571 }3572 else {3573 Logger.error(`Trying to set trait <${trait}> of breed <${a.breed}>, but trait doesn't exist!`);3574 a.setTrait(trait, value);3575 }3576 }3577 }3578 Instructions.UtilTraitHelper = UtilTraitHelper;3579 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));3580})(Compilation || (Compilation = {}));3581/// <reference path="../../Helper/Constants.ts" />3582/// <reference path="../../Common/Agent.ts" />3583/// <reference path="../../Execution/Collisions.ts" />3584/// <reference path="UtilTraitHelper.ts" />3585var Compilation;3586(function (Compilation) {3587 var Instructions;3588 (function (Instructions) {3589 "use strict";3590 var Constants = Helper.Constants;3591 var Collisions = Execution.Collisions;3592 class CountWith extends Instructions.UtilTraitHelper {3593 constructor() {3594 super(4, 0); // numArgs = 4, numBranches = 03595 }3596 fn(a, scope, args, rets) {3597 var nearBreed = String(args[0]);3598 var radius = Number(args[1]);3599 var trait = String(args[2]);3600 var withData = args[3];3601 rets[0] = Collisions.count(a, nearBreed, radius, trait, withData);3602 rets[1] = Constants.AST_DONE;3603 }3604 to_js_no_yield() {3605 return `3606 Execution.Collisions.count(__wl_agt,3607 ${this.args.data[0].to_js_no_yield()},3608 ${this.args.data[1].to_js_no_yield()},3609 ${this.args.data[2].to_js_no_yield()},3610 ${this.args.data[3].to_js_no_yield()})3611 `;3612 }3613 to_js_setup() {3614 return `3615 ${this.args.data[0].to_js_setup()};3616 ${this.args.data[1].to_js_setup()};3617 ${this.args.data[2].to_js_setup()};3618 ${this.args.data[3].to_js_setup()};3619 var __wl_${this.id}_breed = String(${this.args.data[0].to_js_final()});3620 var __wl_${this.id}_radius = String(${this.args.data[1].to_js_final()});3621 var __wl_${this.id}_trait = String(${this.args.data[2].to_js_final()});3622 var __wl_${this.id}_with_data = String(${this.args.data[3].to_js_final()});3623 `;3624 }3625 to_js_final() {3626 return `3627 Execution.Collisions.count(__wl_wgt, __wl_${this.id}_breed, __wl_${this.id}_radius,3628 __wl_${this.id}_trait, __wl_${this.id}_with_data)3629 `;3630 }3631 }3632 Instructions.CountWith = CountWith;3633 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));3634})(Compilation || (Compilation = {}));3635/// <reference path="../../DataStructures/AST.ts" />3636/// <reference path="../../Common/Agent.ts" />3637/// <reference path="../../Common/State.ts" />3638var Compilation;3639(function (Compilation) {3640 var Instructions;3641 (function (Instructions) {3642 "use strict";3643 var ASTNode = DataStructures.ASTNode;3644 class DetectCollision extends ASTNode {3645 constructor() {3646 super(1, 1); // numArgs = 1, numBranches = 13647 }3648 fn(a, scope, args, rets) {3649 rets[0] = 0;3650 rets[1] = 0; // take the first branch3651 }3652 to_js_no_yield() {3653 return `3654 ${this.branches[0].to_js()}3655 `;3656 }3657 to_js_setup() {3658 return ``;3659 }3660 to_js_final() {3661 return `3662 ${this.branches[0].to_js()}3663 `;3664 }3665 }3666 Instructions.DetectCollision = DetectCollision;3667 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));3668})(Compilation || (Compilation = {}));3669/// <reference path="../../Helper/Constants.ts" />3670/// <reference path="../../DataStructures/AST.ts" />3671/// <reference path="../../Common/Agent.ts" />3672/// <reference path="../../Execution/Collisions.ts" />3673var Compilation;3674(function (Compilation) {3675 var Instructions;3676 (function (Instructions) {3677 "use strict";3678 var ASTNode = DataStructures.ASTNode;3679 var Constants = Helper.Constants;3680 var Collisions = Execution.Collisions;3681 class DetectNearest extends ASTNode {3682 constructor() {3683 super(2, 0); // numArgs = 2, numBranches = 03684 }3685 fn(a, scope, args, rets) {3686 var nearBreed = String(args[0]);3687 var radius = Number(args[1]);3688 rets[0] = Collisions.nearest(a, nearBreed, radius);3689 rets[1] = Constants.AST_DONE;3690 }3691 to_js_no_yield() {3692 return `3693 Execution.Collisions.nearest(__wl_agt, ${this.args.data[0].to_js_no_yield()},3694 ${this.args.data[1].to_js_no_yield()})3695 `;3696 }3697 to_js_setup() {3698 return `3699 ${this.args.data[0].to_js_setup()};3700 ${this.args.data[1].to_js_setup()};3701 var __wl_${this.id}_breed = String(${this.args.data[0].to_js_final()});3702 var __wl_${this.id}_radius = String(${this.args.data[1].to_js_final()});3703 `;3704 }3705 to_js_final() {3706 return `3707 Execution.Collisions.nearest(__wl_agt, __wl_${this.id}_breed, __wl_${this.id}_radius);3708 `;3709 }3710 }3711 Instructions.DetectNearest = DetectNearest;3712 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));3713})(Compilation || (Compilation = {}));3714/// <reference path="../../Helper/Constants.ts" />3715/// <reference path="../../Common/Agent.ts" />3716/// <reference path="../../Execution/Collisions.ts" />3717/// <reference path="UtilTraitHelper.ts" />3718var Compilation;3719(function (Compilation) {3720 var Instructions;3721 (function (Instructions) {3722 "use strict";3723 var Constants = Helper.Constants;3724 var Collisions = Execution.Collisions;3725 class DetectNearestWith extends Instructions.UtilTraitHelper {3726 constructor() {3727 super(4, 0); // numArgs = 4, numBranches = 03728 }3729 fn(a, scope, args, rets) {3730 var nearBreed = String(args[0]);3731 var radius = Number(args[1]);3732 var trait = String(args[2]);3733 var withData = args[3];3734 rets[0] = Collisions.nearest(a, nearBreed, radius, trait, withData);3735 rets[1] = Constants.AST_DONE;3736 }3737 to_js_no_yield() {3738 return `3739 Execution.Collisions.nearest(__wl_agt,3740 ${this.args.data[0].to_js_no_yield()},3741 ${this.args.data[1].to_js_no_yield()},3742 ${this.args.data[2].to_js_no_yield()},3743 ${this.args.data[3].to_js_no_yield()})3744 `;3745 }3746 to_js_setup() {3747 return `3748 ${this.args.data[0].to_js_setup()};3749 ${this.args.data[1].to_js_setup()};3750 ${this.args.data[2].to_js_setup()};3751 ${this.args.data[3].to_js_setup()};3752 var __wl_${this.id}_breed = String(${this.args.data[0].to_js_final()});3753 var __wl_${this.id}_radius = String(${this.args.data[1].to_js_final()});3754 var __wl_${this.id}_trait = String(${this.args.data[2].to_js_final()});3755 var __wl_${this.id}_with_data = String(${this.args.data[3].to_js_final()});3756 `;3757 }3758 to_js_final() {3759 return `3760 Execution.Collisions.nearest(__wl_agt, __wl_${this.id}_breed, __wl_${this.id}_radius,3761 __wl_${this.id}_trait, __wl_${this.id}_with_data)3762 `;3763 }3764 }3765 Instructions.DetectNearestWith = DetectNearestWith;3766 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));3767})(Compilation || (Compilation = {}));3768/// <reference path="../../Helper/Constants.ts" />3769/// <reference path="../../DataStructures/AST.ts" />3770/// <reference path="../../Common/Agent.ts" />3771var Compilation;3772(function (Compilation) {3773 var Instructions;3774 (function (Instructions) {3775 "use strict";3776 var ASTNode = DataStructures.ASTNode;3777 var Constants = Helper.Constants;3778 class FaceTowards extends ASTNode {3779 constructor() {3780 super(1, 0); // numArgs = 1, numBranches = 03781 }3782 fn(a, scope, args, rets) {3783 var receivedAgent = args[0];3784 var pX = receivedAgent.state.x;3785 var pY = receivedAgent.state.y;3786 if (!(pX === a.state.x && pY === a.state.y)) {3787 a.safeSetHeading(Math.atan2(pY - a.state.y, pX - a.state.x) * 180 / Math.PI);3788 }3789 rets[1] = Constants.AST_DONE;3790 }3791 to_js_no_yield() {3792 return `3793 __wl_agt.faceTowards(${this.args.data[0].to_js_no_yield()})3794 `;3795 }3796 to_js_setup() {3797 return `3798 ${this.args.data[0].to_js_setup()};3799 var __wl_${this.id}_agt = ${this.args.data[0].to_js_final()};3800 `;3801 }3802 to_js_final() {3803 return `3804 __wl_agt.faceTowards(__wl_${this.id}_agt);3805 `;3806 }3807 }3808 Instructions.FaceTowards = FaceTowards;3809 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));3810})(Compilation || (Compilation = {}));3811/// <reference path="../../Common/Agent.ts" />3812/// <reference path="../../DataStructures/AST.ts" />3813/// <reference path="../../Helper/Constants.ts" />3814var Compilation;3815(function (Compilation) {3816 var Instructions;3817 (function (Instructions) {3818 "use strict";3819 var ASTNode = DataStructures.ASTNode;3820 var Constants = Helper.Constants;3821 class GetMyTrait extends ASTNode {3822 constructor() {3823 super(1, 0); // numArgs = 1, numBranches = 03824 }3825 fn(a, scope, args, rets) {3826 var trait = String(args[0]);3827 rets[0] = a.getTrait(trait);3828 rets[1] = Constants.AST_DONE;3829 }3830 to_js_no_yield() {3831 return `3832 __wl_agt.getTrait(${this.args.data[0].to_js_no_yield()})3833 `;3834 }3835 to_js_setup() {3836 return `3837 ${this.args.data[0].to_js_setup()};3838 var __wl_${this.id}_trait = ${this.args.data[0].to_js_final()};3839 `;3840 }3841 to_js_final() {3842 return `3843 __wl_agt.getTrait(__wl_${this.id}_trait);3844 `;3845 }3846 }3847 Instructions.GetMyTrait = GetMyTrait;3848 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));3849})(Compilation || (Compilation = {}));3850/// <reference path="../../Helper/Constants.ts" />3851/// <reference path="../../DataStructures/AST.ts" />3852/// <reference path="../../Common/Agent.ts" />3853var Compilation;3854(function (Compilation) {3855 var Instructions;3856 (function (Instructions) {3857 "use strict";3858 var ASTNode = DataStructures.ASTNode;3859 var Constants = Helper.Constants;3860 class If extends ASTNode {3861 constructor() {3862 super(1, 1); // numArgs = 1, numBranches = 13863 }3864 fn(a, scope, args, rets) {3865 if (args[0]) {3866 rets[1] = 0;3867 }3868 else {3869 rets[1] = Constants.AST_DONE;3870 }3871 }3872 to_js_no_yield() {3873 return `3874 if (${this.args.data[0].to_js_no_yield()}) {3875 ${this.branches[0].to_js()}3876 }3877 `;3878 }3879 to_js_setup() {3880 return `3881 ${this.args.data[0].to_js_setup()};3882 var __wl_${this.id}_cond = ${this.args.data[0].to_js_final()};3883 `;3884 }3885 to_js_final() {3886 return `3887 if (__wl_${this.id}_cond) {3888 ${this.branches[0].to_js()}3889 }3890 `;3891 }3892 }3893 Instructions.If = If;3894 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));3895})(Compilation || (Compilation = {}));3896/// <reference path="../../DataStructures/AST.ts" />3897/// <reference path="../../Common/Agent.ts" />3898var Compilation;3899(function (Compilation) {3900 var Instructions;3901 (function (Instructions) {3902 "use strict";3903 var ASTNode = DataStructures.ASTNode;3904 class IfElse extends ASTNode {3905 constructor() {3906 super(1, 2); // numArgs = 1, numBranches = 23907 }3908 fn(a, scope, args, rets) {3909 if (args[0]) {3910 rets[1] = 0;3911 }3912 else {3913 rets[1] = 1;3914 }3915 }3916 to_js_no_yield() {3917 return `3918 if (${this.args.data[0].to_js_no_yield()}) {3919 ${this.branches[0].to_js()}3920 } else {3921 ${this.branches[1].to_js()}3922 }3923 `;3924 }3925 to_js_setup() {3926 return `3927 ${this.args.data[0].to_js_setup()};3928 var __wl_${this.id}_cond = ${this.args.data[0].to_js_final()};3929 `;3930 }3931 to_js_final() {3932 return `3933 if (__wl_${this.id}_cond) {3934 ${this.branches[0].to_js()}3935 } else {3936 ${this.branches[1].to_js()}3937 }3938 `;3939 }3940 }3941 Instructions.IfElse = IfElse;3942 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));3943})(Compilation || (Compilation = {}));3944var Helper;3945(function (Helper) {3946 "use strict";3947 class KeyManager {3948 static init() {3949 document.getElementById("renderer-canvas").addEventListener("keydown", this.keydownCB);3950 document.getElementById("renderer-canvas").addEventListener("keyup", this.keyupCB);3951 Helper.KeyManager.reset();3952 }3953 // Is the current key of this epoch equal to this key?3954 static isKeyPressed(key) {3955 // In javascript land, the 0th element of an empty array is undefined3956 return Helper.KeyManager.pressedQueue[0] === key;3957 }3958 // Is the key currently held down3959 static isKeyHeld(key) {3960 return Helper.KeyManager.pressedKeys.has(key);3961 }3962 static reset() {3963 Helper.KeyManager.pressedQueue = new Array();3964 Helper.KeyManager.pressedKeys = new Set();3965 }3966 static keypressCB(e) {3967 // pass3968 }3969 static keydownCB(e) {3970 var key = e.keyCode;3971 if (!Helper.KeyManager.pressedKeys.has(key)) {3972 Helper.KeyManager.pressedQueue.push(key);3973 }3974 Helper.KeyManager.pressedKeys.add(key);3975 if (!e.metaKey) {3976 e.preventDefault();3977 }3978 else {3979 // if this keystroke causes a default browser action (like search, bookmark, etc),3980 // we won't receive the keyup event so we manually clear the pressedKeys3981 if (key !== 17 && key !== 18 && key !== 91 && key !== 93 && key !== 224) {3982 setTimeout(function () { KeyManager.pressedKeys.clear(); }, 100);3983 }3984 }3985 }3986 static keyupCB(e) {3987 var key = e.keyCode;3988 Helper.KeyManager.pressedKeys.delete(key);3989 if (!e.metaKey) {3990 e.preventDefault();3991 }3992 }3993 static tick() {3994 Helper.KeyManager.pressedQueue.shift();3995 }3996 }3997 // this is a queue of pressed keys: keydowns get sent here and they get3998 // processed each time tick is called3999 KeyManager.pressedQueue = new Array();4000 // this is a set of keys that are currently pressed4001 KeyManager.pressedKeys = new Set();4002 Helper.KeyManager = KeyManager;4003})(Helper || (Helper = {}));4004/// <reference path="../../Helper/Constants.ts" />4005/// <reference path="../../Helper/KeyManager.ts" />4006/// <reference path="../../DataStructures/AST.ts" />4007/// <reference path="../../Common/Agent.ts" />4008var Compilation;4009(function (Compilation) {4010 var Instructions;4011 (function (Instructions) {4012 "use strict";4013 var ASTNode = DataStructures.ASTNode;4014 var Constants = Helper.Constants;4015 var KeyManager = Helper.KeyManager;4016 class KeyHeld extends ASTNode {4017 constructor() {4018 super(1, 0); // numArgs = 1, numBranches = 04019 }4020 fn(a, scope, args, rets) {4021 var key = Number(args[0]);4022 rets[0] = KeyManager.isKeyHeld(key);4023 rets[1] = Constants.AST_DONE;4024 }4025 to_js_no_yield() {4026 return `4027 Helper.KeyManager.isKeyHeld(Number(${this.args.data[0].to_js_no_yield()}))4028 `;4029 }4030 to_js_setup() {4031 return `4032 ${this.args.data[0].to_js_setup()};4033 var __wl_${this.id}_key = Number(${this.args.data[0].to_js_final()});4034 `;4035 }4036 to_js_final() {4037 return `4038 Helper.KeyManager.isKeyHeld(__wl_${this.id}_key)4039 `;4040 }4041 }4042 Instructions.KeyHeld = KeyHeld;4043 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));4044})(Compilation || (Compilation = {}));4045/// <reference path="../../Helper/Constants.ts" />4046/// <reference path="../../Helper/KeyManager.ts" />4047/// <reference path="../../DataStructures/AST.ts" />4048/// <reference path="../../Common/Agent.ts" />4049var Compilation;4050(function (Compilation) {4051 var Instructions;4052 (function (Instructions) {4053 "use strict";4054 var ASTNode = DataStructures.ASTNode;4055 var Constants = Helper.Constants;4056 var KeyManager = Helper.KeyManager;4057 class KeyTyped extends ASTNode {4058 constructor() {4059 super(1, 0); // numArgs = 1, numBranches = 04060 }4061 fn(a, scope, args, rets) {4062 var key = Number(args[0]);4063 rets[0] = KeyManager.isKeyPressed(key);4064 rets[1] = Constants.AST_DONE;4065 }4066 to_js_no_yield() {4067 return `4068 Helper.KeyManager.isKeyPressed(Number(${this.args.data[0].to_js_no_yield()}))4069 `;4070 }4071 to_js_setup() {4072 return `4073 ${this.args.data[0].to_js_setup()};4074 var __wl_${this.id}_key = Number(${this.args.data[0].to_js_final()});4075 `;4076 }4077 to_js_final() {4078 return `4079 Helper.KeyManager.isKeyPressed(__wl_${this.id}_key)4080 `;4081 }4082 }4083 Instructions.KeyTyped = KeyTyped;4084 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));4085})(Compilation || (Compilation = {}));4086/// <reference path="../../Helper/Constants.ts" />4087/// <reference path="../../DataStructures/AST.ts" />4088/// <reference path="../../Common/Agent.ts" />4089var Compilation;4090(function (Compilation) {4091 var Instructions;4092 (function (Instructions) {4093 "use strict";4094 var ASTNode = DataStructures.ASTNode;4095 var Constants = Helper.Constants;4096 class List extends ASTNode {4097 constructor(numElements) {4098 super(numElements, 0); // numArgs = numElements, numBranches = 04099 }4100 fn(a, scope, args, rets) {4101 // create a shallow copy4102 rets[0] = args.slice(0);4103 rets[1] = Constants.AST_DONE;4104 }4105 to_js_no_yield() {4106 return `4107 ${this.args.data[0].to_js_no_yield()}.slice(0)4108 `;4109 }4110 to_js_setup() {4111 return `4112 ${this.args.data[0].to_js_setup()};4113 var __wl_${this.id}_list = ${this.args.data[0].to_js_final()};4114 `;4115 }4116 to_js_final() {4117 return `4118 __wl_${this.id}_list.slice(0);4119 `;4120 }4121 }4122 Instructions.List = List;4123 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));4124})(Compilation || (Compilation = {}));4125/// <reference path="../../Helper/Constants.ts" />4126/// <reference path="../../DataStructures/AST.ts" />4127/// <reference path="../../Common/Agent.ts" />4128/// <reference path="../../Helper/Comparison.ts" />4129var Compilation;4130(function (Compilation) {4131 var Instructions;4132 (function (Instructions) {4133 "use strict";4134 var ASTNode = DataStructures.ASTNode;4135 var Constants = Helper.Constants;4136 var Comparison = Helper.Comparison;4137 class ListContains extends ASTNode {4138 constructor() {4139 super(2, 0); // numArgs = 2, numBranches = 04140 }4141 fn(a, scope, args, rets) {4142 var list = Array(args[0]);4143 var item = args[1];4144 if (list.indexOf(item) !== -1) {4145 rets[0] = true;4146 }4147 else {4148 rets[0] = false;4149 for (var datum of list) {4150 if (Comparison.equals(datum, item)) {4151 rets[0] = true;4152 break;4153 }4154 }4155 }4156 rets[1] = Constants.AST_DONE;4157 }4158 to_js_no_yield() {4159 return `4160 Helper.Utils.listContains(${this.args.data[0].to_js_no_yield()}, ${this.args.data[1].to_js_no_yield()})4161 `;4162 }4163 to_js_setup() {4164 return `4165 ${this.args.data[0].to_js_setup()};4166 ${this.args.data[1].to_js_setup()};4167 __wl_${this.id}_list = ${this.args.data[0].to_js_final()};4168 __wl_${this.id}_item = ${this.args.data[1].to_js_final()};4169 __wl_${this.id}_ret;4170 if (__wl_${this.id}_list.indexOf(__wl_${this.id}_item) !== -1) {4171 __wl_${this.id}_ret = true;4172 } else {4173 __wl_${this.id}_ret = false;4174 for (var datum of __wl_${this.id}_list) {4175 if (Helper.Comparison.equals(datum, __wl_${this.id}_item)) {4176 __wl_${this.id}_ret = true;4177 break;4178 }4179 }4180 }4181 `;4182 }4183 to_js_final() {4184 return `4185 Helper.Utils.listContains(__wl_${this.id}_list, __wl_${this.id}_item)4186 `;4187 }4188 }4189 Instructions.ListContains = ListContains;4190 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));4191})(Compilation || (Compilation = {}));4192/// <reference path="../../Helper/Constants.ts" />4193/// <reference path="../../DataStructures/AST.ts" />4194/// <reference path="../../Common/Agent.ts" />4195var Compilation;4196(function (Compilation) {4197 var Instructions;4198 (function (Instructions) {4199 "use strict";4200 var ASTNode = DataStructures.ASTNode;4201 var Constants = Helper.Constants;4202 class ListGet extends ASTNode {4203 constructor() {4204 super(2, 0); // numArgs = 2, numBranches = 04205 }4206 fn(a, scope, args, rets) {4207 var list = Array(args[0]);4208 var index = Number(args[1]);4209 rets[0] = list[index];4210 rets[1] = Constants.AST_DONE;4211 }4212 to_js_no_yield() {4213 return `4214 ${this.args.data[0].to_js_no_yield()}[${this.args.data[1].to_js_no_yield()}]4215 `;4216 }4217 to_js_setup() {4218 return `4219 ${this.args.data[0].to_js_setup()};4220 ${this.args.data[1].to_js_setup()};4221 var __wl_${this.id}_list = ${this.args.data[0].to_js_final()};4222 var __wl_${this.id}_idx = ${this.args.data[1].to_js_final()};4223 `;4224 }4225 to_js_final() {4226 return `4227 __wl_${this.id}_list[__wl_${this.id}_idx]4228 `;4229 }4230 }4231 Instructions.ListGet = ListGet;4232 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));4233})(Compilation || (Compilation = {}));4234/// <reference path="../../Helper/Constants.ts" />4235/// <reference path="../../DataStructures/AST.ts" />4236/// <reference path="../../Common/Agent.ts" />4237var Compilation;4238(function (Compilation) {4239 var Instructions;4240 (function (Instructions) {4241 "use strict";4242 var ASTNode = DataStructures.ASTNode;4243 var Constants = Helper.Constants;4244 class ListSplice extends ASTNode {4245 constructor(mode) {4246 super(3, 0); // numArgs = 3, numBranches = 04247 this.mode = mode || Constants.LIST_BEGINNING; // LIST_BEGINNING happens to be 04248 }4249 fn(a, scope, args, rets) {4250 var index = Number(args[0]);4251 var toInsert = Array(args[1]);4252 var listInto = Array(args[2]);4253 if (this.mode === Constants.LIST_BEGINNING) {4254 rets[0] = toInsert.concat(listInto);4255 }4256 else if (this.mode === Constants.LIST_END) {4257 rets[0] = listInto.concat(toInsert);4258 }4259 else {4260 var firstPartInto = listInto;4261 var lastPartInto = firstPartInto.splice(index);4262 var newList = firstPartInto.concat(toInsert);4263 newList = newList.concat(lastPartInto);4264 rets[0] = newList;4265 }4266 rets[1] = Constants.AST_DONE;4267 }4268 to_js_no_yield() {4269 return `4270 Helper.Utils.listSplice(${this.args.data[0].to_js_no_yield()},4271 ${this.args.data[1].to_js_no_yield()},4272 ${this.args.data[2].to_js_no_yield()})4273 `;4274 }4275 to_js_setup() {4276 return `4277 ${this.args.data[0].to_js_setup()};4278 ${this.args.data[1].to_js_setup()};4279 ${this.args.data[2].to_js_setup()};4280 var __wl_${this.id}_idx = ${this.args.data[0].to_js_final()};4281 var __wl_${this.id}_to_insert = ${this.args.data[1].to_js_final()};4282 var __wl_${this.id}_list_into = ${this.args.data[2].to_js_final()};4283 var __wl_${this.id}_ret;4284 if (${this.mode} === ${Constants.LIST_BEGINNING}) {4285 __wl_${this.id}_ret = __wl_${this.id}_to_insert.concat(__wl_${this.id}_list_into);4286 } else if (${this.mode} === ${Constants.LIST_END}) {4287 __wl_${this.id}_ret = __wl_${this.id}_list_into.concat(__wl_${this.id}_to_insert);4288 } else {4289 var __wl_${this.id}_first_part_into = __wl_${this.id}_list_into;4290 var __wl_${this.id}_last_part_into = __wl_${this.id}_first_part_into.splice(__wl_${this.id}_idx);4291 var __wl_${this.id}_new_list = __wl_${this.id}_first_part_into.concat(__wl_${this.id}_to_insert);4292 __wl_${this.id}_ret = __wl_${this.id}_new_list.concat(__wl_${this.id}_last_part_into);4293 }4294 `;4295 }4296 to_js_final() {4297 return `4298 __wl_${this.id}_ret4299 `;4300 }4301 }4302 Instructions.ListSplice = ListSplice;4303 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));4304})(Compilation || (Compilation = {}));4305/// <reference path="../../Helper/Constants.ts" />4306/// <reference path="../../Common/Agent.ts" />4307/// <reference path="ListSplice.ts" />4308var Compilation;4309(function (Compilation) {4310 var Instructions;4311 (function (Instructions) {4312 "use strict";4313 var Constants = Helper.Constants;4314 var ListSplice = Compilation.Instructions.ListSplice;4315 class ListInsert extends ListSplice {4316 fn(a, scope, args, rets) {4317 var index = args[0];4318 var item = args[1];4319 var list = Array(args[2]);4320 if (this.mode === Constants.LIST_BEGINNING) {4321 list.splice(0, 0, item);4322 }4323 else if (this.mode === Constants.LIST_END) {4324 list.splice(list.length, 0, item);4325 }4326 else {4327 list.splice(index, 0, item);4328 }4329 rets[0] = list;4330 rets[1] = Constants.AST_DONE;4331 }4332 to_js_no_yield() {4333 return `4334 Helper.Utils.listInto(${this.args.data[0].to_js_no_yield()},4335 ${this.args.data[1].to_js_no_yield()},4336 ${this.args.data[2].to_js_no_yield()})4337 `;4338 }4339 to_js_setup() {4340 return `4341 ${this.args.data[0].to_js_setup()};4342 ${this.args.data[1].to_js_setup()};4343 ${this.args.data[2].to_js_setup()};4344 var __wl_${this.id}_idx = ${this.args.data[0].to_js_final()};4345 var __wl_${this.id}_item = ${this.args.data[1].to_js_final()};4346 var __wl_${this.id}_list = ${this.args.data[2].to_js_final()};4347 if (${this.mode} === ${Constants.LIST_BEGINNING}) {4348 __wl_${this.id}_list.splice(0, 0, __wl_${this.id}_item);4349 } else if (${this.mode} === ${Constants.LIST_END}) {4350 __wl_${this.id}_list.splice(__wl_${this.id}_list.length, 0, __wl_${this.id}_item);4351 } else {4352 __wl_${this.id}_list.splice(__wl_${this.id}_idx, 0, __wl_${this.id}_item);4353 }4354 `;4355 }4356 to_js_final() {4357 return `4358 __wl_${this.id}_list4359 `;4360 }4361 }4362 Instructions.ListInsert = ListInsert;4363 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));4364})(Compilation || (Compilation = {}));4365/// <reference path="../../Helper/Constants.ts" />4366/// <reference path="../../DataStructures/AST.ts" />4367/// <reference path="../../Common/Agent.ts" />4368var Compilation;4369(function (Compilation) {4370 var Instructions;4371 (function (Instructions) {4372 "use strict";4373 var ASTNode = DataStructures.ASTNode;4374 var Constants = Helper.Constants;4375 class ListLength extends ASTNode {4376 constructor() {4377 super(1, 0); // numArgs = 1, numBranches = 04378 }4379 fn(a, scope, args, rets) {4380 var list = Array(args[0]);4381 rets[0] = list.length;4382 rets[1] = Constants.AST_DONE;4383 }4384 to_js_no_yield() {4385 return `4386 ${this.args.data[0].to_js_no_yield()}.length4387 `;4388 }4389 to_js_setup() {4390 return `4391 ${this.args.data[0].to_js_setup()};4392 __wl_${this.id}_list = ${this.args.data[0].to_js_final()};4393 `;4394 }4395 to_js_final() {4396 return `4397 __wl_${this.id}_list.length4398 `;4399 }4400 }4401 Instructions.ListLength = ListLength;4402 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));4403})(Compilation || (Compilation = {}));4404/// <reference path="../../Helper/Constants.ts" />4405/// <reference path="../../DataStructures/AST.ts" />4406/// <reference path="../../Common/Agent.ts" />4407var Compilation;4408(function (Compilation) {4409 var Instructions;4410 (function (Instructions) {4411 "use strict";4412 var ASTNode = DataStructures.ASTNode;4413 var Constants = Helper.Constants;4414 class LoopRepeat extends ASTNode {4415 constructor() {4416 super(1, 1); // numArgs = 1, numBranches = 14417 }4418 fn(a, scope, args, rets) {4419 rets[0] = args[0];4420 if (args[0] > 0) {4421 rets[1] = Constants.AST_REPEAT;4422 }4423 else {4424 rets[1] = Constants.AST_DONE;4425 }4426 }4427 to_js_no_yield() {4428 return `4429 var __wl_${this.id}_num_iters = ${this.args.data[0].to_js_no_yield()};4430 for (var __wl_${this.id}_i = 0; __wl_${this.id}_i < __wl_${this.id}_num_iters; __wl_${this.id}_i++) {4431 ${this.branches[0].to_js()};4432 }4433 `;4434 }4435 to_js_setup() {4436 return `4437 ${this.args.data[0].to_js_setup()};4438 var __wl_${this.id}_num_iters = ${this.args.data[0].to_js_final()};4439 `;4440 }4441 to_js_final() {4442 return `4443 for (var __wl_loop_i = 0; __wl_loop_i < __wl_${this.id}_num_iters; __wl_loop_i++) {4444 ${this.branches[0].to_js()}4445 }4446 `;4447 }4448 }4449 Instructions.LoopRepeat = LoopRepeat;4450 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));4451})(Compilation || (Compilation = {}));4452/// <reference path="../../Helper/Constants.ts" />4453/// <reference path="../../DataStructures/AST.ts" />4454/// <reference path="../../Common/Agent.ts" />4455var Compilation;4456(function (Compilation) {4457 var Instructions;4458 (function (Instructions) {4459 "use strict";4460 var ASTNode = DataStructures.ASTNode;4461 var Constants = Helper.Constants;4462 class LoopWhile extends ASTNode {4463 constructor() {4464 super(1, 1); // numArgs = 1, numBranches = 14465 }4466 fn(a, scope, args, rets) {4467 rets[0] = -1; // signal that we don't want to stop looping after a definite number of times4468 if (args[0]) {4469 rets[1] = Constants.AST_REPEAT;4470 }4471 else {4472 rets[1] = Constants.AST_DONE;4473 }4474 }4475 to_js_no_yield() {4476 return `4477 while (${this.args.data[0].to_js_no_yield()}) {4478 ${this.branches[0].to_js()}4479 }4480 `;4481 }4482 to_js_setup() {4483 return ``;4484 }4485 to_js_final() {4486 return `4487 while (true) {4488 ${this.args.data[0].to_js_setup()};4489 if (!${this.args.data[0].to_js_final()}) {4490 break;4491 }4492 ${this.branches[0].to_js()}4493 }4494 `;4495 }4496 }4497 Instructions.LoopWhile = LoopWhile;4498 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));4499})(Compilation || (Compilation = {}));4500/// <reference path="../../Helper/Constants.ts" />4501/// <reference path="../../DataStructures/AST.ts" />4502/// <reference path="../../Common/Agent.ts" />4503var Compilation;4504(function (Compilation) {4505 var Instructions;4506 (function (Instructions) {4507 "use strict";4508 var ASTNode = DataStructures.ASTNode;4509 var Constants = Helper.Constants;4510 class MoveForward extends ASTNode {4511 constructor() {4512 super(1, 0); // numArgs = 1, numBranches = 04513 }4514 fn(a, scope, args, rets) {4515 var amount = Number(args[0]);4516 a.moveForward(amount);4517 rets[1] = Constants.AST_DONE;4518 }4519 to_js_no_yield() {4520 return `4521 __wl_agt.moveForward(${this.args.data[0].to_js_no_yield()});4522 `;4523 }4524 to_js_setup() {4525 return `4526 ${this.args.data[0].to_js_setup()};4527 var __wl_${this.id}_amount = ${this.args.data[0].to_js_final()};4528 `;4529 }4530 to_js_final() {4531 return `4532 __wl_agt.moveForward(${this.args.data[0].to_js_no_yield()});4533 `;4534 }4535 }4536 Instructions.MoveForward = MoveForward;4537 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));4538})(Compilation || (Compilation = {}));4539/// <reference path="../../Common/Agent.ts" />4540/// <reference path="../../Helper/Constants.ts" />4541/// <reference path="MoveForward.ts" />4542var Compilation;4543(function (Compilation) {4544 var Instructions;4545 (function (Instructions) {4546 "use strict";4547 var Constants = Helper.Constants;4548 var MoveForward = Compilation.Instructions.MoveForward;4549 class MoveBackward extends MoveForward {4550 fn(a, scope, args, rets) {4551 var amount = Number(args[0]);4552 a.moveForward(-amount);4553 rets[1] = Constants.AST_DONE;4554 }4555 to_js_no_yield() {4556 return `4557 __wl_agt.moveForward(-${this.args.data[0].to_js_no_yield()})4558 `;4559 }4560 to_js_setup() {4561 return `4562 ${this.args.data[0].to_js_setup()};4563 var __wl_${this.id}_amount = ${this.args.data[0].to_js_final()};4564 `;4565 }4566 to_js_final() {4567 return `4568 __wl_agt.moveForward(-${this.args.data[0].to_js_no_yield()})4569 `;4570 }4571 }4572 Instructions.MoveBackward = MoveBackward;4573 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));4574})(Compilation || (Compilation = {}));4575/// <reference path="../../Helper/Constants.ts" />4576/// <reference path="../../DataStructures/AST.ts" />4577/// <reference path="../../Common/Agent.ts" />4578var Compilation;4579(function (Compilation) {4580 var Instructions;4581 (function (Instructions) {4582 "use strict";4583 var ASTNode = DataStructures.ASTNode;4584 var Constants = Helper.Constants;4585 class MoveDown extends ASTNode {4586 constructor() {4587 super(1, 0); // numArgs = 1, numBranches = 04588 }4589 fn(a, scope, args, rets) {4590 a.safeSetZ(a.state.z - args[0]);4591 rets[1] = Constants.AST_DONE;4592 }4593 to_js_no_yield() {4594 return `4595 __wl_agt.safeSetZ(__wl_agt.state.z - ${this.args.data[0].to_js_no_yield()})4596 `;4597 }4598 to_js_setup() {4599 return `4600 ${this.args.data[0].to_js_setup()};4601 var __wl_${this.id}_amt = ${this.args.data[0].to_js_final()};4602 `;4603 }4604 to_js_final() {4605 return `4606 __wl_agt.safeSetZ(__wl_agt.state.z - __wl_${this.id}_amt);4607 `;4608 }4609 }4610 Instructions.MoveDown = MoveDown;4611 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));4612})(Compilation || (Compilation = {}));4613/// <reference path="../../Helper/Constants.ts" />4614/// <reference path="../../DataStructures/AST.ts" />4615/// <reference path="../../Common/Agent.ts" />4616var Compilation;4617(function (Compilation) {4618 var Instructions;4619 (function (Instructions) {4620 "use strict";4621 var ASTNode = DataStructures.ASTNode;4622 var Constants = Helper.Constants;4623 class MoveLeft extends ASTNode {4624 constructor() {4625 super(1, 0); // numArgs = 1, numBranches = 04626 }4627 fn(a, scope, args, rets) {4628 a.safeSetHeading(a.state.heading + args[0]);4629 rets[1] = Constants.AST_DONE;4630 }4631 to_js_no_yield() {4632 return `4633 __wl_agt.safeSetHeading(__wl_agt.state.heading + ${this.args.data[0].to_js_no_yield()})4634 `;4635 }4636 to_js_setup() {4637 return `4638 ${this.args.data[0].to_js_setup()};4639 var __wl_${this.id}_amt = ${this.args.data[0].to_js_final()};4640 `;4641 }4642 to_js_final() {4643 return `4644 __wl_agt.safeSetHeading(__wl_agt.state.heading + __wl_${this.id}_amt);4645 `;4646 }4647 }4648 Instructions.MoveLeft = MoveLeft;4649 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));4650})(Compilation || (Compilation = {}));4651/// <reference path="../../Helper/Constants.ts" />4652/// <reference path="../../DataStructures/AST.ts" />4653/// <reference path="../../Common/Agent.ts" />4654var Compilation;4655(function (Compilation) {4656 var Instructions;4657 (function (Instructions) {4658 "use strict";4659 var ASTNode = DataStructures.ASTNode;4660 var Constants = Helper.Constants;4661 class MoveRight extends ASTNode {4662 constructor() {4663 super(1, 0); // numArgs = 1, numBranches = 04664 }4665 fn(a, scope, args, rets) {4666 a.safeSetHeading(a.state.heading - args[0]);4667 rets[1] = Constants.AST_DONE;4668 }4669 to_js_no_yield() {4670 return `4671 __wl_agt.safeSetHeading(__wl_agt.state.heading - ${this.args.data[0].to_js_no_yield()})4672 `;4673 }4674 to_js_setup() {4675 return `4676 ${this.args.data[0].to_js_setup()};4677 var __wl_${this.id}_amt = ${this.args.data[0].to_js_final()};4678 `;4679 }4680 to_js_final() {4681 return `4682 __wl_agt.safeSetHeading(__wl_agt.state.heading - __wl_${this.id}_amt);4683 `;4684 }4685 }4686 Instructions.MoveRight = MoveRight;4687 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));4688})(Compilation || (Compilation = {}));4689/// <reference path="../../Helper/Constants.ts" />4690/// <reference path="../../DataStructures/AST.ts" />4691/// <reference path="../../Common/Agent.ts" />4692var Compilation;4693(function (Compilation) {4694 var Instructions;4695 (function (Instructions) {4696 "use strict";4697 var ASTNode = DataStructures.ASTNode;4698 var Constants = Helper.Constants;4699 class MoveTeleport extends ASTNode {4700 constructor() {4701 super(3, 0); // numArgs = 3, numBranches = 04702 }4703 fn(a, scope, args, rets) {4704 var x = Number(args[0]);4705 var y = Number(args[1]);4706 var z = Number(args[2]);4707 a.safeSetX(x);4708 a.safeSetY(y);4709 a.safeSetZ(z);4710 a.prevState = a.state.copy();4711 rets[1] = Constants.AST_DONE;4712 }4713 to_js_no_yield() {4714 return `4715 __wl_agt.prevState = __wl_agt.state.copy();4716 __wl_agt.safeSetX(${this.args.data[0].to_js_no_yield()});4717 __wl_agt.safeSetY(${this.args.data[1].to_js_no_yield()});4718 __wl_agt.safeSetZ(${this.args.data[2].to_js_no_yield()});4719 `;4720 }4721 to_js_setup() {4722 return `4723 ${this.args.data[0].to_js_setup()};4724 ${this.args.data[1].to_js_setup()};4725 ${this.args.data[2].to_js_setup()};4726 var __wl_${this.id}_x = ${this.args.data[0].to_js_final()};4727 var __wl_${this.id}_y = ${this.args.data[1].to_js_final()};4728 var __wl_${this.id}_z = ${this.args.data[2].to_js_final()};4729 `;4730 }4731 to_js_final() {4732 return `4733 __wl_agt.safeSetX(__wl_${this.id}_x);4734 __wl_agt.safeSetY(__wl_${this.id}_y);4735 __wl_agt.safeSetZ(__wl_${this.id}_z);4736 __wl_agt.prevState = __wl_agt.state.copy();4737 `;4738 }4739 }4740 Instructions.MoveTeleport = MoveTeleport;4741 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));4742})(Compilation || (Compilation = {}));4743/// <reference path="../../Helper/Constants.ts" />4744/// <reference path="../../DataStructures/AST.ts" />4745/// <reference path="../../Common/Agent.ts" />4746var Compilation;4747(function (Compilation) {4748 var Instructions;4749 (function (Instructions) {4750 "use strict";4751 var ASTNode = DataStructures.ASTNode;4752 var Constants = Helper.Constants;4753 class MoveUp extends ASTNode {4754 constructor() {4755 super(1, 0); // numArgs = 1, numBranches = 04756 }4757 fn(a, scope, args, rets) {4758 a.safeSetZ(a.state.z + args[0]);4759 rets[1] = Constants.AST_DONE;4760 }4761 to_js_no_yield() {4762 return `4763 __wl_agt.safeSetZ(__wl_agt.state.z + ${this.args.data[0].to_js_no_yield()})4764 `;4765 }4766 to_js_setup() {4767 return `4768 ${this.args.data[0].to_js_setup()};4769 var __wl_${this.id}_amt = ${this.args.data[0].to_js_final()};4770 `;4771 }4772 to_js_final() {4773 return `4774 __wl_agt.safeSetZ(__wl_agt.state.z + __wl_${this.id}_amt);4775 `;4776 }4777 }4778 Instructions.MoveUp = MoveUp;4779 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));4780})(Compilation || (Compilation = {}));4781/// <reference path="../../Helper/Constants.ts" />4782/// <reference path="../../Helper/Logger.ts" />4783/// <reference path="../../DataStructures/AST.ts" />4784/// <reference path="../../Common/Agent.ts" />4785var Compilation;4786(function (Compilation) {4787 var Instructions;4788 (function (Instructions) {4789 "use strict";4790 var ASTNode = DataStructures.ASTNode;4791 var Constants = Helper.Constants;4792 var Logger = Helper.Logger;4793 class PrintToJSConsole extends ASTNode {4794 constructor() {4795 super(1, 0); // numArgs = 1, numBranches = 04796 }4797 fn(a, scope, args, rets) {4798 Logger.mustLog(args[0]);4799 rets[1] = Constants.AST_DONE;4800 }4801 to_js_no_yield() {4802 return `4803 Logger.mustLog(${this.args.data[0].to_js_no_yield()})4804 `;4805 }4806 to_js_setup() {4807 return `4808 ${this.args.data[0].to_js_setup()};4809 var __wl_${this.id}_print = ${this.args.data[0].to_js_final()};4810 `;4811 }4812 to_js_final() {4813 return `4814 Logger.mustLog(__wl_${this.id}_print);4815 `;4816 }4817 }4818 Instructions.PrintToJSConsole = PrintToJSConsole;4819 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));4820})(Compilation || (Compilation = {}));4821/// <reference path="../../Helper/Constants.ts" />4822/// <reference path="../../DataStructures/AST.ts" />4823/// <reference path="../../Common/Agent.ts" />4824/// <reference path="../../Common/Procedure.ts" />4825/// <reference path="../../Common/State.ts" />4826var Compilation;4827(function (Compilation) {4828 var Instructions;4829 (function (Instructions) {4830 "use strict";4831 var ASTNode = DataStructures.ASTNode;4832 var State = Common.State;4833 var Procedure = Common.Procedure;4834 var Constants = Helper.Constants;4835 class ProcCall extends ASTNode {4836 constructor() {4837 super(1, 0); // numArgs = 1, numBranches = 04838 }4839 can_yield(procs) {4840 // Arg 0 must be a UtilEvalData so we know its value at compile time4841 var procName = String(this.args.data[0].getData());4842 if (procs.has(procName)) {4843 return false;4844 }4845 else {4846 procs.add(procName);4847 return State.procedureRoots.get(procName).can_yield(procs);4848 }4849 }4850 fn(a, scope, args, rets) {4851 rets[0] = args[0];4852 rets[1] = Constants.AST_PROC_CALL;4853 }4854 to_js_no_yield() {4855 var fname = String(this.args.data[0].getData());4856 var params = Procedure.getByName(fname).params;4857 var args = new Array();4858 for (var i = 0; i < params.length; i++) {4859 args.push(",");4860 args.push(`${this.args.data[i + 1].to_js_no_yield()}`);4861 }4862 return `4863 Common.State.procedureFunctions.get("${fname}")(__wl_agt, __wl_thd ${args.join("")})4864 `;4865 }4866 to_js_setup() {4867 var setups = [];4868 var finals = [];4869 for (var i = 0; i < this.args.data.length - 1; i++) {4870 setups[i] = this.args.data[i + 1].to_js_setup();4871 finals[i] = `let __wl_${this.id}_param_val_${i} = ${this.args.data[i + 1].to_js_final()}`;4872 }4873 var fname = String(this.args.data[0].getData());4874 var params = Procedure.getByName(fname).params;4875 var args = new Array();4876 for (var i = 0; i < params.length; i++) {4877 args.push(",");4878 args.push(`__wl_${this.id}_param_val_${i}`);4879 }4880 return `4881 ${this.args.data[0].to_js_setup()};4882 ${setups.join("; ")};4883 ${finals.join("; ")};4884 var __wl_${this.id}_fn_name = ${this.args.data[0].to_js_final()};4885 var __wl_${this.id}_fn = Common.State.procedureGenerators.get(__wl_${this.id}_fn_name);4886 var __wl_${this.id}_gen = __wl_${this.id}_fn(__wl_agt, __wl_thd ${args.join("")});4887 var __wl_${this.id}_ret;4888 while (true) {4889 var iterRes = __wl_${this.id}_gen.next();4890 if (iterRes.done) {4891 __wl_${this.id}_ret = iterRes.value;4892 break;4893 }4894 yield "${Constants.YIELD_NORMAL}";4895 }4896 `;4897 }4898 to_js_final() {4899 return `4900 __wl_${this.id}_ret;4901 `;4902 }4903 }4904 Instructions.ProcCall = ProcCall;4905 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));4906})(Compilation || (Compilation = {}));4907/// <reference path="../../Helper/Constants.ts" />4908/// <reference path="../../DataStructures/AST.ts" />4909/// <reference path="../../Common/Agent.ts" />4910/// <reference path="../../Common/Procedure.ts" />4911var Compilation;4912(function (Compilation) {4913 var Instructions;4914 (function (Instructions) {4915 "use strict";4916 var ASTNode = DataStructures.ASTNode;4917 var Procedure = Common.Procedure;4918 var Constants = Helper.Constants;4919 class ProcParam extends ASTNode {4920 constructor() {4921 super(1, 0); // numArgs = 1, numBranches = 04922 }4923 fn(a, scope, args, rets) {4924 var paramName = String(args[0]);4925 rets[0] = scope.get(paramName);4926 rets[1] = Constants.AST_DONE;4927 }4928 to_js_no_yield() {4929 var params = Procedure.getByName(this.procName).params;4930 var paramName = String(this.args.data[0].getData());4931 var index = params.indexOf(paramName);4932 return `4933 __wl_param_${index}4934 `;4935 }4936 to_js_setup() {4937 return `4938 `;4939 }4940 to_js_final() {4941 var params = Procedure.getByName(this.procName).params;4942 var paramName = String(this.args.data[0].getData());4943 var index = params.indexOf(paramName);4944 return `4945 __wl_param_${index}4946 `;4947 }4948 }4949 Instructions.ProcParam = ProcParam;4950 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));4951})(Compilation || (Compilation = {}));4952/// <reference path="../../Helper/Constants.ts" />4953/// <reference path="../../DataStructures/AST.ts" />4954/// <reference path="../../Common/Agent.ts" />4955var Compilation;4956(function (Compilation) {4957 var Instructions;4958 (function (Instructions) {4959 "use strict";4960 var ASTNode = DataStructures.ASTNode;4961 var Constants = Helper.Constants;4962 class ProcReturn extends ASTNode {4963 constructor() {4964 super(2, 0); // numArgs = 2, numBranches = 04965 }4966 fn(a, scope, args, rets) {4967 rets[0] = args[0];4968 rets[1] = Constants.AST_PROC_RET;4969 }4970 to_js_no_yield() {4971 return `4972 return ${this.args.data[0].to_js_no_yield().trim()}4973 `;4974 }4975 to_js_setup() {4976 return `4977 ${this.args.data[0].to_js_setup()};4978 var __wl_${this.id}_ret = ${this.args.data[0].to_js_final()};4979 `;4980 }4981 to_js_final() {4982 return `4983 return __wl_${this.id}_ret;4984 `;4985 }4986 }4987 Instructions.ProcReturn = ProcReturn;4988 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));4989})(Compilation || (Compilation = {}));4990/// <reference path="../../DataStructures/AST.ts" />4991/// <reference path="../../Common/Agent.ts" />4992/// <reference path="../../Common/Procedure.ts" />4993/// <reference path="../../Helper/Utils.ts" />4994var Compilation;4995(function (Compilation) {4996 var Instructions;4997 (function (Instructions) {4998 "use strict";4999 var ASTNode = DataStructures.ASTNode;5000 var CProcedure = Common.Procedure;5001 class Procedure extends ASTNode {5002 constructor() {5003 super(2, 1); // numArgs = 2, numBranches = 15004 }5005 fn(a, scope, args, rets) {5006 rets[1] = 0;5007 }5008 to_js_no_yield() {5009 return `5010 ${this.branches[0].to_js()}5011 return ${(this.args.data[1] === undefined) ? undefined : this.args.data[1].to_js_no_yield().trim()};5012 `;5013 }5014 to_js_setup() {5015 return ``;5016 }5017 to_js_final() {5018 return `5019 ${this.branches[0].to_js()}5020 `;5021 }5022 make_function() {5023 var procName = String(this.args.data[0].getData());5024 var params = CProcedure.getByName(procName).params;5025 var paramNames = new Array(2 * params.length);5026 for (var i = 0; i < params.length; i++) {5027 paramNames[2 * i] = ",";5028 paramNames[2 * i + 1] = `__wl_param_${i}`;5029 }5030 var f;5031 /* tslint:disable no-eval */5032 eval(`f = function(__wl_agt, __wl_thd ${paramNames.join("")}){ ${this.to_js_no_yield()};}`);5033 /* tslint:enable no-eval */5034 return f;5035 }5036 make_generator() {5037 var procName = String(this.args.data[0].getData());5038 var params = CProcedure.getByName(procName).params;5039 var paramNames = new Array(2 * params.length);5040 for (var i = 0; i < params.length; i++) {5041 paramNames[2 * i] = ",";5042 paramNames[2 * i + 1] = `__wl_param_${i}`;5043 }5044 var g;5045 /* tslint:disable no-eval */5046 eval(`g = function*(__wl_agt, __wl_thd ${paramNames.join("")}){5047 ${this.to_js_setup()}; ${this.to_js_final()};5048 }`);5049 /* tslint:enable no-eval */5050 return g;5051 }5052 }5053 Instructions.Procedure = Procedure;5054 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));5055})(Compilation || (Compilation = {}));5056/// <reference path="../../Helper/Constants.ts" />5057/// <reference path="../../Helper/Utils.ts" />5058/// <reference path="../../DataStructures/AST.ts" />5059/// <reference path="../../Common/Agent.ts" />5060var Compilation;5061(function (Compilation) {5062 var Instructions;5063 (function (Instructions) {5064 "use strict";5065 var ASTNode = DataStructures.ASTNode;5066 var Constants = Helper.Constants;5067 var Utils = Helper.Utils;5068 class RandomDecimal extends ASTNode {5069 constructor() {5070 super(0, 0); // numArgs = 0, numBranches = 05071 }5072 fn(a, scope, args, rets) {5073 rets[0] = Utils.random();5074 rets[1] = Constants.AST_DONE;5075 }5076 to_js_no_yield() {5077 return `5078 Helper.Utils.random()5079 `;5080 }5081 to_js_setup() {5082 return ``;5083 }5084 to_js_final() {5085 return `5086 Helper.Utils.random()5087 `;5088 }5089 }5090 Instructions.RandomDecimal = RandomDecimal;5091 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));5092})(Compilation || (Compilation = {}));5093/// <reference path="../../Helper/Constants.ts" />5094/// <reference path="../../Helper/Utils.ts" />5095/// <reference path="../../DataStructures/AST.ts" />5096/// <reference path="../../Common/Agent.ts" />5097var Compilation;5098(function (Compilation) {5099 var Instructions;5100 (function (Instructions) {5101 "use strict";5102 var ASTNode = DataStructures.ASTNode;5103 var Constants = Helper.Constants;5104 var Utils = Helper.Utils;5105 class RandomInteger extends ASTNode {5106 constructor() {5107 super(2, 0); // numArgs = 2, numBranches = 05108 }5109 fn(a, scope, args, rets) {5110 var lower = Number(args[0]);5111 var upper = Number(args[1]);5112 rets[0] = Math.floor((Utils.random() * (upper + 1 - lower)) + lower);5113 rets[1] = Constants.AST_DONE;5114 }5115 to_js_no_yield() {5116 return `5117 Helper.Utils.randomInteger(${this.args.data[0].to_js_no_yield()}, ${this.args.data[1].to_js_no_yield()})5118 `;5119 }5120 to_js_setup() {5121 return `5122 ${this.args.data[0].to_js_setup()};5123 ${this.args.data[1].to_js_setup()};5124 var __wl_${this.id}_lower = ${this.args.data[0].to_js_final()};5125 var __wl_${this.id}_upper = ${this.args.data[1].to_js_final()};5126 var __wl_${this.id}_range = __wl_${this.id}_upper - __wl_${this.id}_lower + 1;5127 `;5128 }5129 to_js_final() {5130 return `5131 Math.floor((Helper.Utils.random() * __wl_${this.id}_range) + __wl_${this.id}_lower)5132 `;5133 }5134 }5135 Instructions.RandomInteger = RandomInteger;5136 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));5137})(Compilation || (Compilation = {}));5138/// <reference path="../../Helper/Constants.ts" />5139/// <reference path="../../Helper/Utils.ts" />5140/// <reference path="../../DataStructures/AST.ts" />5141/// <reference path="../../Common/Agent.ts" />5142var Compilation;5143(function (Compilation) {5144 var Instructions;5145 (function (Instructions) {5146 "use strict";5147 var ASTNode = DataStructures.ASTNode;5148 var Constants = Helper.Constants;5149 var Utils = Helper.Utils;5150 class RandomPercent extends ASTNode {5151 constructor() {5152 super(1, 1); // numArgs = 1, numBranches = 15153 }5154 fn(a, scope, args, rets) {5155 if (Utils.random() * 100 < args[0]) {5156 rets[0] = 0;5157 rets[1] = 0;5158 }5159 else {5160 rets[1] = Constants.AST_DONE;5161 }5162 }5163 to_js_no_yield() {5164 return `5165 if (Helper.Utils.random() * 100 < ${this.args.data[0].to_js_no_yield()}) {5166 ${this.branches[0].to_js()}5167 }5168 `;5169 }5170 to_js_setup() {5171 return `5172 ${this.args.data[0].to_js_setup()};5173 var __wl_${this.id}_threshold = ${this.args.data[0].to_js_final()};5174 `;5175 }5176 to_js_final() {5177 return `5178 if (Helper.Utils.random() * 100 < __wl_${this.id}_threshold) {5179 ${this.branches[0].to_js()}5180 }5181 `;5182 }5183 }5184 Instructions.RandomPercent = RandomPercent;5185 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));5186})(Compilation || (Compilation = {}));5187/// <reference path="../../Helper/Constants.ts" />5188/// <reference path="../../DataStructures/AST.ts" />5189/// <reference path="../../Common/Agent.ts" />5190var Compilation;5191(function (Compilation) {5192 var Instructions;5193 (function (Instructions) {5194 "use strict";5195 var ASTNode = DataStructures.ASTNode;5196 var Constants = Helper.Constants;5197 class Scatter extends ASTNode {5198 constructor() {5199 super(0, 0); // numArgs = 0, numBranches = 05200 }5201 fn(a, scope, args, rets) {5202 a.scatter();5203 rets[1] = Constants.AST_DONE;5204 }5205 to_js_no_yield() {5206 return `5207 __wl_agt.scatter()5208 `;5209 }5210 to_js_setup() {5211 return ``;5212 }5213 to_js_final() {5214 return `5215 __wl_agt.scatter();5216 `;5217 }5218 }5219 Instructions.Scatter = Scatter;5220 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));5221})(Compilation || (Compilation = {}));5222/// <reference path="../../Helper/Constants.ts" />5223/// <reference path="../../DataStructures/AST.ts" />5224/// <reference path="../../Common/Agent.ts" />5225/// <reference path="../../Execution/AgentController.ts" />5226var Compilation;5227(function (Compilation) {5228 var Instructions;5229 (function (Instructions) {5230 "use strict";5231 var ASTNode = DataStructures.ASTNode;5232 var Constants = Helper.Constants;5233 var AgentController = Execution.AgentController;5234 class ScatterEveryone extends ASTNode {5235 constructor() {5236 super(0, 0); // numArgs = 0, numBranches = 05237 }5238 fn(_, scope, args, rets) {5239 AgentController.scatterAllAgents();5240 rets[1] = Constants.AST_DONE;5241 }5242 to_js_no_yield() {5243 return `5244 Execution.AgentController.scatterAllAgents()5245 `;5246 }5247 to_js_setup() {5248 return ``;5249 }5250 to_js_final() {5251 return `5252 Execution.AgentController.scatterAllAgents()5253 `;5254 }5255 }5256 Instructions.ScatterEveryone = ScatterEveryone;5257 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));5258})(Compilation || (Compilation = {}));5259/// <reference path="../../Helper/Constants.ts" />5260/// <reference path="../../Helper/Logger.ts" />5261/// <reference path="../../DataStructures/AST.ts" />5262/// <reference path="../../Common/Agent.ts" />5263var Compilation;5264(function (Compilation) {5265 var Instructions;5266 (function (Instructions) {5267 "use strict";5268 var ASTNode = DataStructures.ASTNode;5269 var Constants = Helper.Constants;5270 var Logger = Helper.Logger;5271 class SendDataToBackend extends ASTNode {5272 constructor() {5273 super(1, 0); // numArgs = 1, numBranches = 05274 }5275 fn(a, scope, args, rets) {5276 Logger.mustLog(args[0]);5277 rets[1] = Constants.AST_DONE;5278 }5279 to_js_no_yield() {5280 return `5281 var reporter = new GameReporter();5282 reporter.report(${this.args.data[0].to_js_no_yield()}, {});5283 `;5284 }5285 to_js_setup() {5286 return `5287 ${this.args.data[0].to_js_setup()};5288 var __wl_${this.id}_print = ${this.args.data[0].to_js_final()};5289 `;5290 }5291 to_js_final() {5292 return `5293 Logger.mustLog(__wl_${this.id}_print);5294 `;5295 }5296 }5297 Instructions.SendDataToBackend = SendDataToBackend;5298 class GameReporter {5299 constructor() {5300 this.uuid = this.getCookie('session_uuid');5301 }5302 submitData(data) {5303 var xhr = new XMLHttpRequest();5304 // This part gets unplatform's session uuid if available5305 // and creates a json string for the ajax POST. The /appdata/ api5306 // is pretty flexible for the params field. Timestamps are generated5307 // server-side & don't need to be included.5308 var data_string = {};5309 // if you want to test with a session id, you can set5310 // document.cookie = "session_uuid=test"5311 data_string['session_id'] = this.uuid;5312 for (var key in data) {5313 data_string[key] = data[key];5314 }5315 ;5316 var qbank = { data: data_string };5317 qbank = JSON.stringify(qbank);5318 xhr.open('POST', '/api/v1/logging/genericlog', true); // True means async5319 xhr.setRequestHeader("x-api-proxy", this.uuid);5320 xhr.setRequestHeader("Content-Type", "application/json");5321 xhr.send(qbank);5322 if (xhr.response != 200) {5323 var xhr = new XMLHttpRequest();5324 var unplatform = JSON.stringify(data_string);5325 xhr.open('POST', '/api/appdata/', true); // True means async5326 xhr.setRequestHeader("Content-Type", "application/json");5327 xhr.send(unplatform);5328 }5329 }5330 ;5331 // Generic get cookie function5332 getCookie(cname) {5333 var name = cname + "=";5334 var ca = document.cookie.split(';');5335 for (var i = 0; i < ca.length; i++) {5336 var c = ca[i];5337 while (c.charAt(0) == ' ')5338 c = c.substring(1);5339 if (c.indexOf(name) == 0)5340 return c.substring(name.length, c.length);5341 }5342 console.log('no uuid found');5343 }5344 ;5345 // The report function is used to report stateless data. This means reports should include5346 // as much data and relevant metadata as possible. Timestamps are recorded serverside and5347 // are used with reports to reconstruct what students did. Example:5348 // var reporter = new GameReporter(); reporter.report('click', {button_name : 'start'});5349 report(event, params) {5350 var data = {5351 // app_name ideally should be get the app's name5352 // via an environment variable but for now it's hard coded5353 "app_name": "slnova",5354 "version": "1.0",5355 // usually the event that triggrs the action, e.g. go_button_clicked5356 // this field has a max length of 32 chars5357 "event_type": event,5358 // params is the place to dump data related to the event. no max length and5359 // can include sub objects. this data is stringified in the submit data function.5360 // ex: params : {level : 2, player_velocity : 30, computer_velocity : 20 }5361 "params": params,5362 };5363 this.submitData(data);5364 }5365 }5366 Instructions.GameReporter = GameReporter;5367 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));5368})(Compilation || (Compilation = {}));5369/// <reference path="../../DataStructures/AST.ts" />5370/// <reference path="../../Helper/Constants.ts" />5371/// <reference path="../../Common/Agent.ts" />5372var Compilation;5373(function (Compilation) {5374 var Instructions;5375 (function (Instructions) {5376 "use strict";5377 var ASTNode = DataStructures.ASTNode;5378 var Constants = Helper.Constants;5379 class SetMyTrait extends ASTNode {5380 constructor() {5381 super(2, 0); // numArgs = 2, numBranches = 05382 }5383 fn(a, scope, args, rets) {5384 var trait = String(args[0]);5385 var value = args[1];5386 a.setTrait(trait, value);5387 rets[1] = Constants.AST_DONE;5388 }5389 to_js_no_yield() {5390 return `5391 __wl_agt.setTrait(${this.args.data[0].to_js_no_yield()}, ${this.args.data[1].to_js_no_yield()})5392 `;5393 }5394 to_js_setup() {5395 return `5396 ${this.args.data[0].to_js_setup()};5397 ${this.args.data[1].to_js_setup()};5398 var __wl_${this.id}_trait = ${this.args.data[0].to_js_final()};5399 var __wl_${this.id}_value = ${this.args.data[1].to_js_final()};5400 `;5401 }5402 to_js_final() {5403 return `5404 __wl_agt.setTrait(__wl_${this.id}_trait, __wl_${this.id}_value);5405 `;5406 }5407 }5408 Instructions.SetMyTrait = SetMyTrait;5409 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));5410})(Compilation || (Compilation = {}));5411/// <reference path="../../Helper/Constants.ts" />5412/// <reference path="../../DataStructures/AST.ts" />5413/// <reference path="../../Common/Agent.ts" />5414var Compilation;5415(function (Compilation) {5416 var Instructions;5417 (function (Instructions) {5418 "use strict";5419 var ASTNode = DataStructures.ASTNode;5420 var Constants = Helper.Constants;5421 class SetPen extends ASTNode {5422 constructor() {5423 super(1, 0); // numArgs = 1, numBranches = 05424 }5425 fn(a, scope, args, rets) {5426 var setting = String(args[0]);5427 a.isPenDown = (setting === "down");5428 rets[1] = Constants.AST_DONE;5429 }5430 to_js_no_yield() {5431 return `5432 __wl_agt.isPenDown = (${this.args.data[0].to_js_no_yield()} === "down")5433 `;5434 }5435 to_js_setup() {5436 return `5437 ${this.args.data[0].to_js_setup()};5438 var __wl_${this.id}_state = ${this.args.data[0].to_js_final()};5439 `;5440 }5441 to_js_final() {5442 return `5443 __wl_agt.isPenDown = (__wl_${this.id}_state === "down");5444 `;5445 }5446 }5447 Instructions.SetPen = SetPen;5448 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));5449})(Compilation || (Compilation = {}));5450/// <reference path="../../Helper/Constants.ts" />5451/// <reference path="../../DataStructures/AST.ts" />5452/// <reference path="../../Common/Agent.ts" />5453var Compilation;5454(function (Compilation) {5455 var Instructions;5456 (function (Instructions) {5457 "use strict";5458 var ASTNode = DataStructures.ASTNode;5459 var Constants = Helper.Constants;5460 class ShapeOptions extends ASTNode {5461 constructor() {5462 super(1, 0); // numArgs = 1, numBranches = 05463 }5464 fn(a, scope, args, rets) {5465 rets[0] = String(args[0]);5466 rets[1] = Constants.AST_DONE;5467 }5468 to_js_no_yield() {5469 return `5470 ${this.args.data[0].to_js_no_yield()}5471 `;5472 }5473 to_js_setup() {5474 return `5475 ${this.args.data[0].to_js_setup()};5476 var __wl_${this.id}_option = String(${this.args.data[0].to_js_final()});5477 `;5478 }5479 to_js_final() {5480 return `5481 __wl_${this.id}_option;5482 `;5483 }5484 }5485 Instructions.ShapeOptions = ShapeOptions;5486 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));5487})(Compilation || (Compilation = {}));5488/// <reference path="../../Helper/Constants.ts" />5489/// <reference path="../../DataStructures/AST.ts" />5490/// <reference path="../../Common/Agent.ts" />5491var Compilation;5492(function (Compilation) {5493 var Instructions;5494 (function (Instructions) {5495 "use strict";5496 var ASTNode = DataStructures.ASTNode;5497 var Constants = Helper.Constants;5498 class SoundOptions extends ASTNode {5499 constructor() {5500 super(1, 0); // numArgs = 1, numBranches = 05501 }5502 fn(a, scope, args, rets) {5503 rets[0] = String(args[0]);5504 rets[1] = Constants.AST_DONE;5505 }5506 to_js_no_yield() {5507 return `5508 ${this.args.data[0].to_js_no_yield()}5509 `;5510 }5511 to_js_setup() {5512 return `5513 ${this.args.data[0].to_js_setup()};5514 var __wl_${this.id}_option = String(${this.args.data[0].to_js_final()});5515 `;5516 }5517 to_js_final() {5518 return `5519 __wl_${this.id}_option;5520 `;5521 }5522 }5523 Instructions.SoundOptions = SoundOptions;5524 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));5525})(Compilation || (Compilation = {}));5526/// <reference path="../../Helper/Constants.ts" />5527/// <reference path="../../DataStructures/AST.ts" />5528/// <reference path="../../Common/Agent.ts" />5529var Compilation;5530(function (Compilation) {5531 var Instructions;5532 (function (Instructions) {5533 "use strict";5534 var ASTNode = DataStructures.ASTNode;5535 var Constants = Helper.Constants;5536 class SoundPlay extends ASTNode {5537 constructor() {5538 super(1, 0); // numArgs = 1, numBranches = 05539 }5540 fn(a, scope, args, rets) {5541 rets[1] = Constants.AST_DONE;5542 }5543 to_js_no_yield() {5544 return `5545 AssetManager.playSound(${this.args.data[0].to_js_no_yield()})5546 `;5547 }5548 to_js_setup() {5549 return `5550 ${this.args.data[0].to_js_setup()};5551 var __wl_${this.id}_sound_id = ${this.args.data[0].to_js_final()};5552 `;5553 }5554 to_js_final() {5555 return `5556 AssetManager.playSound(__wl_${this.id}_sound_id);5557 `;5558 }5559 }5560 Instructions.SoundPlay = SoundPlay;5561 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));5562})(Compilation || (Compilation = {}));5563/// <reference path="../../Helper/Constants.ts" />5564/// <reference path="../../DataStructures/AST.ts" />5565/// <reference path="../../Common/Agent.ts" />5566var Compilation;5567(function (Compilation) {5568 var Instructions;5569 (function (Instructions) {5570 "use strict";5571 var ASTNode = DataStructures.ASTNode;5572 var Constants = Helper.Constants;5573 class Stamp extends ASTNode {5574 constructor() {5575 super(1, 0); // numArgs = 1, numBranches = 05576 }5577 fn(a, scope, args, rets) {5578 rets[0] = undefined;5579 rets[1] = Constants.AST_DONE;5580 throw new Error("unimplemented");5581 }5582 to_js_no_yield() {5583 return `5584 var color = ${this.args.data[0].to_js_no_yield()};5585 viewport.terrain.circlePixels(__wl_agt.state.x, __wl_agt.state.y, __wl_agt.state.size,5586 (color & 0xFF0000) >> 16,5587 (color & 0x00FF00) >> 8,5588 color & 0x0000FF)5589 `;5590 }5591 to_js_setup() {5592 return `5593 ${this.args.data[0].to_js_setup()};5594 var __wl_${this.id}_color = ${this.args.data[0].to_js_final()};5595 `;5596 }5597 to_js_final() {5598 return `5599 viewport.terrain.circlePixels(__wl_agt.state.x, __wl_agt.state.y, __wl_agt.state.size,5600 (__wl_${this.id}_color & 0xFF0000) >> 16,5601 (__wl_${this.id}_color & 0x00FF00) >> 8,5602 __wl_${this.id}_color & 0x0000FF)5603 `;5604 }5605 }5606 Instructions.Stamp = Stamp;5607 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));5608})(Compilation || (Compilation = {}));5609/// <reference path="../../Helper/Constants.ts" />5610/// <reference path="../../DataStructures/AST.ts" />5611/// <reference path="../../Common/Agent.ts" />5612var Compilation;5613(function (Compilation) {5614 var Instructions;5615 (function (Instructions) {5616 "use strict";5617 var ASTNode = DataStructures.ASTNode;5618 var Constants = Helper.Constants;5619 class StampGrid extends ASTNode {5620 constructor() {5621 super(1, 0); // numArgs = 1, numBranches = 05622 }5623 fn(a, scope, args, rets) {5624 rets[0] = undefined;5625 rets[1] = Constants.AST_DONE;5626 throw new Error("unimplemented");5627 }5628 to_js_no_yield() {5629 return `5630 var color = ${this.args.data[0].to_js_no_yield()};5631 viewport.terrain.gridSquarePixels(__wl_agt.state.x, __wl_agt.state.y,5632 (color & 0xFF0000) >> 16,5633 (color & 0x00FF00) >> 8,5634 color & 0x0000FF)5635 `;5636 }5637 to_js_setup() {5638 return `5639 ${this.args.data[0].to_js_setup()};5640 var __wl_${this.id}_color = ${this.args.data[0].to_js_final()};5641 `;5642 }5643 to_js_final() {5644 return `5645 viewport.terrain.gridSquarePixels(__wl_agt.state.x, __wl_agt.state.y,5646 (__wl_${this.id}_color & 0xFF0000) >> 16,5647 (__wl_${this.id}_color & 0x00FF00) >> 8,5648 __wl_${this.id}_color & 0x0000FF)5649 `;5650 }5651 }5652 Instructions.StampGrid = StampGrid;5653 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));5654})(Compilation || (Compilation = {}));5655/// <reference path="../../Helper/Constants.ts" />5656/// <reference path="../../DataStructures/AST.ts" />5657/// <reference path="../../Common/Agent.ts" />5658var Compilation;5659(function (Compilation) {5660 var Instructions;5661 (function (Instructions) {5662 "use strict";5663 var ASTNode = DataStructures.ASTNode;5664 var Constants = Helper.Constants;5665 class TerrainClear extends ASTNode {5666 constructor() {5667 super(0, 0); // numArgs = 0, numBranches = 05668 }5669 fn(a, scope, args, rets) {5670 rets[0] = undefined;5671 rets[1] = Constants.AST_DONE;5672 throw new Error("unimplemented");5673 }5674 to_js_no_yield() {5675 return `5676 viewport.terrain.clear()5677 `;5678 }5679 to_js_setup() {5680 return `5681 viewport.terrain.clear()5682 `;5683 }5684 to_js_final() {5685 return ``;5686 }5687 }5688 Instructions.TerrainClear = TerrainClear;5689 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));5690})(Compilation || (Compilation = {}));5691/// <reference path="../../Helper/Constants.ts" />5692/// <reference path="../../DataStructures/AST.ts" />5693/// <reference path="../../Common/Agent.ts" />5694var Compilation;5695(function (Compilation) {5696 var Instructions;5697 (function (Instructions) {5698 "use strict";5699 var ASTNode = DataStructures.ASTNode;5700 var Constants = Helper.Constants;5701 class TerrainColor extends ASTNode {5702 constructor() {5703 super(0, 0); // numArgs = 0, numBranches = 05704 }5705 fn(a, scope, args, rets) {5706 rets[0] = undefined;5707 rets[1] = Constants.AST_DONE;5708 throw new Error("unimplemented");5709 }5710 to_js_no_yield() {5711 return `5712 viewport.terrain.getPixelColorAt(__wl_agt.state.x, __wl_agt.state.y)5713 `;5714 }5715 to_js_setup() {5716 return `5717 viewport.terrain.getPixelColorAt(__wl_agt.state.x, __wl_agt.state.y)5718 `;5719 }5720 to_js_final() {5721 return ``;5722 }5723 }5724 Instructions.TerrainColor = TerrainColor;5725 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));5726})(Compilation || (Compilation = {}));5727/// <reference path="../../Helper/Constants.ts" />5728/// <reference path="../../Common/Agent.ts" />5729/// <reference path="UtilTraitHelper.ts" />5730var Compilation;5731(function (Compilation) {5732 var Instructions;5733 (function (Instructions) {5734 "use strict";5735 var Constants = Helper.Constants;5736 // TODO: It appears this isn't even used anymore, as the code for getting5737 // traits is now inside Execution.Agent, called from Helper.Utils.getTrait.5738 // Can we remove this?5739 var UtilTraitHelper = Compilation.Instructions.UtilTraitHelper;5740 class TraitOf extends UtilTraitHelper {5741 constructor() {5742 super(2, 0); // numArgs = 2, numBranches = 05743 }5744 fn(a, scope, args, rets) {5745 var trait = args[0];5746 var agt = args[1];5747 rets[0] = this.traitHelper(agt, trait);5748 rets[1] = Constants.AST_DONE;5749 }5750 to_js_no_yield() {5751 return `5752 Helper.Utils.getTrait(${this.args.data[1].to_js_no_yield()}, ${this.args.data[0].to_js_no_yield()})5753 `;5754 }5755 to_js_setup() {5756 return `5757 ${this.args.data[0].to_js_setup()};5758 ${this.args.data[1].to_js_setup()};5759 var __wl_${this.id}_name = ${this.args.data[0].to_js_final()};5760 var __wl_${this.id}_agt = ${this.args.data[1].to_js_final()};5761 `;5762 }5763 to_js_final() {5764 return `5765 Helper.Utils.getTrait(${this.args.data[1].to_js_no_yield()}, ${this.args.data[0].to_js_no_yield()})5766 `;5767 }5768 }5769 Instructions.TraitOf = TraitOf;5770 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));5771})(Compilation || (Compilation = {}));5772/// <reference path="../../Helper/Constants.ts" />5773/// <reference path="../../Helper/Utils.ts" />5774/// <reference path="../../DataStructures/AST.ts" />5775/// <reference path="../../Common/Agent.ts" />5776var Compilation;5777(function (Compilation) {5778 var Instructions;5779 (function (Instructions) {5780 "use strict";5781 var ASTNode = DataStructures.ASTNode;5782 var Constants = Helper.Constants;5783 var Utils = Helper.Utils;5784 class VarDefine extends ASTNode {5785 constructor() {5786 super(3, 0); // numArgs = 3, numBranches = 05787 this.useParentScope = false;5788 }5789 fn(a, scope, args, rets) {5790 scope.set(args[0], args[2]);5791 rets[1] = Constants.AST_DONE;5792 }5793 to_js_no_yield() {5794 if (this.useParentScope) {5795 return `5796 __wl_thd.scope.set(${this.args.data[0].to_js_no_yield()}, ${this.args.data[2].to_js_no_yield()})5797 `;5798 }5799 else {5800 var hash = Utils.hash(this.args.data[0].getData());5801 return `5802 var __wl_var_${hash} = ${this.args.data[2].to_js_no_yield()}5803 `;5804 }5805 }5806 to_js_setup() {5807 return `5808 ${this.args.data[0].to_js_setup()};5809 ${this.args.data[2].to_js_setup()};5810 var __wl_${this.id}_name = ${this.args.data[0].to_js_final()};5811 var __wl_${this.id}_val = ${this.args.data[2].to_js_final()};5812 `;5813 }5814 to_js_final() {5815 if (this.useParentScope) {5816 return `5817 __wl_thd.scope.set(__wl_${this.id}_name, __wl_${this.id}_val);5818 `;5819 }5820 else {5821 var hash = Utils.hash(this.args.data[0].getData());5822 return `5823 var __wl_var_${hash} = __wl_${this.id}_val5824 `;5825 }5826 }5827 }5828 Instructions.VarDefine = VarDefine;5829 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));5830})(Compilation || (Compilation = {}));5831/// <reference path="../../Helper/Constants.ts" />5832/// <reference path="../../Helper/Utils.ts" />5833/// <reference path="../../Helper/Logger.ts" />5834/// <reference path="../../DataStructures/AST.ts" />5835/// <reference path="../../Common/Agent.ts" />5836var Compilation;5837(function (Compilation) {5838 var Instructions;5839 (function (Instructions) {5840 "use strict";5841 var ASTNode = DataStructures.ASTNode;5842 var Constants = Helper.Constants;5843 var Logger = Helper.Logger;5844 var Utils = Helper.Utils;5845 class VarGet extends ASTNode {5846 constructor() {5847 super(1, 0); // numArgs = 1, numBranches = 05848 this.useParentScope = false;5849 }5850 fn(a, scope, args, rets) {5851 // Logger.assert(scope.has(args[0]));5852 rets[0] = scope.get(args[0]);5853 rets[1] = Constants.AST_DONE;5854 }5855 to_js_no_yield() {5856 if (this.useParentScope) {5857 return `5858 __wl_thd.scope.get(${this.args.data[0].to_js_no_yield()})5859 `;5860 }5861 else {5862 var hash = Utils.hash(this.args.data[0].getData());5863 return `5864 __wl_var_${hash}5865 `;5866 }5867 }5868 to_js_setup() {5869 return `5870 ${this.args.data[0].to_js_setup()};5871 var __wl_${this.id}_name = ${this.args.data[0].to_js_final()};5872 `;5873 }5874 to_js_final() {5875 if (this.useParentScope) {5876 return `5877 __wl_thd.scope.get(__wl_${this.id}_name);5878 `;5879 }5880 else {5881 var hash = Utils.hash(this.args.data[0].getData());5882 return `5883 __wl_var_${hash};5884 `;5885 }5886 }5887 }5888 Instructions.VarGet = VarGet;5889 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));5890})(Compilation || (Compilation = {}));5891/// <reference path="../../Helper/Logger.ts" />5892/// <reference path="../../Helper/Constants.ts" />5893/// <reference path="../../Helper/Utils.ts" />5894/// <reference path="../../DataStructures/AST.ts" />5895/// <reference path="../../Common/Agent.ts" />5896var Compilation;5897(function (Compilation) {5898 var Instructions;5899 (function (Instructions) {5900 "use strict";5901 var ASTNode = DataStructures.ASTNode;5902 var Constants = Helper.Constants;5903 var Logger = Helper.Logger;5904 var Utils = Helper.Utils;5905 class VarSet extends ASTNode {5906 constructor() {5907 super(2, 0); // numArgs = 2, numBranches = 05908 this.useParentScope = false;5909 }5910 fn(a, scope, args, rets) {5911 // Logger.assert(scope.has(args[0]));5912 scope.set(args[0], args[1]);5913 rets[1] = Constants.AST_DONE;5914 }5915 to_js_no_yield() {5916 if (this.useParentScope) {5917 return `5918 __wl_thd.scope.set(${this.args.data[0].to_js_no_yield()}, ${this.args.data[1].to_js_no_yield()})5919 `;5920 }5921 else {5922 var hash = Utils.hash(this.args.data[0].getData());5923 return `5924 __wl_var_${hash} = ${this.args.data[1].to_js_no_yield()}5925 `;5926 }5927 }5928 to_js_setup() {5929 return `5930 ${this.args.data[0].to_js_setup()};5931 ${this.args.data[2].to_js_setup()};5932 var __wl_${this.id}_name = ${this.args.data[0].to_js_final()};5933 var __wl_${this.id}_val = ${this.args.data[1].to_js_final()};5934 `;5935 }5936 to_js_final() {5937 if (this.useParentScope) {5938 return `5939 __wl_thd.scope.set(__wl_${this.id}_name, __wl_${this.id}_val);5940 `;5941 }5942 else {5943 var hash = Utils.hash(this.args.data[0].getData());5944 return `5945 __wl_var_${hash} = __wl_${this.id}_val5946 `;5947 }5948 }5949 }5950 Instructions.VarSet = VarSet;5951 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));5952})(Compilation || (Compilation = {}));5953/// <reference path="../../dts/widgets.d.ts" />5954/// <reference path="../../Helper/Constants.ts" />5955/// <reference path="../../DataStructures/AST.ts" />5956/// <reference path="../../Common/Agent.ts" />5957var Compilation;5958(function (Compilation) {5959 var Instructions;5960 (function (Instructions) {5961 "use strict";5962 var ASTNode = DataStructures.ASTNode;5963 var Constants = Helper.Constants;5964 class WgtAddDataLineGraph extends ASTNode {5965 constructor() {5966 super(4, 0); // numArgs = 4, numBranches = 05967 }5968 fn(a, scope, args, rets) {5969 var lineGraphName = args[0];5970 var seriesName = args[1];5971 var x = args[2];5972 var y = args[3];5973 var graph = WidgetManager.getWidgetByName(lineGraphName);5974 graph.addData(seriesName, x, y);5975 graph.update();5976 rets[1] = Constants.AST_DONE;5977 }5978 to_js_no_yield() {5979 return `5980 var graph = WidgetManager.getWidgetByName(${this.args.data[0].to_js_no_yield()}); 5981 graph.addData(5982 String(${this.args.data[1].to_js_no_yield()}),5983 Number(${this.args.data[2].to_js_no_yield()}),5984 Number(${this.args.data[3].to_js_no_yield()})5985 );5986 graph.update();5987 `;5988 }5989 to_js_setup() {5990 return `5991 ${this.args.data[0].to_js_setup()};5992 ${this.args.data[1].to_js_setup()};5993 ${this.args.data[2].to_js_setup()};5994 ${this.args.data[3].to_js_setup()};5995 var __wl_${this.id}_w_name = ${this.args.data[0].to_js_final()};5996 var __wl_${this.id}_s_name = String(${this.args.data[1].to_js_final()});5997 var __wl_${this.id}_x = Number(${this.args.data[2].to_js_final()});5998 var __wl_${this.id}_y = Number(${this.args.data[3].to_js_final()});5999 `;6000 }6001 to_js_final() {6002 return `6003 var graph = WidgetManager.getWidgetByName(${this.args.data[0].to_js_no_yield()}); 6004 graph.addData(6005 __wl_${this.id}_s_name,6006 __wl_${this.id}_x,6007 __wl_${this.id}_y6008 );6009 graph.update();6010 `;6011 }6012 }6013 Instructions.WgtAddDataLineGraph = WgtAddDataLineGraph;6014 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));6015})(Compilation || (Compilation = {}));6016/// <reference path="../../dts/widgets.d.ts" />6017/// <reference path="../../Helper/Constants.ts" />6018/// <reference path="../../DataStructures/AST.ts" />6019/// <reference path="../../Common/Agent.ts" />6020var Compilation;6021(function (Compilation) {6022 var Instructions;6023 (function (Instructions) {6024 "use strict";6025 var ASTNode = DataStructures.ASTNode;6026 var Constants = Helper.Constants;6027 class WgtButtonPush extends ASTNode {6028 constructor() {6029 super(1, 1); // numArgs = 1, numBranches = 16030 }6031 fn(a, scope, args, rets) {6032 var name = args[0];6033 var button = WidgetManager.getWidgetByName(name);6034 if (button.checkPushed()) {6035 rets[1] = Constants.AST_YIELD_REPEAT;6036 }6037 else {6038 rets[1] = Constants.AST_YIELD_REPEAT_NO_BRANCH;6039 }6040 }6041 to_js_no_yield() {6042 return `6043 var __wl_${this.id}_btn_name = ${this.args.data[0].to_js_no_yield()};6044 if (Common.State.pushedButtons.has(__wl_${this.id}_btn_name)) {6045 ${this.branches[0].to_js()}6046 }6047 `;6048 }6049 to_js_setup() {6050 return `6051 ${this.args.data[0].to_js_setup()};6052 var __wl_${this.id}_btn_name = ${this.args.data[0].to_js_final()};6053 `;6054 }6055 to_js_final() {6056 return `6057 if (Common.State.pushedButtons.has(__wl_${this.id}_btn_name)) {6058 ${this.branches[0].to_js()}6059 }6060 `;6061 }6062 }6063 Instructions.WgtButtonPush = WgtButtonPush;6064 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));6065})(Compilation || (Compilation = {}));6066/// <reference path="../../dts/widgets.d.ts" />6067/// <reference path="../../Helper/Constants.ts" />6068/// <reference path="../../DataStructures/AST.ts" />6069/// <reference path="../../Common/Agent.ts" />6070var Compilation;6071(function (Compilation) {6072 var Instructions;6073 (function (Instructions) {6074 "use strict";6075 var ASTNode = DataStructures.ASTNode;6076 var Constants = Helper.Constants;6077 class WgtButtonToggle extends ASTNode {6078 constructor() {6079 super(1, 1); // numArgs = 1, numBranches = 16080 }6081 fn(a, scope, args, rets) {6082 var name = args[0];6083 var button = WidgetManager.getWidgetByName(name);6084 if (button.isToggled()) {6085 rets[1] = Constants.AST_YIELD_REPEAT;6086 }6087 else {6088 rets[1] = Constants.AST_YIELD_REPEAT_NO_BRANCH;6089 }6090 }6091 to_js_no_yield() {6092 return `6093 var __wl_${this.id}_btn_name = ${this.args.data[0].to_js_no_yield()};6094 if (6095 (Common.State.toggledButtons.has(__wl_${this.id}_btn_name) &&6096 !__wl_agt.disabledButtons.has(__wl_${this.id}_btn_name)6097 ) ||6098 __wl_agt.enabledButtons.has(__wl_${this.id}_btn_name)) {6099 ${this.branches[0].to_js()}6100 }6101 `;6102 }6103 to_js_setup() {6104 return `6105 ${this.args.data[0].to_js_setup()};6106 var __wl_${this.id}_btn_name = ${this.args.data[0].to_js_final()};6107 `;6108 }6109 to_js_final() {6110 return `6111 if (6112 (Common.State.toggledButtons.has(__wl_${this.id}_btn_name) &&6113 !__wl_agt.disabledButtons.has(__wl_${this.id}_btn_name)6114 ) ||6115 __wl_agt.enabledButtons.has(__wl_${this.id}_btn_name)) {6116 ${this.branches[0].to_js()}6117 }6118 `;6119 }6120 }6121 Instructions.WgtButtonToggle = WgtButtonToggle;6122 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));6123})(Compilation || (Compilation = {}));6124/// <reference path="../../dts/widgets.d.ts" />6125/// <reference path="../../Helper/Constants.ts" />6126/// <reference path="../../DataStructures/AST.ts" />6127/// <reference path="../../Common/Agent.ts" />6128var Compilation;6129(function (Compilation) {6130 var Instructions;6131 (function (Instructions) {6132 "use strict";6133 var ASTNode = DataStructures.ASTNode;6134 var Constants = Helper.Constants;6135 class WgtButtonToggleSet extends ASTNode {6136 constructor() {6137 super(3, 0); // numArgs = 3, numBranches = 06138 }6139 fn(a, scope, args, rets) {6140 var name = args[0];6141 var button = WidgetManager.getWidgetByName(name);6142 if (args[2] === "everyone") {6143 button.setValue(args[1] === "on");6144 }6145 else {6146 a.setToggleButton(name, args[1] === "on");6147 }6148 rets[1] = Constants.AST_DONE;6149 }6150 to_js_no_yield() {6151 return `6152 var __wl_${this.id}_btn_toggle = WidgetManager.getWidgetByName(${this.args.data[0].to_js_no_yield()});6153 var __wl_${this.id}_btn_state = Boolean(${this.args.data[1].to_js_no_yield()} === "on");6154 if (${this.args.data[2].to_js_no_yield()}) {6155 __wl_${this.id}_btn_toggle.setValue(__wl_${this.id}_btn_state);6156 } else {6157 __wl_agt.setToggleButton(__wl_${this.id}_btn_toggle, __wl_${this.id}_btn_state);6158 }6159 `;6160 }6161 to_js_setup() {6162 return `6163 ${this.args.data[0].to_js_setup()};6164 ${this.args.data[1].to_js_setup()};6165 ${this.args.data[2].to_js_setup()};6166 var __wl_${this.id}_btn_name = ${this.args.data[0].to_js_final()};6167 var __wl_${this.id}_btn_state = Boolean(${this.args.data[1].to_js_final()} === "on");6168 var __wl_${this.id}_btn_target = String(${this.args.data[2].to_js_final()});6169 `;6170 }6171 to_js_final() {6172 return `6173 var __wl_${this.id}_btn_toggle = WidgetManager.getWidgetByName(__wl_${this.id}_btn_name);6174 if (__wl_${this.id}_btn_target == "everyone") {6175 __wl_${this.id}_btn_toggle.setValue(__wl_${this.id}_btn_state);6176 } else {6177 __wl_agt.setToggleButton(__wl_${this.id}_btn_toggle, __wl_${this.id}_btn_state);6178 }6179 `;6180 }6181 }6182 Instructions.WgtButtonToggleSet = WgtButtonToggleSet;6183 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));6184})(Compilation || (Compilation = {}));6185/// <reference path="../../dts/widgets.d.ts" />6186/// <reference path="../../Helper/Constants.ts" />6187/// <reference path="../../DataStructures/AST.ts" />6188/// <reference path="../../Common/Agent.ts" />6189var Compilation;6190(function (Compilation) {6191 var Instructions;6192 (function (Instructions) {6193 "use strict";6194 var ASTNode = DataStructures.ASTNode;6195 var Constants = Helper.Constants;6196 class WgtClearDataLineGraph extends ASTNode {6197 constructor() {6198 super(1, 0); // numArgs = 1, numBranches = 06199 }6200 fn(a, scope, args, rets) {6201 var name = args[0];6202 var graph = WidgetManager.getWidgetByName(name);6203 graph.clear();6204 rets[1] = Constants.AST_DONE;6205 }6206 to_js_no_yield() {6207 return `6208 WidgetManager.getWidgetByName(${this.args.data[0].to_js_no_yield()}).clear()6209 `;6210 }6211 to_js_setup() {6212 return `6213 ${this.args.data[0].to_js_setup()};6214 var __wl_${this.id}_w_name = ${this.args.data[0].to_js_final()};6215 `;6216 }6217 to_js_final() {6218 return `6219 WidgetManager.getWidgetByName(__wl_${this.id}_w_name).clear();6220 `;6221 }6222 }6223 Instructions.WgtClearDataLineGraph = WgtClearDataLineGraph;6224 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));6225})(Compilation || (Compilation = {}));6226/// <reference path="../../dts/widgets.d.ts" />6227/// <reference path="../../Helper/Constants.ts" />6228/// <reference path="../../DataStructures/AST.ts" />6229/// <reference path="../../Common/Agent.ts" />6230var Compilation;6231(function (Compilation) {6232 var Instructions;6233 (function (Instructions) {6234 "use strict";6235 var ASTNode = DataStructures.ASTNode;6236 var Constants = Helper.Constants;6237 class WgtGetLabel extends ASTNode {6238 constructor() {6239 super(1, 0); // numArgs = 1, numBranches = 06240 }6241 fn(a, scope, args, rets) {6242 var name = args[0];6243 var w = WidgetManager.getWidgetByName(name);6244 rets[0] = w.getValue();6245 rets[1] = Constants.AST_DONE;6246 }6247 to_js_no_yield() {6248 return `6249 WidgetManager.getWidgetByName(${this.args.data[0].to_js_no_yield()}).getValue()6250 `;6251 }6252 to_js_setup() {6253 return `6254 ${this.args.data[0].to_js_setup()};6255 var __wl_${this.id}_w_name = ${this.args.data[0].to_js_final()};6256 `;6257 }6258 to_js_final() {6259 return `6260 WidgetManager.getWidgetByName(__wl_${this.id}_w_name).getValue();6261 `;6262 }6263 }6264 Instructions.WgtGetLabel = WgtGetLabel;6265 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));6266})(Compilation || (Compilation = {}));6267/// <reference path="../../dts/widgets.d.ts" />6268/// <reference path="../../Helper/Constants.ts" />6269/// <reference path="../../DataStructures/AST.ts" />6270/// <reference path="../../Common/Agent.ts" />6271var Compilation;6272(function (Compilation) {6273 var Instructions;6274 (function (Instructions) {6275 "use strict";6276 var ASTNode = DataStructures.ASTNode;6277 var Constants = Helper.Constants;6278 class WgtGetSliderValue extends ASTNode {6279 constructor() {6280 super(1, 0); // numArgs = 1, numBranches = 06281 }6282 fn(a, scope, args, rets) {6283 var name = args[0];6284 var sw = WidgetManager.getWidgetByName(name);6285 rets[0] = sw.getValue();6286 rets[1] = Constants.AST_DONE;6287 }6288 to_js_no_yield() {6289 return `6290 WidgetManager.getWidgetByName(${this.args.data[0].to_js_no_yield()}).getValue()6291 `;6292 }6293 to_js_setup() {6294 return `6295 ${this.args.data[0].to_js_setup()};6296 var __wl_${this.id}_w_name = ${this.args.data[0].to_js_final()};6297 `;6298 }6299 to_js_final() {6300 return `6301 WidgetManager.getWidgetByName(__wl_${this.id}_w_name).getValue();6302 `;6303 }6304 }6305 Instructions.WgtGetSliderValue = WgtGetSliderValue;6306 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));6307})(Compilation || (Compilation = {}));6308/// <reference path="../../dts/widgets.d.ts" />6309/// <reference path="../../Helper/Constants.ts" />6310/// <reference path="../../DataStructures/AST.ts" />6311/// <reference path="../../Common/Agent.ts" />6312var Compilation;6313(function (Compilation) {6314 var Instructions;6315 (function (Instructions) {6316 "use strict";6317 var ASTNode = DataStructures.ASTNode;6318 var Constants = Helper.Constants;6319 class WgtGetText extends ASTNode {6320 constructor() {6321 super(1, 0); // numArgs = 1, numBranches = 06322 }6323 fn(a, scope, args, rets) {6324 var name = args[0];6325 var db = WidgetManager.getWidgetByName(name);6326 rets[0] = db.getValue();6327 rets[1] = Constants.AST_DONE;6328 }6329 to_js_no_yield() {6330 return `6331 Helper.Utils.guessType(WidgetManager.getWidgetByName(${this.args.data[0].to_js_no_yield()}).getValue())6332 `;6333 }6334 to_js_setup() {6335 return `6336 ${this.args.data[0].to_js_setup()};6337 var __wl_${this.id}_w_name = ${this.args.data[0].to_js_final()};6338 `;6339 }6340 to_js_final() {6341 return `6342 Helper.Utils.guessType(WidgetManager.getWidgetByName(__wl_${this.id}_w_name).getValue());6343 `;6344 }6345 }6346 Instructions.WgtGetText = WgtGetText;6347 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));6348})(Compilation || (Compilation = {}));6349/// <reference path="../../dts/widgets.d.ts" />6350/// <reference path="../../Helper/Constants.ts" />6351/// <reference path="../../DataStructures/AST.ts" />6352/// <reference path="../../Common/Agent.ts" />6353var Compilation;6354(function (Compilation) {6355 var Instructions;6356 (function (Instructions) {6357 "use strict";6358 var ASTNode = DataStructures.ASTNode;6359 var Constants = Helper.Constants;6360 class WgtSetLabel extends ASTNode {6361 constructor() {6362 super(2, 0); // numArgs = 2, numBranches = 06363 }6364 fn(a, scope, args, rets) {6365 var name = args[0];6366 var val = String(args[1]);6367 var w = WidgetManager.getWidgetByName(name);6368 w.setValue(val);6369 rets[1] = Constants.AST_DONE;6370 }6371 to_js_no_yield() {6372 return `6373 WidgetManager.getWidgetByName(${this.args.data[0].to_js_no_yield()}).setValue(6374 String(${this.args.data[1].to_js_no_yield()})6375 )6376 `;6377 }6378 to_js_setup() {6379 return `6380 ${this.args.data[0].to_js_setup()};6381 ${this.args.data[1].to_js_setup()};6382 var __wl_${this.id}_w_name = ${this.args.data[0].to_js_final()};6383 var __wl_${this.id}_val = String(${this.args.data[1].to_js_final()});6384 `;6385 }6386 to_js_final() {6387 return `6388 WidgetManager.getWidgetByName(__wl_${this.id}_w_name).setValue(__wl_${this.id}_val);6389 `;6390 }6391 }6392 Instructions.WgtSetLabel = WgtSetLabel;6393 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));6394})(Compilation || (Compilation = {}));6395/// <reference path="../../dts/widgets.d.ts" />6396/// <reference path="../../Helper/Constants.ts" />6397/// <reference path="../../DataStructures/AST.ts" />6398/// <reference path="../../Common/Agent.ts" />6399var Compilation;6400(function (Compilation) {6401 var Instructions;6402 (function (Instructions) {6403 "use strict";6404 var ASTNode = DataStructures.ASTNode;6405 var Constants = Helper.Constants;6406 class WgtSetText extends ASTNode {6407 constructor() {6408 super(2, 0); // numArgs = 2, numBranches = 06409 }6410 fn(a, scope, args, rets) {6411 var name = args[0];6412 var val = String(args[1]);6413 var db = WidgetManager.getWidgetByName(name);6414 db.setValue(val);6415 rets[1] = Constants.AST_DONE;6416 }6417 to_js_no_yield() {6418 return `6419 WidgetManager.getWidgetByName(${this.args.data[0].to_js_no_yield()}).setValue(6420 String(${this.args.data[1].to_js_no_yield()})6421 )6422 `;6423 }6424 to_js_setup() {6425 return `6426 ${this.args.data[0].to_js_setup()};6427 ${this.args.data[1].to_js_setup()};6428 var __wl_${this.id}_w_name = ${this.args.data[0].to_js_final()};6429 var __wl_${this.id}_val = String(${this.args.data[1].to_js_final()});6430 `;6431 }6432 to_js_final() {6433 return `6434 WidgetManager.getWidgetByName(__wl_${this.id}_w_name).setValue(__wl_${this.id}_val);6435 `;6436 }6437 }6438 Instructions.WgtSetText = WgtSetText;6439 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));6440})(Compilation || (Compilation = {}));6441/// <reference path="../../dts/widgets.d.ts" />6442/// <reference path="../../Helper/Constants.ts" />6443/// <reference path="../../DataStructures/AST.ts" />6444/// <reference path="../../Common/Agent.ts" />6445var Compilation;6446(function (Compilation) {6447 var Instructions;6448 (function (Instructions) {6449 "use strict";6450 var ASTNode = DataStructures.ASTNode;6451 var Constants = Helper.Constants;6452 class WgtShow extends ASTNode {6453 constructor() {6454 super(1, 0); // numArgs = 1, numBranches = 06455 }6456 fn(a, scope, args, rets) {6457 var name = args[0];6458 var widget = WidgetManager.getWidgetByName(name);6459 widget.setVisibility(true);6460 rets[1] = Constants.AST_DONE;6461 }6462 to_js_no_yield() {6463 return `6464 WidgetManager.getWidgetByName(${this.args.data[0].to_js_no_yield()}).setVisibility(true);6465 `;6466 }6467 to_js_setup() {6468 return `6469 ${this.args.data[0].to_js_setup()};6470 var __wl_${this.id}_w_name = ${this.args.data[0].to_js_final()};6471 `;6472 }6473 to_js_final() {6474 return `6475 WidgetManager.getWidgetByName(__wl_${this.id}_w_name).setVisibility(true);6476 `;6477 }6478 }6479 Instructions.WgtShow = WgtShow;6480 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));6481})(Compilation || (Compilation = {}));6482/// <reference path="../../dts/widgets.d.ts" />6483/// <reference path="../../Helper/Constants.ts" />6484/// <reference path="../../DataStructures/AST.ts" />6485/// <reference path="../../Common/Agent.ts" />6486var Compilation;6487(function (Compilation) {6488 var Instructions;6489 (function (Instructions) {6490 "use strict";6491 var ASTNode = DataStructures.ASTNode;6492 var Constants = Helper.Constants;6493 class WgtHide extends ASTNode {6494 constructor() {6495 super(1, 0); // numArgs = 1, numBranches = 06496 }6497 fn(a, scope, args, rets) {6498 var name = args[0];6499 var widget = WidgetManager.getWidgetByName(name);6500 widget.setVisibility(false);6501 rets[1] = Constants.AST_DONE;6502 }6503 to_js_no_yield() {6504 return `6505 WidgetManager.getWidgetByName(${this.args.data[0].to_js_no_yield()}).setVisibility(false);6506 `;6507 }6508 to_js_setup() {6509 return `6510 ${this.args.data[0].to_js_setup()};6511 var __wl_${this.id}_w_name = ${this.args.data[0].to_js_final()};6512 `;6513 }6514 to_js_final() {6515 return `6516 WidgetManager.getWidgetByName(__wl_${this.id}_w_name).setVisibility(false);6517 `;6518 }6519 }6520 Instructions.WgtHide = WgtHide;6521 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));6522})(Compilation || (Compilation = {}));6523/// <reference path="../../Helper/Constants.ts" />6524/// <reference path="../../Common/Agent.ts" />6525/// <reference path="../../Execution/AgentController.ts" />6526/// <reference path="UtilTraitHelper.ts" />6527var Compilation;6528(function (Compilation) {6529 var Instructions;6530 (function (Instructions) {6531 "use strict";6532 var Constants = Helper.Constants;6533 var AgentController = Execution.AgentController;6534 var UtilTraitHelper = Compilation.Instructions.UtilTraitHelper;6535 class WrldGetTrait extends UtilTraitHelper {6536 constructor() {6537 super(1, 0); // numArgs = 1, numBranches = 06538 }6539 fn(a, scope, args, rets) {6540 var traitName = String(args[0]);6541 rets[0] = this.traitHelper(AgentController.worldInstance, traitName);6542 rets[1] = Constants.AST_DONE;6543 }6544 to_js_no_yield() {6545 return `6546 Execution.AgentController.worldInstance.getTrait(${this.args.data[0].to_js_no_yield()})6547 `;6548 }6549 to_js_setup() {6550 return `6551 ${this.args.data[0].to_js_setup()};6552 var __wl_${this.id}_name = ${this.args.data[0].to_js_final()};6553 `;6554 }6555 to_js_final() {6556 return `6557 Execution.AgentController.worldInstance.getTrait(__wl_${this.id}_name);6558 `;6559 }6560 }6561 Instructions.WrldGetTrait = WrldGetTrait;6562 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));6563})(Compilation || (Compilation = {}));6564/// <reference path="../../Helper/Constants.ts" />6565/// <reference path="../../Common/Agent.ts" />6566/// <reference path="../../Execution/AgentController.ts" />6567/// <reference path="UtilTraitHelper.ts" />6568var Compilation;6569(function (Compilation) {6570 var Instructions;6571 (function (Instructions) {6572 "use strict";6573 var Constants = Helper.Constants;6574 var AgentController = Execution.AgentController;6575 var UtilTraitHelper = Compilation.Instructions.UtilTraitHelper;6576 class WrldSetTrait extends UtilTraitHelper {6577 constructor() {6578 super(2, 0); // numArgs = 2, numBranches = 06579 }6580 fn(a, scope, args, rets) {6581 var traitName = String(args[0]);6582 var data = String(args[0]);6583 AgentController.worldInstance.setTrait(traitName, data);6584 rets[1] = Constants.AST_DONE;6585 }6586 to_js_no_yield() {6587 return `6588 Execution.AgentController.worldInstance.setTrait(${this.args.data[0].to_js_no_yield()}, ${this.args.data[1].to_js_no_yield()})6589 `;6590 }6591 to_js_setup() {6592 return `6593 ${this.args.data[0].to_js_setup()};6594 ${this.args.data[1].to_js_setup()};6595 var __wl_${this.id}_name = ${this.args.data[0].to_js_final()};6596 var __wl_${this.id}_val = ${this.args.data[1].to_js_final()};6597 `;6598 }6599 to_js_final() {6600 return `6601 Execution.AgentController.worldInstance.setTrait(__wl_${this.id}_name, __wl_${this.id}_val);6602 `;6603 }6604 }6605 Instructions.WrldSetTrait = WrldSetTrait;6606 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));6607})(Compilation || (Compilation = {}));6608/// <reference path="../../Helper/Constants.ts" />6609/// <reference path="../../DataStructures/AST.ts" />6610/// <reference path="../../Common/Agent.ts" />6611/// <reference path="../../Execution/AgentController.ts" />6612var Compilation;6613(function (Compilation) {6614 var Instructions;6615 (function (Instructions) {6616 "use strict";6617 var ASTNode = DataStructures.ASTNode;6618 var Constants = Helper.Constants;6619 var AgentController = Execution.AgentController;6620 class WrldTheWorld extends ASTNode {6621 constructor() {6622 super(0, 0); // numArgs = 0, numBranches = 06623 }6624 fn(a, scope, args, rets) {6625 rets[0] = AgentController.worldInstance;6626 rets[1] = Constants.AST_DONE;6627 }6628 to_js_no_yield() {6629 return `6630 Execution.AgentController.worldInstance6631 `;6632 }6633 to_js_setup() {6634 return ``;6635 }6636 to_js_final() {6637 return `6638 Execution.AgentController.worldInstance6639 `;6640 }6641 }6642 Instructions.WrldTheWorld = WrldTheWorld;6643 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));6644})(Compilation || (Compilation = {}));6645/// <reference path="../../Helper/Constants.ts" />6646/// <reference path="../../DataStructures/AST.ts" />6647/// <reference path="../../Common/Agent.ts" />6648/// <reference path="../../Common/State.ts" />6649var Compilation;6650(function (Compilation) {6651 var Instructions;6652 (function (Instructions) {6653 "use strict";6654 var ASTNode = DataStructures.ASTNode;6655 var Constants = Helper.Constants;6656 var State = Common.State;6657 class Yield extends ASTNode {6658 constructor() {6659 super(0, 0); // numArgs = 0, numBranches = 06660 }6661 can_yield(procs) {6662 return State.generatorSupported;6663 }6664 fn(a, scope, args, rets) {6665 rets[1] = Constants.AST_YIELD;6666 }6667 to_js_no_yield() {6668 return ``;6669 }6670 to_js_setup() {6671 return ``;6672 }6673 to_js_final() {6674 return `6675 yield "${Constants.YIELD_NORMAL}"6676 `;6677 }6678 }6679 Instructions.Yield = Yield;6680 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));6681})(Compilation || (Compilation = {}));6682/// <reference path="Instructions/AgtCreate.ts" />6683/// <reference path="Instructions/AgtCreateDo.ts" />6684/// <reference path="Instructions/AgtDelete.ts" />6685/// <reference path="Instructions/AgtDeleteAgent.ts" />6686/// <reference path="Instructions/AgtDeleteEveryone.ts" />6687/// <reference path="Instructions/AgtMe.ts" />6688/// <reference path="Instructions/AgtMyParent.ts" />6689/// <reference path="Instructions/CalcAbs.ts" />6690/// <reference path="Instructions/CalcArcSinCosTan.ts" />6691/// <reference path="Instructions/CalcDifference.ts" />6692/// <reference path="Instructions/CalcLn.ts" />6693/// <reference path="Instructions/CalcLog.ts" />6694/// <reference path="Instructions/CalcMaxMin.ts" />6695/// <reference path="Instructions/CalcPower.ts" />6696/// <reference path="Instructions/CalcProduct.ts" />6697/// <reference path="Instructions/CalcQuotient.ts" />6698/// <reference path="Instructions/CalcRemainder.ts" />6699/// <reference path="Instructions/CalcRound.ts" />6700/// <reference path="Instructions/CalcSquareRoot.ts" />6701/// <reference path="Instructions/CalcSum.ts" />6702/// <reference path="Instructions/CalcTrigSinCosTan.ts" />6703/// <reference path="Instructions/Clock.ts" />6704/// <reference path="Instructions/ClockSet.ts" />6705/// <reference path="Instructions/Collidee.ts" />6706/// <reference path="Instructions/ColorOptions.ts" />6707/// <reference path="Instructions/ColorRGB.ts" />6708/// <reference path="Instructions/CompAnd.ts" />6709/// <reference path="Instructions/CompEquals.ts" />6710/// <reference path="Instructions/CompNotEquals.ts" />6711/// <reference path="Instructions/CompGreaterThan.ts" />6712/// <reference path="Instructions/CompGreaterThanOrEqualTo.ts" />6713/// <reference path="Instructions/CompLessThan.ts" />6714/// <reference path="Instructions/CompLessThanOrEqualTo.ts" />6715/// <reference path="Instructions/CompNot.ts" />6716/// <reference path="Instructions/CompOr.ts" />6717/// <reference path="Instructions/ConstantTrue.ts" />6718/// <reference path="Instructions/ConstantFalse.ts" />6719/// <reference path="Instructions/ConstantPi.ts" />6720/// <reference path="Instructions/CameraTake.ts" />6721/// <reference path="Instructions/Count.ts" />6722/// <reference path="Instructions/CountWith.ts" />6723/// <reference path="Instructions/DetectCollision.ts" />6724/// <reference path="Instructions/DetectNearest.ts" />6725/// <reference path="Instructions/DetectNearestWith.ts" />6726/// <reference path="Instructions/FaceTowards.ts" />6727/// <reference path="Instructions/GetMyTrait.ts" />6728/// <reference path="Instructions/If.ts" />6729/// <reference path="Instructions/IfElse.ts" />6730/// <reference path="Instructions/KeyHeld.ts" />6731/// <reference path="Instructions/KeyTyped.ts" />6732/// <reference path="Instructions/List.ts" />6733/// <reference path="Instructions/ListContains.ts" />6734/// <reference path="Instructions/ListGet.ts" />6735/// <reference path="Instructions/ListInsert.ts" />6736/// <reference path="Instructions/ListLength.ts" />6737/// <reference path="Instructions/ListSplice.ts" />6738/// <reference path="Instructions/LoopRepeat.ts" />6739/// <reference path="Instructions/LoopWhile.ts" />6740/// <reference path="Instructions/MoveBackward.ts" />6741/// <reference path="Instructions/MoveDown.ts" />6742/// <reference path="Instructions/MoveForward.ts" />6743/// <reference path="Instructions/MoveLeft.ts" />6744/// <reference path="Instructions/MoveRight.ts" />6745/// <reference path="Instructions/MoveTeleport.ts" />6746/// <reference path="Instructions/MoveUp.ts" />6747/// <reference path="Instructions/PrintToJSConsole.ts" />6748/// <reference path="Instructions/ProcCall.ts" />6749/// <reference path="Instructions/ProcParam.ts" />6750/// <reference path="Instructions/ProcReturn.ts" />6751/// <reference path="Instructions/Procedure.ts" />6752/// <reference path="Instructions/RandomDecimal.ts" />6753/// <reference path="Instructions/RandomInteger.ts" />6754/// <reference path="Instructions/RandomPercent.ts" />6755/// <reference path="Instructions/Scatter.ts" />6756/// <reference path="Instructions/ScatterEveryone.ts" />6757/// <reference path="Instructions/SendDataToBackend.ts" />6758/// <reference path="Instructions/SetMyTrait.ts" />6759/// <reference path="Instructions/SetPen.ts" />6760/// <reference path="Instructions/ShapeOptions.ts" />6761/// <reference path="Instructions/SoundOptions.ts" />6762/// <reference path="Instructions/SoundPlay.ts" />6763/// <reference path="Instructions/Stamp.ts" />6764/// <reference path="Instructions/StampGrid.ts" />6765/// <reference path="Instructions/TerrainClear.ts" />6766/// <reference path="Instructions/TerrainColor.ts" />6767/// <reference path="Instructions/TraitOf.ts" />6768/// <reference path="Instructions/VarDefine.ts" />6769/// <reference path="Instructions/VarGet.ts" />6770/// <reference path="Instructions/VarSet.ts" />6771/// <reference path="Instructions/WgtAddDataLineGraph.ts" />6772/// <reference path="Instructions/WgtButtonPush.ts" />6773/// <reference path="Instructions/WgtButtonToggle.ts" />6774/// <reference path="Instructions/WgtButtonToggleSet.ts" />6775/// <reference path="Instructions/WgtClearDataLineGraph.ts" />6776/// <reference path="Instructions/WgtGetLabel.ts" />6777/// <reference path="Instructions/WgtGetSliderValue.ts" />6778/// <reference path="Instructions/WgtGetText.ts" />6779/// <reference path="Instructions/WgtSetLabel.ts" />6780/// <reference path="Instructions/WgtSetText.ts" />6781/// <reference path="Instructions/WgtShow.ts" />6782/// <reference path="Instructions/WgtHide.ts" />6783/// <reference path="Instructions/WrldGetTrait.ts" />6784/// <reference path="Instructions/WrldSetTrait.ts" />6785/// <reference path="Instructions/WrldTheWorld.ts" />6786/// <reference path="Instructions/Yield.ts" />6787/// <reference path="../Helper/Logger.ts" />6788/// <reference path="../DataStructures/BlockPacket.ts" />6789/// <reference path="../DataStructures/AST.ts" />6790var Compilation;6791(function (Compilation) {6792 "use strict";6793 var AgtCreate = Compilation.Instructions.AgtCreate;6794 var AgtCreateDo = Compilation.Instructions.AgtCreateDo;6795 var AgtDelete = Compilation.Instructions.AgtDelete;6796 var AgtDeleteAgent = Compilation.Instructions.AgtDeleteAgent;6797 var AgtDeleteEveryone = Compilation.Instructions.AgtDeleteEveryone;6798 var AgtMe = Compilation.Instructions.AgtMe;6799 var AgtMyParent = Compilation.Instructions.AgtMyParent;6800 var CalcAbs = Compilation.Instructions.CalcAbs;6801 var CalcArcSinCosTan = Compilation.Instructions.CalcArcSinCosTan;6802 var CalcDifference = Compilation.Instructions.CalcDifference;6803 var CalcLn = Compilation.Instructions.CalcLn;6804 var CalcLog = Compilation.Instructions.CalcLog;6805 var CalcMaxMin = Compilation.Instructions.CalcMaxMin;6806 var CalcPower = Compilation.Instructions.CalcPower;6807 var CalcProduct = Compilation.Instructions.CalcProduct;6808 var CalcQuotient = Compilation.Instructions.CalcQuotient;6809 var CalcRemainder = Compilation.Instructions.CalcRemainder;6810 var CalcRound = Compilation.Instructions.CalcRound;6811 var CalcSquareRoot = Compilation.Instructions.CalcSquareRoot;6812 var CalcSum = Compilation.Instructions.CalcSum;6813 var CalcTrigSinCosTan = Compilation.Instructions.CalcTrigSinCosTan;6814 var Clock = Compilation.Instructions.Clock;6815 var ClockSet = Compilation.Instructions.ClockSet;6816 var CameraTake = Compilation.Instructions.CameraTake;6817 var Collidee = Compilation.Instructions.Collidee;6818 var ColorOptions = Compilation.Instructions.ColorOptions;6819 var ColorRGB = Compilation.Instructions.ColorRGB;6820 var CompAnd = Compilation.Instructions.CompAnd;6821 var CompEquals = Compilation.Instructions.CompEquals;6822 var CompNotEquals = Compilation.Instructions.CompNotEquals;6823 var CompGreaterThan = Compilation.Instructions.CompGreaterThan;6824 var CompGreaterThanOrEqualTo = Compilation.Instructions.CompGreaterThanOrEqualTo;6825 var CompLessThan = Compilation.Instructions.CompLessThan;6826 var CompLessThanOrEqualTo = Compilation.Instructions.CompLessThanOrEqualTo;6827 var CompNot = Compilation.Instructions.CompNot;6828 var CompOr = Compilation.Instructions.CompOr;6829 var ConstantTrue = Compilation.Instructions.ConstantTrue;6830 var ConstantFalse = Compilation.Instructions.ConstantFalse;6831 var ConstantPi = Compilation.Instructions.ConstantPi;6832 var Count = Compilation.Instructions.Count;6833 var CountWith = Compilation.Instructions.CountWith;6834 var DetectCollision = Compilation.Instructions.DetectCollision;6835 var DetectNearest = Compilation.Instructions.DetectNearest;6836 var DetectNearestWith = Compilation.Instructions.DetectNearestWith;6837 var FaceTowards = Compilation.Instructions.FaceTowards;6838 var GetMyTrait = Compilation.Instructions.GetMyTrait;6839 var If = Compilation.Instructions.If;6840 var IfElse = Compilation.Instructions.IfElse;6841 var KeyHeld = Compilation.Instructions.KeyHeld;6842 var KeyTyped = Compilation.Instructions.KeyTyped;6843 var List = Compilation.Instructions.CompOr;6844 var ListContains = Compilation.Instructions.ListContains;6845 var ListGet = Compilation.Instructions.ListGet;6846 var ListInsert = Compilation.Instructions.ListInsert;6847 var ListLength = Compilation.Instructions.ListLength;6848 var ListSplice = Compilation.Instructions.ListSplice;6849 var LoopRepeat = Compilation.Instructions.LoopRepeat;6850 var LoopWhile = Compilation.Instructions.LoopWhile;6851 var MoveBackward = Compilation.Instructions.MoveBackward;6852 var MoveDown = Compilation.Instructions.MoveDown;6853 var MoveForward = Compilation.Instructions.MoveForward;6854 var MoveLeft = Compilation.Instructions.MoveLeft;6855 var MoveRight = Compilation.Instructions.MoveRight;6856 var MoveTeleport = Compilation.Instructions.MoveTeleport;6857 var MoveUp = Compilation.Instructions.MoveUp;6858 var PrintToJSConsole = Compilation.Instructions.PrintToJSConsole;6859 var ProcCall = Compilation.Instructions.ProcCall;6860 var ProcParam = Compilation.Instructions.ProcParam;6861 var ProcReturn = Compilation.Instructions.ProcReturn;6862 var Procedure = Compilation.Instructions.Procedure;6863 var RandomDecimal = Compilation.Instructions.RandomDecimal;6864 var RandomInteger = Compilation.Instructions.RandomInteger;6865 var RandomPercent = Compilation.Instructions.RandomPercent;6866 var Scatter = Compilation.Instructions.Scatter;6867 var ScatterEveryone = Compilation.Instructions.ScatterEveryone;6868 var SendDataToBackend = Compilation.Instructions.SendDataToBackend;6869 var SetMyTrait = Compilation.Instructions.SetMyTrait;6870 var SetPen = Compilation.Instructions.SetPen;6871 var ShapeOptions = Compilation.Instructions.ShapeOptions;6872 var SoundOptions = Compilation.Instructions.SoundOptions;6873 var SoundPlay = Compilation.Instructions.SoundPlay;6874 var Stamp = Compilation.Instructions.Stamp;6875 var StampGrid = Compilation.Instructions.StampGrid;6876 var TerrainClear = Compilation.Instructions.TerrainClear;6877 var TerrainColor = Compilation.Instructions.TerrainColor;6878 var TraitOf = Compilation.Instructions.TraitOf;6879 var VarDefine = Compilation.Instructions.VarDefine;6880 var VarGet = Compilation.Instructions.VarGet;6881 var VarSet = Compilation.Instructions.VarSet;6882 var WgtAddDataLineGraph = Compilation.Instructions.WgtAddDataLineGraph;6883 var WgtButtonPush = Compilation.Instructions.WgtButtonPush;6884 var WgtButtonToggle = Compilation.Instructions.WgtButtonToggle;6885 var WgtButtonToggleSet = Compilation.Instructions.WgtButtonToggleSet;6886 var WgtClearDataLineGraph = Compilation.Instructions.WgtClearDataLineGraph;6887 var WgtGetLabel = Compilation.Instructions.WgtGetLabel;6888 var WgtGetSliderValue = Compilation.Instructions.WgtGetSliderValue;6889 var WgtGetText = Compilation.Instructions.WgtGetText;6890 var WgtSetLabel = Compilation.Instructions.WgtSetLabel;6891 var WgtSetText = Compilation.Instructions.WgtSetText;6892 var WgtShow = Compilation.Instructions.WgtShow;6893 var WgtHide = Compilation.Instructions.WgtHide;6894 var WrldGetTrait = Compilation.Instructions.WrldGetTrait;6895 var WrldSetTrait = Compilation.Instructions.WrldSetTrait;6896 var WrldTheWorld = Compilation.Instructions.WrldTheWorld;6897 var Yield = Compilation.Instructions.Yield;6898 var Logger = Helper.Logger;6899 class BlockTable {6900 static makeASTNode(bp) {6901 // Logger.log(`Making ASTNode for ${bp}`);6902 var name = bp.getName();6903 var maker = Compilation.BlockTable.table.get(name);6904 if (maker === undefined) {6905 Logger.error(`Unable to find a match for ${name}`);6906 return undefined;6907 }6908 var node = new maker();6909 node.blockID = bp.getID();6910 return node;6911 }6912 }6913 BlockTable.table = new Map([6914 // Agents6915 ["agt-create", AgtCreate],6916 ["agt-create-do", AgtCreateDo],6917 ["agt-delete", AgtDelete],6918 ["agt-delete-everyone", AgtDeleteEveryone],6919 ["agt-delete-agent", AgtDeleteAgent],6920 ["scatter", Scatter],6921 ["scatter-everyone", ScatterEveryone],6922 ["camera-take", CameraTake],6923 ["agt-me", AgtMe],6924 ["agt-my-parent", AgtMyParent],6925 // Detection6926 ["collision", DetectCollision],6927 ["collidee", Collidee],6928 ["count", Count],6929 ["count-with", CountWith],6930 ["detect-nearest", DetectNearest],6931 ["detect-nearest-with", DetectNearestWith],6932 // Environment6933 ["terrain-clear", TerrainClear],6934 ["stamp", Stamp],6935 ["stamp-grid", StampGrid],6936 ["pen", SetPen],6937 ["terrain-color", TerrainColor],6938 ["clock", Clock],6939 ["clock-set", ClockSet],6940 ["wrld-get-trait", WrldGetTrait],6941 ["wrld-set-trait", WrldSetTrait],6942 ["wrld-the-world", WrldTheWorld],6943 // Interface6944 ["wgt-button-push", WgtButtonPush],6945 ["wgt-button-toggle", WgtButtonToggle],6946 ["wgt-button-toggle-set", WgtButtonToggleSet],6947 ["wgt-hide", WgtHide],6948 ["wgt-show", WgtShow],6949 ["wgt-set-text", WgtSetText],6950 ["wgt-get-text", WgtGetText],6951 ["wgt-set-label", WgtSetLabel],6952 ["wgt-get-label", WgtGetLabel],6953 ["wgt-slider", WgtGetSliderValue],6954 ["wgt-line-graph", WgtAddDataLineGraph],6955 ["wgt-line-graph-clear", WgtClearDataLineGraph],6956 // Keyboard6957 ["key-typed", KeyTyped],6958 ["key-held", KeyHeld],6959 // List6960 ["list", List],6961 ["list-splice", ListSplice],6962 ["list-contains", ListContains],6963 ["list-get", ListGet],6964 ["list-insert", ListInsert],6965 ["list-Length", ListLength],6966 // Logic6967 ["if", If],6968 ["ifelse", IfElse],6969 ["loop-while", LoopWhile],6970 ["random-chance", RandomPercent],6971 ["loop-repeat", LoopRepeat],6972 ["yield", Yield],6973 ["comp-and", CompAnd],6974 ["comp-less-than", CompLessThan],6975 ["comp-greater-than", CompGreaterThan],6976 ["comp-less-than-or-equal-to", CompLessThanOrEqualTo],6977 ["comp-greater-than-or-equal-to", CompGreaterThanOrEqualTo],6978 ["comp-equals", CompEquals],6979 ["comp-not", CompNot],6980 ["comp-not-equals", CompNotEquals],6981 ["comp-or", CompOr],6982 ["constant-true", ConstantTrue],6983 ["constant-false", ConstantFalse],6984 // Math6985 ["calc-abs", CalcAbs],6986 ["calc-arcsincostan", CalcArcSinCosTan],6987 ["calc-difference", CalcDifference],6988 ["calc-ln", CalcLn],6989 ["calc-log", CalcLog],6990 ["calc-min-max", CalcMaxMin],6991 ["calc-power", CalcPower],6992 ["calc-product", CalcProduct],6993 ["calc-quotient", CalcQuotient],6994 ["calc-remainder", CalcRemainder],6995 ["calc-round", CalcRound],6996 ["calc-sincostan", CalcTrigSinCosTan],6997 ["calc-sum", CalcSum],6998 ["calc-squareroot", CalcSquareRoot],6999 ["random-decimal", RandomDecimal],7000 ["random-integer", RandomInteger],7001 ["constant-pi", ConstantPi],7002 // Movement7003 ["move-forward", MoveForward],7004 ["move-backwards", MoveBackward],7005 ["move-left", MoveLeft],7006 ["move-right", MoveRight],7007 ["move-up", MoveUp],7008 ["move-down", MoveDown],7009 ["move-face-towards", FaceTowards],7010 ["move-teleport", MoveTeleport],7011 // Procedures7012 ["procedure", Procedure],7013 ["proc-call", ProcCall],7014 ["proc-call-return", ProcCall],7015 ["proc-param", ProcParam],7016 ["proc-return-early", ProcReturn],7017 // Sounds7018 ["sound-options", SoundOptions],7019 ["sound-play", SoundPlay],7020 // Traits7021 ["trait-get", GetMyTrait],7022 ["trait-set", SetMyTrait],7023 ["trait-of", TraitOf],7024 ["color-rgb", ColorRGB],7025 ["color-options", ColorOptions],7026 ["shape-options", ShapeOptions],7027 ["shape-asset", ShapeOptions],7028 // Variables7029 ["var-define", VarDefine],7030 ["var-set", VarSet],7031 ["var-value", VarGet],7032 // Debugger7033 ["sendDataToBackend", SendDataToBackend],7034 ["printToJS", PrintToJSConsole],7035 ["printToJS-list", PrintToJSConsole],7036 ["printToJS-boolean", PrintToJSConsole],7037 ]);7038 Compilation.BlockTable = BlockTable;7039})(Compilation || (Compilation = {}));7040/// <reference path="../DataStructures/BlockPacket.ts" />7041/// <reference path="../DataStructures/AST.ts" />7042/// <reference path="../Common/ASTNode.ts" />7043/// <reference path="../Common/State.ts" />7044/// <reference path="../Common/Breed.ts" />7045/// <reference path="../Common/Agent.ts" />7046/// <reference path="../Common/Thread.ts" />7047/// <reference path="../Helper/Logger.ts" />7048/// <reference path="../Helper/Utils.ts" />7049/// <reference path="../Execution/Threads/GeneratorRepeatThread.ts" />7050/// <reference path="../Execution/Threads/FunctionRepeatThread.ts" />7051/// <reference path="../Execution/Threads/CollisionThread.ts" />7052/// <reference path="../Execution/AgentController.ts" />7053/// <reference path="../Common/Procedure.ts" />7054/// <reference path="BlockTable.ts" />7055/// <reference path="BlocksReader.ts" />7056/// <reference path="Instructions/ProcParam.ts" />7057var Compilation;7058(function (Compilation) {7059 "use strict";7060 var AgentController = Execution.AgentController;7061 var State = Common.State;7062 var Logger = Helper.Logger;7063 var BlocksReader = Compilation.BlocksReader;7064 var BlockTable = Compilation.BlockTable;7065 var ASTList = DataStructures.ASTList;7066 var UtilEvalData = DataStructures.UtilEvalData;7067 var Procedure = Common.Procedure;7068 var GeneratorRepeatThread = Execution.Threads.GeneratorRepeatThread;7069 var FunctionRepeatThread = Execution.Threads.FunctionRepeatThread;7070 var CollisionThread = Execution.Threads.CollisionThread;7071 var AgtCreateDo = Compilation.Instructions.AgtCreateDo;7072 var VarGet = Compilation.Instructions.VarGet;7073 var VarSet = Compilation.Instructions.VarSet;7074 var VarDefine = Compilation.Instructions.VarDefine;7075 class Compiler {7076 static compileAll() {7077 for (var [procName, procNode] of State.procedureRoots) {7078 if (procNode.can_yield(new Set())) {7079 State.procedureGenerators.set(procName, procNode.make_generator());7080 }7081 else {7082 State.procedureFunctions.set(procName, procNode.make_function());7083 }7084 }7085 for (var breedID = 0, len = State.buttonMap.length; breedID < len; breedID++) {7086 var nodes = State.buttonMap[breedID];7087 if (nodes !== undefined) {7088 for (var node of nodes) {7089 Compilation.Compiler.compileNode(breedID, node);7090 }7091 }7092 }7093 for (var collisionDict of State.collisionDict.values()) {7094 for (var node of collisionDict.values()) {7095 Compilation.Compiler.compileNode(undefined, node);7096 }7097 }7098 // get the possible colliding breed pairs7099 var breedIDs = AgentController.getBreedIDs();7100 var everyoneID = AgentController.EVERYONE.id;7101 if (State.collisionDict.get(everyoneID).size > 0) {7102 State.collidingBreeds = new Set(breedIDs);7103 }7104 else {7105 State.collidingBreeds = new Set();7106 for (var i = 0; i < breedIDs.length; i++) {7107 var breedID = breedIDs[i];7108 if (State.collisionDict.get(breedID).size > 0) {7109 State.collidingBreeds.add(breedID);7110 }7111 }7112 }7113 for (var collidingBreed of State.collidingBreeds) {7114 if (State.collisionDict.get(everyoneID).has(everyoneID) ||7115 State.collisionDict.get(collidingBreed).has(everyoneID)) {7116 State.collidedBreeds.set(collidingBreed, breedIDs.slice(0));7117 }7118 else {7119 State.collidedBreeds.set(collidingBreed, Array.from([7120 ...State.collisionDict.get(everyoneID).keys(),7121 ...State.collisionDict.get(collidingBreed).keys(),7122 ]));7123 }7124 }7125 }7126 static compileNode(breedID, node) {7127 var buttonName = State.jsBtnNames.get(node);7128 if (node.can_yield(new Set())) {7129 node.yields = true;7130 var gen = node.make_generator();7131 State.jsGenerators.set(node, gen);7132 if (breedID === AgentController.WORLD.id) {7133 var world = AgentController.worldInstance;7134 var jsThread = new GeneratorRepeatThread(world, buttonName, gen);7135 world.jsthreads.push(jsThread);7136 }7137 }7138 else {7139 node.yields = false;7140 var fun = node.make_function();7141 State.jsFunctions.set(node, fun);7142 if (breedID === AgentController.WORLD.id) {7143 var world = AgentController.worldInstance;7144 var thread = new FunctionRepeatThread(world, buttonName, fun);7145 world.jsthreads.push(thread);7146 }7147 }7148 }7149 // All at once7150 static createTopBlock(bp) {7151 var topLevelNames = ["collision", "procedure", "wgt-button-push", "wgt-button-toggle"];7152 if (topLevelNames.indexOf(bp.getName()) < 0) {7153 return;7154 }7155 var node;7156 if (bp.getName() === "procedure") {7157 node = Compilation.Compiler.createProcedure(bp);7158 }7159 else {7160 node = Compilation.Compiler.createHelper(bp, undefined, undefined);7161 }7162 var breedName = BlocksReader.getPageName(bp);7163 var breed = AgentController.getByName(breedName);7164 switch (bp.getName()) {7165 case "collision":7166 {7167 var otherBreedName = BlocksReader.getLabel(bp.getID(), 0);7168 var otherBreed = AgentController.getByName(otherBreedName);7169 State.collisionDict.get(breed.id).set(otherBreed.id, node);7170 State.collisionsOn = true;7171 State.binningOn = true;7172 }7173 break;7174 case "procedure":7175 {7176 var procName = String(BlocksReader.getInternalArg(bp.getID(), 0));7177 var fullProcName = `${breed.name}${procName}`;7178 State.procedureRoots.set(fullProcName, node);7179 var proc = Procedure.makeNew(fullProcName);7180 for (var i = 2; i < node.args.data.length; i++) {7181 proc.params.push(node.args.data[i].getData());7182 }7183 }7184 break;7185 case "wgt-button-push":7186 {7187 State.buttonMap[breed.id].push(node);7188 var btnName = node.args.data[0].getData();7189 State.jsBtnNames.set(node, btnName);7190 }7191 break;7192 case "wgt-button-toggle":7193 {7194 State.buttonMap[breed.id].push(node);7195 var btnName = node.args.data[0].getData();7196 State.jsBtnNames.set(node, btnName);7197 }7198 break;7199 default: {7200 throw new Error(`Unknown block packet type: ${bp.getName()}`);7201 }7202 }7203 // if "AgtCreateDo" is somewhere in this tree, then mark all variable instructions with7204 // useParentScope = true7205 var nodes = [node];7206 var agtCreateDoPresent = false;7207 while (nodes.length > 0) {7208 var curNode = nodes.splice(0, 1)[0]; // pop from the head of the queue7209 if (curNode === undefined) {7210 continue;7211 }7212 if (curNode instanceof AgtCreateDo) {7213 agtCreateDoPresent = true;7214 break;7215 }7216 for (var arg of curNode.args.data) {7217 nodes.push(arg);7218 }7219 for (var branch of curNode.branches) {7220 for (var childNode of branch.data) {7221 nodes.push(childNode);7222 }7223 }7224 }7225 if (agtCreateDoPresent) {7226 nodes = [node];7227 while (nodes.length > 0) {7228 var curNode = nodes.splice(0, 1)[0]; // pop from the head of the queue7229 if (curNode === undefined) {7230 continue;7231 }7232 if (curNode instanceof VarDefine || curNode instanceof VarSet || curNode instanceof VarGet) {7233 curNode.useParentScope = true;7234 }7235 for (var arg of curNode.args.data) {7236 nodes.push(arg);7237 }7238 for (var branch of curNode.branches) {7239 for (var childNode of branch.data) {7240 nodes.push(childNode);7241 }7242 }7243 }7244 }7245 }7246 static createProcedure(bp) {7247 var node = BlockTable.makeASTNode(bp);7248 var len = BlocksReader.getSBLength(bp.getID());7249 var numArgs = Math.floor(len / 3) - 1;7250 // set the name7251 var breedName = BlocksReader.getPageName(bp);7252 var procName = BlocksReader.getInternalArg(bp.getID(), 0);7253 node.args.data[0] = new UtilEvalData(`${breedName}${procName}`);7254 // set the return socket, if any7255 if (len % 3 === 2) {7256 var arg = BlocksReader.getInternalArg(bp.getID(), len - (len % 3));7257 if (typeof (arg) === "string") {7258 node.args[1] = new UtilEvalData(arg);7259 }7260 else {7261 var blockID = Number(arg.getID().replace(/^\D+/g, ""));7262 node.args[1] = Compilation.Compiler.createHelper(BlocksReader.getBlock(blockID), node, node);7263 }7264 }7265 for (var idx = 0; idx < numArgs; idx++) {7266 var arg = BlocksReader.getInternalArg(bp.getID(), 2 + 3 * idx);7267 node.args.data[2 + idx] = new UtilEvalData(arg);7268 }7269 node.numArgs = node.args.data.length;7270 node.branches[0] = new ASTList();7271 var branchBP = BlocksReader.getSB(bp.getID(), len - (len % 3) - 1);7272 while (branchBP !== undefined) {7273 node.branches[0].data.push(Compilation.Compiler.createHelper(branchBP, node, node));7274 branchBP = BlocksReader.getAfterBlock(branchBP);7275 }7276 return node;7277 }7278 static createHelper(bp, parent, procedureRoot) {7279 var node = BlockTable.makeASTNode(bp);7280 // Logger.assert(bp.getName() !== "procedure");7281 var blockName = bp.getName();7282 if (blockName === "proc-call" || blockName === "proc-call-return") {7283 node.numArgs = BlocksReader.getSBLength(bp.getID());7284 }7285 else if (blockName === "proc-param") {7286 node.procName = procedureRoot.args.data[0].getData();7287 }7288 else if (blockName === "count" || blockName === "count-with" ||7289 blockName === "detect-nearest" || blockName === "detect-nearest-with") {7290 State.binningOn = true;7291 }7292 var idx = 0;7293 for (var aIdx = 0; aIdx < node.numArgs; aIdx++, idx++) {7294 var arg = BlocksReader.getInternalArg(bp.getID(), idx);7295 if (typeof (arg) === "string") {7296 node.args.data[aIdx] = new UtilEvalData(arg);7297 }7298 else {7299 var blockID = Number(arg.getID().replace(/^\D+/g, ""));7300 node.args.data[aIdx] = Compilation.Compiler.createHelper(BlocksReader.getBlock(blockID), node, procedureRoot);7301 }7302 }7303 for (var bIdx = 0; bIdx < node.numBranches; bIdx++, idx++) {7304 node.branches[bIdx] = new ASTList();7305 var branchBP = BlocksReader.getSB(bp.getID(), idx);7306 while (branchBP !== undefined) {7307 node.branches[bIdx].data.push(Compilation.Compiler.createHelper(branchBP, node, procedureRoot));7308 branchBP = BlocksReader.getAfterBlock(branchBP);7309 }7310 }7311 return node;7312 }7313 static make_thread(node, a) {7314 var buttonName = State.jsBtnNames.get(node);7315 if (node.yields) {7316 return new GeneratorRepeatThread(a, buttonName, State.jsGenerators.get(node));7317 }7318 else {7319 return new FunctionRepeatThread(a, buttonName, State.jsFunctions.get(node));7320 }7321 }7322 static make_collision_thread(node, a, b) {7323 // Logger.assert(node.yields === true);7324 return new CollisionThread(a, State.jsGenerators.get(node), b);7325 }7326 }7327 Compilation.Compiler = Compiler;7328})(Compilation || (Compilation = {}));7329/// <reference path="../Helper/Constants.ts" />7330/// <reference path="../Helper/Logger.ts" />7331/// <reference path="../Helper/Utils.ts" />7332/// <reference path="../Common/State.ts" />7333/// <reference path="../Common/Agent.ts" />7334/// <reference path="../Common/Breed.ts" />7335/// <reference path="../Common/Thread.ts" />7336/// <reference path="../Common/Trait.ts" />7337/// <reference path="../Compilation/Compiler.ts" />7338/// <reference path="../DataStructures/Bin.ts" />7339/// <reference path="../DataStructures/AST.ts" />7340/// <reference path="../dts/viewport.d.ts" />7341/// <reference path="Threads/GeneratorRepeatThread.ts" />7342/// <reference path="Collisions.ts" />7343/// <reference path="AgentController.ts" />7344/// <reference path="Threads/GeneratorRepeatThread.ts" />7345var Execution;7346(function (Execution) {7347 "use strict";7348 var State = Common.State;7349 var Compiler = Compilation.Compiler;7350 var AgentController = Execution.AgentController;7351 var Constants = Helper.Constants;7352 var Collisions = Execution.Collisions;7353 var Logger = Helper.Logger;7354 var Utils = Helper.Utils;7355 class Agent {7356 /**7357 * Agents hold the state and threads of their WebLand representations. Note that by default, new agents7358 * are added to the agent queue and initialized with any running threads of their breed.7359 * @param snapshot:Boolean=False - setting this to true will 'snapshot' an agent instead of creating it,7360 * thereby preventing it from being initialized with threads or added to the AgentQueue7361 */7362 constructor(breed, parent, state, snapShot) {7363 this.isAgent = true;7364 this.isPenDown = false;7365 this.hasCamera = false;7366 this.isDead = false;7367 this.isSnapshot = false;7368 ///////////////////////////AGENT ENGINE//////////////////////////7369 this.threads = new Map();7370 this.jsthreads = new Array();7371 /** Binning system to assist smell */7372 this.bins = [];7373 this.jbins = [];7374 this.disabledButtons = new Set();7375 this.enabledButtons = new Set();7376 // Logger.log(`Constructing a new ${breed}`);7377 this.breed = breed;7378 this.parent = parent;7379 this.state = state || new Execution.AgentState();7380 this.prevState = new Execution.AgentState();7381 this.isSnapshot = snapShot;7382 this.traits = new Array(this.breed.customTraits.length);7383 if (this.isSnapshot) {7384 this.id = this.parent.id;7385 this.original = parent;7386 }7387 else {7388 // snapshots will get their id's from the agent they are a clone of7389 this.id = Execution.Agent.idBase++;7390 this.cacheVisibleState();7391 this.state.shape = breed.shape;7392 // Compiles EVERYONE blocks and pushes to each agent's jsthreads7393 var everyoneNodes = State.buttonMap[AgentController.EVERYONE.id] || [];7394 for (var i = 0, len = everyoneNodes.length; i < len; i++) {7395 var node = everyoneNodes[i];7396 this.jsthreads.push(Compiler.make_thread(node, this));7397 }7398 var nodes = State.buttonMap[breed.id] || [];7399 for (var i = 0, len = nodes.length; i < len; i++) {7400 var node = nodes[i];7401 this.jsthreads.push(Compiler.make_thread(node, this));7402 }7403 AgentController.insert(this);7404 }7405 }7406 /**7407 * Copies the values of all in-common custom traits from source to dest agent.7408 */7409 static copyCustomTraits(source, dest) {7410 if (source.breed === dest.breed) {7411 for (var traitID = 0, len = dest.traits.length; traitID < len; traitID++) {7412 dest.traits[traitID] = source.traits[traitID];7413 }7414 }7415 // set previous state to be the source's current traits7416 // (so hatchlings start at parent's position and move on from there)7417 dest.prevState = source.state.copy();7418 }7419 static snapShot(a) {7420 var newAgent = new Execution.Agent(a.breed, a, a.state.copy(), true);7421 Execution.Agent.copyCustomTraits(a, newAgent);7422 return newAgent;7423 }7424 updateBin() {7425 if (State.binningOn) {7426 Collisions.update(this);7427 }7428 }7429 clone(breedName) {7430 breedName = breedName || this.breed.name;7431 var breed = AgentController.getByName(breedName);7432 var newAgent = new Execution.Agent(breed, this, this.state.copy());7433 Execution.Agent.copyCustomTraits(this, newAgent);7434 return newAgent;7435 }7436 reset() {7437 this.threads = new Map();7438 }7439 /**7440 * Removes agent from queue and closes its threads7441 */7442 die() {7443 if (!this.isDead) {7444 // mark the agent as "dead" in case any blocks or the camera have a reference to it7445 this.isDead = true;7446 AgentController.remove(this);7447 // forget who your parent is so that the parent can be garbage collected7448 this.parent = undefined;7449 if (this.hasCamera) {7450 viewport.setCameraAgent(undefined, undefined);7451 }7452 }7453 }7454 ////////////////////////////////////////////////////////////////////////////////////////7455 ///////////////////////////////////////SETTERS//////////////////////////////////////////7456 ////////////////////////////////////////////////////////////////////////////////////////7457 safeSetColor(color) {7458 this.state.color = (color % 0x1000000);7459 }7460 safeSetSize(size) {7461 this.state.size = Math.max(size, 0);7462 }7463 ////////////////////////////////////////////////////////////////////////////////////////7464 ////////////////////////////////////////MOVEMENT////////////////////////////////////////7465 safeSetX(x) {7466 this.state.x = Math.min(Math.max(-Constants.MAPSIZE, x), Constants.MAPSIZE);7467 }7468 safeSetY(y) {7469 this.state.y = Math.min(Math.max(-Constants.MAPSIZE, y), Constants.MAPSIZE);7470 }7471 safeSetZ(z) {7472 this.state.z = Math.min(Math.max(-Constants.MAPCEILING, z), Constants.MAPCEILING);7473 }7474 safeSetHeading(x) {7475 this.state.heading = (x + 360) % 360; // convert negative to positive7476 }7477 safeSetShape(newShape) {7478 this.state.shape = newShape;7479 }7480 scatter() {7481 var size = Constants.MAPSIZE;7482 var x = (Utils.random() * size * 2) - size;7483 var y = (Utils.random() * size * 2) - size;7484 this.state.x = x;7485 this.state.y = y;7486 this.state.heading = Utils.random() * 360;7487 // update previous state as well to achieve a teleportation effect7488 this.prevState = this.state.copy();7489 }7490 getTrait(trait) {7491 switch (trait) {7492 case "x":7493 return this.state.x;7494 case "y":7495 return this.state.y;7496 case "z":7497 return this.state.z;7498 case "color":7499 return this.state.color;7500 case "shape":7501 return this.state.shape;7502 case "heading":7503 return this.state.heading;7504 case "size":7505 return this.state.size;7506 case "breed":7507 return this.breed.name;7508 case "id":7509 return this.id;7510 default:7511 var traitID = this.breed.getTraitID(trait);7512 var value = this.traits[traitID];7513 if (!isNaN(Number(value))) {7514 return Number(value);7515 }7516 return value;7517 }7518 }7519 setTrait(trait, val) {7520 switch (trait) {7521 case "x":7522 this.safeSetX(Number(val));7523 return;7524 case "y":7525 this.safeSetY(Number(val));7526 return;7527 case "z":7528 this.safeSetZ(Number(val));7529 return;7530 case "color":7531 this.safeSetColor(Number(val));7532 return;7533 case "shape":7534 this.safeSetShape(String(val));7535 return;7536 case "heading":7537 this.safeSetHeading(Number(val));7538 return;7539 case "size":7540 this.safeSetSize(Number(val));7541 return;7542 default:7543 var traitID = this.breed.getTraitID(trait);7544 this.traits[traitID] = val;7545 return;7546 }7547 }7548 /**7549 * Precalculates all of the bounces necessary to place the agent in an equivalent7550 * location inside the map, and places the agent there.7551 */7552 bounce() {7553 if (this.state.x > Constants.MAPSIZE) {7554 this.state.x = (2 * Constants.MAPSIZE - this.state.x);7555 this.safeSetHeading(180 - this.state.heading);7556 this.bounce();7557 }7558 else if (this.state.x < -Constants.MAPSIZE) {7559 this.state.x = (-2 * Constants.MAPSIZE - this.state.x);7560 this.safeSetHeading(180 - this.state.heading);7561 this.bounce();7562 }7563 else if (this.state.y > Constants.MAPSIZE) {7564 this.state.y = (2 * Constants.MAPSIZE - this.state.y);7565 this.safeSetHeading(-this.state.heading);7566 this.bounce();7567 }7568 else if (this.state.y < -Constants.MAPSIZE) {7569 this.state.y = (-2 * Constants.MAPSIZE - this.state.y);7570 this.safeSetHeading(-this.state.heading);7571 this.bounce();7572 }7573 }7574 /**7575 * Assumes that the agent's x and y have already been updated, but may be outside7576 * the bounds of the terrain. If so, draws lines and reflects off edges until the7577 * agent is located inside.7578 * @param currentX, currentY - the starting location of the agent7579 * @param deltaX, deltaY - the slope components (passed on through calls to avoid trig calls)7580 */7581 bounceDraw(currentX, currentY, deltaX, deltaY, r, g, b) {7582 var oldX = currentX;7583 var oldY = currentY;7584 var distToLeft = (currentX + Constants.MAPSIZE) / -deltaX;7585 var distToRight = (Constants.MAPSIZE - currentX) / deltaX;7586 var distToBottom = (currentY + Constants.MAPSIZE) / -deltaY;7587 var distToTop = (Constants.MAPSIZE - currentY) / deltaY;7588 // we need to find the closest border more than 0 away7589 distToLeft = distToLeft > 0 ? distToLeft : Infinity;7590 distToRight = distToRight > 0 ? distToRight : Infinity;7591 distToBottom = distToBottom > 0 ? distToBottom : Infinity;7592 distToTop = distToTop > 0 ? distToTop : Infinity;7593 var minDistance = Math.min(distToLeft, distToRight, distToBottom, distToTop);7594 // recursively bounce off the nearest border and then continue...7595 if (this.state.x < -Constants.MAPSIZE && minDistance == distToLeft) {7596 this.state.x = (-2 * Constants.MAPSIZE - this.state.x);7597 this.safeSetHeading(180 - this.state.heading);7598 currentX = -Constants.MAPSIZE;7599 currentY += distToLeft * deltaY;7600 deltaX = -deltaX;7601 viewport.terrain.line(oldX, oldY, currentX, currentY, this.state.size, r, g, b);7602 this.bounceDraw(currentX, currentY, deltaX, deltaY, r, g, b);7603 }7604 else if (this.state.x > Constants.MAPSIZE && minDistance == distToRight) {7605 this.state.x = (2 * Constants.MAPSIZE - this.state.x);7606 this.safeSetHeading(180 - this.state.heading);7607 currentX = Constants.MAPSIZE;7608 currentY += distToRight * deltaY;7609 deltaX = -deltaX;7610 viewport.terrain.line(oldX, oldY, currentX, currentY, this.state.size, r, g, b);7611 this.bounceDraw(currentX, currentY, deltaX, deltaY, r, g, b);7612 }7613 else if (this.state.y < -Constants.MAPSIZE && minDistance == distToBottom) {7614 this.state.y = (-2 * Constants.MAPSIZE - this.state.y);7615 this.safeSetHeading(-this.state.heading);7616 currentX += distToBottom * deltaX;7617 currentY = -Constants.MAPSIZE;7618 deltaY = -deltaY;7619 viewport.terrain.line(oldX, oldY, currentX, currentY, this.state.size, r, g, b);7620 this.bounceDraw(currentX, currentY, deltaX, deltaY, r, g, b);7621 }7622 else if (this.state.y > Constants.MAPSIZE && minDistance == distToTop) {7623 this.state.y = (2 * Constants.MAPSIZE - this.state.y);7624 this.safeSetHeading(-this.state.heading);7625 currentX += distToTop * deltaX;7626 currentY = Constants.MAPSIZE;7627 deltaY = -deltaY;7628 viewport.terrain.line(oldX, oldY, currentX, currentY, this.state.size, r, g, b);7629 this.bounceDraw(currentX, currentY, deltaX, deltaY, r, g, b);7630 }7631 else {7632 viewport.terrain.line(oldX, oldY, this.state.x, this.state.y, this.state.size, r, g, b);7633 }7634 }7635 faceTowards(a) {7636 if (a !== undefined && a.isAgent) {7637 var x = a.state.x;7638 var y = a.state.y;7639 if (this.state.x !== x || this.state.y !== y) {7640 this.safeSetHeading(Math.atan2(y - this.state.y, x - this.state.x) * 180 / Math.PI);7641 }7642 }7643 }7644 moveForward(amount) {7645 var angle = this.state.heading / 180 * Math.PI;7646 var oldX = this.state.x;7647 var oldY = this.state.y;7648 var deltaX = Math.cos(angle);7649 var deltaY = Math.sin(angle);7650 this.state.x += amount * deltaX; // dx;7651 this.state.y += amount * deltaY; // dy; 7652 if (this.isPenDown) {7653 /* tslint:disable bitwise */7654 var r = (this.state.color & 0xFF0000) >> 16;7655 var g = (this.state.color & 0x00FF00) >> 8;7656 var b = (this.state.color & 0x0000FF) >> 0;7657 /* tslint:enable bitwise */7658 this.bounceDraw(oldX, oldY, (amount < 0 ? -deltaX : deltaX), (amount < 0 ? -deltaY : deltaY), r, g, b);7659 }7660 else {7661 this.bounce();7662 }7663 }7664 equals(other) {7665 return this.id === other.id;7666 }7667 cacheVisibleState() {7668 this.prevState = this.state.copy();7669 }7670 setToggleButton(name, disable) {7671 if (disable) {7672 this.disabledButtons.add(name);7673 this.enabledButtons.delete(name);7674 }7675 else {7676 this.disabledButtons.delete(name);7677 this.enabledButtons.add(name);7678 }7679 }7680 isButtonEnabled(name) {7681 // Logger.assert(!(this.disabledButtons.has(name) && this.enabledButtons.has(name)));7682 return this.enabledButtons.has(name);7683 }7684 isButtonDisabled(name) {7685 // Logger.assert(!(this.disabledButtons.has(name) && this.enabledButtons.has(name)));7686 return this.disabledButtons.has(name);7687 }7688 toString() {7689 return `<Agent ${this.id}, breed: ${this.breed}>`;7690 }7691 }7692 Agent.idBase = 0;7693 Execution.Agent = Agent;7694})(Execution || (Execution = {}));7695/// <reference path="../Common/State.ts" />7696/// <reference path="../Common/Breed.ts" />7697/// <reference path="../Common/Thread.ts" />7698/// <reference path="../Compilation/Compiler.ts" />7699/// <reference path="../Helper/Logger.ts" />7700/// <reference path="../Helper/KeyManager.ts" />7701/// <reference path="../Helper/Utils.ts" />7702/// <reference path="../DataStructures/CollisionPair.ts" />7703/// <reference path="../DataStructures/BlockPacket.ts" />7704/// <reference path="../DataStructures/AST.ts" />7705/// <reference path="../dts/widgets.d.ts" />7706/// <reference path="Threads/SingleFunctionThread.ts" />7707/// <reference path="Threads/SetupThread.ts" />7708/// <reference path="Collisions.ts" />7709/// <reference path="AgentController.ts" />7710/// <reference path="Agent.ts" />7711var Execution;7712(function (Execution) {7713 "use strict";7714 var Compiler = Compilation.Compiler;7715 var Agent = Execution.Agent;7716 var State = Common.State;7717 var SingleFunctionThread = Execution.Threads.SingleFunctionThread;7718 var SetupThread = Execution.Threads.SetupThread;7719 var AgentController = Execution.AgentController;7720 var Collisions = Execution.Collisions;7721 var Logger = Helper.Logger;7722 var KeyManager = Helper.KeyManager;7723 var PushButtonWidget = slnova.PushButtonWidget;7724 var ToggleButtonWidget = slnova.ToggleButtonWidget;7725 class Engine {7726 static tick() {7727 // var has better scoping than var, but has poorer performance so we use var for tight loops7728 // see https://gist.github.com/jinpan/4ee227ba4699e433c8406b118bf731667729 /* tslint:disable no-var-keyword */7730 // Logger.log(`Engine tick toJS ${State.clock}, ${AgentController.getAllAgents().length} agents`);7731 var somethingRan = false;7732 var pushButtons = WidgetManager.getWidgetsByType(PushButtonWidget);7733 for (var i = 0; i < pushButtons.length; i++) {7734 var pbw = pushButtons[i];7735 if (pbw.checkPushed()) {7736 var btnName = pbw.getName();7737 if (State.pushButtonRunning.get(btnName)) {7738 Execution.Engine.killThreads(btnName);7739 }7740 else {7741 State.pushedButtons.add(btnName);7742 }7743 }7744 }7745 State.pushButtonRunning.clear();7746 var toggleButtons = WidgetManager.getWidgetsByType(ToggleButtonWidget);7747 for (var i = 0; i < toggleButtons.length; i++) {7748 var tbw = toggleButtons[i];7749 if (tbw.isToggled()) {7750 State.toggledButtons.add(tbw.getName());7751 }7752 }7753 var numAgents = AgentController.numAgents;7754 if (State.pushedButtons.size > 0 || State.toggledButtons.size > 0 || State.runnable) {7755 State.runnable = false;7756 for (var i = 0; i < numAgents; i++) {7757 var a = AgentController.data[i];7758 a.prevState.copyFrom(a.state);7759 AgentController.prevStates[i] = a.prevState; // TODO djw - Why isn't this already the case???7760 var startX = a.state.x;7761 var startY = a.state.y;7762 var startS = a.state.size;7763 var finishedThreads = new Array();7764 for (var j = 0; j < a.jsthreads.length; j++) {7765 var done = a.jsthreads[j].step();7766 if (done) {7767 finishedThreads.push(j);7768 }7769 else {7770 State.runnable = State.runnable || a.jsthreads[j].yielded;7771 }7772 somethingRan = true;7773 }7774 for (var j = finishedThreads.length; j > 0; j--) {7775 a.jsthreads.splice(j - 1, 1);7776 }7777 if (State.binningOn) {7778 if (!a.isDead && (a.state.x !== startX || a.state.y !== startY || a.state.size !== startS)) {7779 a.updateBin();7780 }7781 }7782 }7783 }7784 State.runnable = State.runnable || AgentController.numAgents > numAgents;7785 if (State.collisionsOn && (somethingRan || State.collisionsLastRun)) {7786 var collisions = Collisions.getCollisions();7787 State.collisionsLastRun = (collisions.length > 0);7788 somethingRan = somethingRan || State.collisionsLastRun;7789 if (collisions.length > 0) {7790 // Logger.log(`# Collisions = ${collisions.length}`);7791 for (var i = 0; i < collisions.length; i++) {7792 var collision = collisions[i];7793 var a1 = collision.a;7794 var a2 = collision.b;7795 if (!a1.isDead && !a2.isDead) {7796 Execution.Engine.tryCollide(a1, a2);7797 }7798 }7799 }7800 }7801 if (State.binningOn) {7802 for (var i = 0; i < AgentController.numAgents; i++) {7803 var agent = AgentController.data[i];7804 if (agent.isDead && agent.jbins.length > 0) {7805 Collisions.remove(agent);7806 }7807 }7808 }7809 AgentController.clearDead();7810 KeyManager.tick();7811 State.pushedButtons.clear();7812 State.toggledButtons.clear();7813 if (somethingRan) {7814 State.clock++;7815 }7816 return somethingRan;7817 /* tslint:enable no-var-keyword */7818 }7819 /**7820 * Attempts to run collision code on two colliding agents. Both agents save their state, run collision code7821 * on that state, and save any changes to the AgentList when finished7822 * @returns Array the agents, updated after the collision7823 */7824 static tryCollide(agent1, agent2) {7825 var agent1Copy = undefined;7826 var agent2Copy = undefined;7827 if (Execution.Engine.canCollide(agent1, agent2)) {7828 // before colliding, snapshot each agent so that each7829 // agent gets an unaltered copy of the other one rather than having7830 // the first collision potentially mess up state before the second one.7831 agent2Copy = Agent.snapShot(agent2);7832 // Collide the two agents, using the copy of Agent 2 so it can't be messed up7833 Execution.Engine.collide(agent1, agent2Copy);7834 }7835 if (Execution.Engine.canCollide(agent2, agent1)) {7836 // if we didn't collide in the other direction, we still need to7837 // copy Agent 1's data so Agent 1 can't be messed with via Agent 2's code7838 agent1Copy = Agent.snapShot(agent1);7839 Execution.Engine.collide(agent2, agent1Copy);7840 }7841 }7842 /**7843 * Returns whether or not two agents can collide with one another7844 * @param collider: Agent the collider agent, who would run the code7845 * @param collidee: Agent the other, colliding agent7846 * @returns Boolean true if the two agents can collide, in the given order7847 */7848 static canCollide(collider, collidee) {7849 return (State.collisionDict.get(AgentController.EVERYONE.id).has(AgentController.EVERYONE.id) ||7850 State.collisionDict.get(AgentController.EVERYONE.id).has(collidee.breed.id) ||7851 State.collisionDict.get(collider.breed.id).has(AgentController.EVERYONE.id) ||7852 State.collisionDict.get(collider.breed.id).has(collidee.breed.id));7853 }7854 /**7855 * Executes a one sided collision, returning the updated agent7856 * @param collider: Agent the colliding agent executing the code7857 * @param collidee: Agent the agent being collided with7858 * @returns The agent, updated after the collision7859 */7860 static collide(collider, collidee) {7861 var nodes = [7862 State.collisionDict.get(AgentController.EVERYONE.id).get(AgentController.EVERYONE.id),7863 State.collisionDict.get(AgentController.EVERYONE.id).get(collidee.breed.id),7864 State.collisionDict.get(collider.breed.id).get(AgentController.EVERYONE.id),7865 State.collisionDict.get(collider.breed.id).get(collidee.breed.id),7866 ];7867 for (var i = 0; i < 4; i++) {7868 var node = nodes[i];7869 if (node !== undefined) {7870 if (node.yields) {7871 var collisionThread = Compiler.make_collision_thread(node, collider, collidee);7872 var done = collisionThread.step();7873 if (!done) {7874 collider.jsthreads.push(collisionThread);7875 }7876 }7877 else {7878 collider.collidee = collidee;7879 State.jsFunctions.get(node)(collider, new SingleFunctionThread());7880 collider.collidee = undefined;7881 }7882 }7883 }7884 }7885 static killThreads(buttonName) {7886 for (var i = 0; i < AgentController.numAgents; i++) {7887 var agent = AgentController.data[i];7888 for (var j = 0; j < agent.jsthreads.length; j++) {7889 var t = agent.jsthreads[j];7890 if (t.buttonName === buttonName) {7891 if (t instanceof SetupThread) {7892 agent.jsthreads.splice(j, 1);7893 j--;7894 }7895 else {7896 var rt = t;7897 rt.restart();7898 }7899 }7900 }7901 }7902 }7903 }7904 Execution.Engine = Engine;7905})(Execution || (Execution = {}));7906/// <reference path="Agent.ts" />7907/// <reference path="AgentController.ts" />7908var Execution;7909(function (Execution) {7910 "use strict";7911 var AgentController = Execution.AgentController;7912 var Agent = Execution.Agent;7913 class Observer extends Agent {7914 constructor() {7915 super(AgentController.WORLD, undefined);7916 this.parent = this;7917 }7918 /* tslint:disable no-empty */7919 /**7920 * Override die to ensure the observer agent cannot be removed7921 */7922 die() { }7923 /**7924 * Override Agent setters to ensure the world's default traits don't change7925 */7926 safeSetColor(color) { }7927 safeSetX(x) { }7928 safeSetY(y) { }7929 safeSetZ(z) { }7930 safeSetHeading(x) { }7931 safeSetSize(size) { }7932 safeSetShape(newShape) { }7933 /**7934 * Override other mutators to prevent users from modifying world's traits that way7935 */7936 scatter() { }7937 bounce() { }7938 bounceDraw(currentX, currentY, deltaX, deltaY, r, g, b) { }7939 faceTowards(a) { }7940 moveForward(amout) { }7941 }7942 Execution.Observer = Observer;7943})(Execution || (Execution = {}));7944/// <reference path="../Compilation/BlocksReader.ts" />7945/// <reference path="../Compilation/Compiler.ts" />7946/// <reference path="../Compilation/Instructions/Procedure.ts" />7947/// <reference path="../Compilation/Instructions/ProcCall.ts" />7948/// <reference path="../Common/State.ts" />7949/// <reference path="../Common/IWebLogo.ts" />7950/// <reference path="../Execution/AgentController.ts" />7951/// <reference path="../Execution/Observer.ts" />7952/// <reference path="../Execution/Collisions.ts" />7953/// <reference path="../DataStructures/BlockPacket.ts" />7954/// <reference path="../DataStructures/AST.ts" />7955/// <reference path="../Helper/Constants.ts" />7956/// <reference path="../Helper/Logger.ts" />7957/// <reference path="../Helper/Utils.ts" />7958/// <reference path="../dts/scriptblocks.d.ts" />7959/// <reference path="../dts/scriptblocks.d.ts" />7960var Common;7961(function (Common) {7962 "use strict";7963 var BlocksReader = Compilation.BlocksReader;7964 var Compiler = Compilation.Compiler;7965 var BlockPacket = DataStructures.BlockPacket;7966 var State = Common.State;7967 var AgentController = Execution.AgentController;7968 var Observer = Execution.Observer;7969 var Collisions = Execution.Collisions;7970 var Constants = Helper.Constants;7971 var Logger = Helper.Logger;7972 var Utils = Helper.Utils;7973 class WebLogoApp {7974 constructor() {7975 BlocksReader.app = this;7976 AgentController.worldInstance = new Observer();7977 for (var breedID of AgentController.getBreedIDs()) {7978 var bins = new Array(Math.floor(2 * Constants.MAPSIZE / Collisions.binSize));7979 for (var i = 0; i < 2 * Constants.MAPSIZE; i++) {7980 bins[i] = new Array(Math.floor(2 * Constants.MAPSIZE / Collisions.binSize));7981 for (var j = 0; j < 2 * Constants.MAPSIZE; j++) {7982 bins[i][j] = [];7983 }7984 }7985 Collisions.bins.set(breedID, bins);7986 }7987 State.generatorSupported = Utils.isGeneratorSupported();7988 }7989 static parseID(id) {7990 for (var i = 5; i < id.length; i++) {7991 if (!isNaN(parseInt(id.substring(i), 10))) {7992 return parseInt(id.substring(i), 10);7993 }7994 }7995 if (id === "-1" || id === -1) {7996 return -1;7997 }7998 else {7999 throw new Error("Block ID could not be parsed");8000 }8001 }8002 static parseCommand(command) {8003 var currEl = "";8004 for (var i = 0; i < command.length; i++) {8005 if (command.charAt(i) === " " || command.charAt(i) === "\n") {8006 return currEl;8007 }8008 else {8009 currEl = currEl.concat(command.charAt(i));8010 }8011 }8012 return currEl;8013 }8014 getConnectedBlockInfo(beforeBlockIDStr, afterBlockIDStr, isArg) {8015 return;8016 }8017 getCreatedBlockInfo(blockName, blockID, blockLabel) {8018 return;8019 }8020 /*8021 This is called when something is entered into a text box, but not when a block is inserted in the8022 place of an argument.8023 */8024 getArgumentChangedBlockInfo(blockID, socket, newData) {8025 return;8026 }8027 appGetTopBlocks() {8028 var topBlocks = getTopBlocks();8029 var genuses = [];8030 var ids = [];8031 var labels = [];8032 for (var block of topBlocks) {8033 genuses.push(block[0]);8034 ids.push(block[1]);8035 labels.push(block[2]);8036 }8037 var cleanBlocks = [];8038 for (var genus of genuses) {8039 cleanBlocks.push(Common.WebLogoApp.parseCommand(genus));8040 }8041 var cleanIDs = [];8042 for (var id of ids) {8043 cleanIDs.push(Common.WebLogoApp.parseID(id));8044 }8045 var packets = [];8046 for (var i = 0; i < ids.length; i++) {8047 packets.push(new BlockPacket(cleanBlocks[i], cleanIDs[i], labels[i]));8048 }8049 return packets;8050 }8051 appGetNamedBlocks(name) {8052 var namedPackets = getNamedBlocks(name);8053 var returnPackets = new Array();8054 for (var packet of namedPackets) {8055 returnPackets.push(new BlockPacket(packet[0], Common.WebLogoApp.parseID(packet[1]), packet[2]));8056 }8057 return returnPackets;8058 }8059 appGetPages() {8060 var pageNames = getPages();8061 return pageNames;8062 }8063 appGetCurrentPage() {8064 return getCurrentPage();8065 }8066 appGetParent(blockID) {8067 var parentPacket = getParentBlock(blockID);8068 if (parentPacket === undefined) {8069 return undefined;8070 }8071 return new BlockPacket(parentPacket[0], Common.WebLogoApp.parseID(parentPacket[1]), parentPacket[2]);8072 }8073 appGetSBLength(blockID) {8074 return getSBLength(blockID);8075 }8076 appGetPageName(blockID) {8077 return getPageName(blockID);8078 }8079 appGetBlock(blockID) {8080 var thisPacket = getBlock(blockID);8081 /* tslint:disable no-null-keyword */8082 if (thisPacket === undefined || thisPacket === null) {8083 /* tslint:enable no-null-keyword */8084 return undefined;8085 }8086 return new BlockPacket(thisPacket[0], Common.WebLogoApp.parseID(thisPacket[1]), thisPacket[2]);8087 }8088 appGetBlockPage(blockID) {8089 // WebLogo.printToJSConsole("Getting block page in WebLogo");8090 return getPageName(blockID);8091 }8092 appGetBeforeBlock(blockID) {8093 var beforePacket = getBeforeBlock(blockID);8094 /* tslint:disable no-null-keyword */8095 if (beforePacket === undefined || beforePacket === null) {8096 /* tslint:enable no-null-keyword */8097 return undefined;8098 }8099 return new BlockPacket(beforePacket[0], Common.WebLogoApp.parseID(beforePacket[1]), beforePacket[2]);8100 }8101 appGetAfterBlock(blockID) {8102 var afterPacket = getAfterBlock(blockID);8103 /* tslint:disable no-null-keyword */8104 if (afterPacket === undefined || afterPacket === null) {8105 /* tslint:enable no-null-keyword */8106 return undefined;8107 }8108 return new BlockPacket(afterPacket[0], Common.WebLogoApp.parseID(afterPacket[1]), afterPacket[2]);8109 }8110 appGetInternalArg(blockID, socketIndex) {8111 var arg = getArg(blockID, socketIndex);8112 return arg;8113 }8114 appGetLabel(blockID, socket) {8115 var label = getBlockLabel(blockID, socket);8116 return label;8117 }8118 appGetSB(blockID, socket, socketIndex) {8119 var subPacket = getSB(blockID, socket, socketIndex);8120 /* tslint:disable no-null-keyword */8121 if (subPacket === undefined || subPacket === null) {8122 /* tslint:enable no-null-keyword */8123 return undefined;8124 }8125 var blocky = new BlockPacket(subPacket[0], Common.WebLogoApp.parseID(subPacket[1]), subPacket[2]);8126 return blocky;8127 }8128 dispatchToJS(args) {8129 if (!State.isTest) {8130 receiveDispatch(args);8131 }8132 }8133 getBreeds() {8134 return AgentController.getBreeds();8135 }8136 getDeletedBlockInfo(blockIDstr, name) {8137 return;8138 }8139 getDisconnectedBlockInfo(beforeBlockIDStr, afterBlockIDStr, isArg) {8140 return;8141 }8142 getWidgetsOfType(str) {8143 // Logger.log(`get widgets of type ${str}`);8144 var arr;8145 switch (str) {8146 case "WebLand.Widgets::ButtonWidget":8147 {8148 arr = WidgetManager.getWidgetsByType(slnova.PushButtonWidget);8149 }8150 break;8151 case "WebLand.Widgets::ToggleButtonWidget":8152 {8153 arr = WidgetManager.getWidgetsByType(slnova.ToggleButtonWidget);8154 }8155 break;8156 case "WebLand.Widgets::DataBoxWidget":8157 {8158 arr = WidgetManager.getWidgetsByType(slnova.DataBoxWidget);8159 }8160 break;8161 case "WebLand.Widgets::LineGraphWidget":8162 {8163 arr = WidgetManager.getWidgetsByType(slnova.ChartWidget);8164 }8165 break;8166 case "WebLand.Widgets::TableWidget":8167 {8168 arr = WidgetManager.getWidgetsByType(slnova.TableWidget);8169 }8170 break;8171 case "WebLand.Widgets::SliderWidget":8172 {8173 arr = WidgetManager.getWidgetsByType(slnova.SliderWidget);8174 }8175 break;8176 case "WebLand.Widgets::LabelWidget":8177 {8178 arr = WidgetManager.getWidgetsByType(slnova.LabelWidget);8179 }8180 break;8181 default:8182 {8183 return [];8184 }8185 ;8186 }8187 var ret = new Array();8188 for (var widget of arr) {8189 ret.push(widget.getName());8190 }8191 return ret;8192 }8193 labelChanged(blockID, name) {8194 return;8195 }8196 getSeriesOfGraph(graphName) {8197 return WidgetManager.getSeriesOfGraph(graphName);8198 }8199 getReadableTraits(breed) {8200 return AgentController.getReadableTraits(breed);8201 }8202 getChangeableTraits(breed) {8203 return AgentController.getChangeableTraits(breed);8204 }8205 getCustomTraits(breed) {8206 return AgentController.getCustomTraits(breed);8207 }8208 getWorldTraits() {8209 return AgentController.getCustomTraits(AgentController.WORLD.name);8210 }8211 addTrait(breedName, trait, dataType, dv) {8212 if (Constants.DEFAULT_TRAIT_NAMES.has(trait)) {8213 return true;8214 }8215 var success = AgentController.addTrait(breedName, trait, dataType, dv);8216 if (success) {8217 BlocksReader.dispatchEvent({8218 "category": "trait",8219 "event": "add",8220 "breed": breedName,8221 "name": trait,8222 "traitType": dataType,8223 "defaultValue": dv,8224 });8225 }8226 return success;8227 }8228 renameTrait(breedName, oldName, newName, dv) {8229 var success = AgentController.renameTrait(breedName, oldName, newName, dv);8230 if (success) {8231 this.dispatchToJS({8232 "category": "trait",8233 "event": "change",8234 "breed": breedName,8235 "oldName": oldName,8236 "newName": newName,8237 });8238 }8239 return success;8240 }8241 removeTrait(breedName, trait) {8242 var success = AgentController.removeTrait(breedName, trait);8243 if (success) {8244 this.dispatchToJS({8245 "category": "trait",8246 "event": "delete",8247 "breed": breedName,8248 "name": trait,8249 });8250 }8251 return success;8252 }8253 addBreed(breedName) {8254 var breedID = AgentController.addBreed(breedName);8255 if (breedID !== undefined) {8256 State.buttonMap[breedID] = new Array();8257 State.collisionDict.set(breedID, new Map());8258 State.collisionFunctions.set(breedID, new Map());8259 var size = Math.floor(2 * Constants.MAPSIZE / Collisions.binSize);8260 var bins = new Array(size);8261 for (var i = 0; i < size; i++) {8262 bins[i] = new Array(size);8263 for (var j = 0; j < size; j++) {8264 bins[i][j] = [];8265 }8266 }8267 Collisions.bins.set(breedID, bins);8268 this.dispatchToJS({8269 "category": "breed",8270 "event": "add",8271 "defaultShape": "box",8272 "name": breedName,8273 });8274 }8275 return (breedID !== undefined);8276 }8277 renameBreed(oldName, newName) {8278 var success = AgentController.renameBreed(oldName, newName);8279 if (success) {8280 this.dispatchToJS({8281 "category": "breed",8282 "event": "change",8283 "oldName": oldName,8284 "newName": newName,8285 "name": oldName,8286 });8287 }8288 return success;8289 }8290 removeBreed(breedName) {8291 var breedID = AgentController.removeBreed(breedName);8292 if (breedID !== undefined) {8293 delete (State.buttonMap[breedID]);8294 State.collisionDict.delete(breedID);8295 this.dispatchToJS({8296 "category": "breed",8297 "event": "delete",8298 "name": breedName,8299 });8300 }8301 return (breedID !== undefined);8302 }8303 compileAll() {8304 this.reset(false);8305 for (var bp of BlocksReader.getTopBlocks()) {8306 Compiler.createTopBlock(bp);8307 }8308 Compiler.compileAll();8309 }8310 reset(hard) {8311 AgentController.reset(hard);8312 State.reset(hard);8313 State.buttonMap[AgentController.WORLD.id] = [];8314 State.buttonMap[AgentController.EVERYONE.id] = [];8315 Logger.lastBlockPrint = "";8316 Logger.allPrinted = new Array();8317 for (var breedID of AgentController.getBreedIDs(true)) {8318 State.buttonMap[breedID] = [];8319 State.collisionDict.set(breedID, new Map());8320 State.collisionFunctions.set(breedID, new Map());8321 }8322 }8323 }8324 Common.WebLogoApp = WebLogoApp;8325})(Common || (Common = {}));8326/// <reference path="../../Helper/Constants.ts" />8327/// <reference path="../../DataStructures/AST.ts" />8328/// <reference path="../../Common/Agent.ts" />8329var Compilation;8330(function (Compilation) {8331 var Instructions;8332 (function (Instructions) {8333 "use strict";8334 var ASTNode = DataStructures.ASTNode;8335 var Constants = Helper.Constants;8336 /*8337 This class is used exclusively for testing8338 */8339 class Return extends ASTNode {8340 constructor() {8341 super(1, 0); // numArgs = 1, numBranches = 08342 }8343 fn(a, scope, args, rets) {8344 rets[0] = args[0];8345 rets[1] = Constants.AST_DONE;8346 }8347 to_js_no_yield() {8348 return `8349 return ${this.args.data[0].to_js_no_yield().trim()}8350 `;8351 }8352 to_js_setup() {8353 return `8354 ${this.args.data[0].to_js_setup()};8355 var __wl_${this.id}_ret = ${this.args.data[0].to_js_final().trim()};8356 `;8357 }8358 to_js_final() {8359 return `8360 return __wl_${this.id}_ret;8361 `;8362 }8363 }8364 Instructions.Return = Return;8365 })(Instructions = Compilation.Instructions || (Compilation.Instructions = {}));8366})(Compilation || (Compilation = {}));8367/// <reference path="../Execution/Engine.ts" />8368/// <reference path="../Common/App.ts" />...
runtime-core.cjs.js
Source:runtime-core.cjs.js
...976 if (disabled) {977 if (!wasDisabled) {978 // enabled -> disabled979 // move into main container980 moveTeleport(n2, container, mainAnchor, internals, 1 /* TOGGLE */);981 }982 }983 else {984 // target changed985 if ((n2.props && n2.props.to) !== (n1.props && n1.props.to)) {986 const nextTarget = (n2.target = resolveTarget(n2.props, querySelector));987 if (nextTarget) {988 moveTeleport(n2, nextTarget, null, internals, 0 /* TARGET_CHANGE */);989 }990 else {991 warn('Invalid Teleport target on update:', target, `(${typeof target})`);992 }993 }994 else if (wasDisabled) {995 // disabled -> enabled996 // move into teleport target997 moveTeleport(n2, target, targetAnchor, internals, 1 /* TOGGLE */);998 }999 }1000 }1001 },1002 remove(vnode, { r: remove, o: { remove: hostRemove } }) {1003 const { shapeFlag, children, anchor } = vnode;1004 hostRemove(anchor);1005 if (shapeFlag & 16 /* ARRAY_CHILDREN */) {1006 for (let i = 0; i < children.length; i++) {1007 remove(children[i]);1008 }1009 }1010 },1011 move: moveTeleport,1012 hydrate: hydrateTeleport1013};1014function moveTeleport(vnode, container, parentAnchor, { o: { insert }, m: move }, moveType = 2 /* REORDER */) {1015 // move target anchor if this is a target change.1016 if (moveType === 0 /* TARGET_CHANGE */) {1017 insert(vnode.targetAnchor, container, parentAnchor);1018 }1019 const { el, anchor, shapeFlag, children, props } = vnode;1020 const isReorder = moveType === 2 /* REORDER */;1021 // move main view anchor if this is a re-order.1022 if (isReorder) {1023 insert(el, container, parentAnchor);1024 }1025 // if this is a re-order and teleport is enabled (content is in target)1026 // do not move children. So the opposite is: only move children if this1027 // is not a reorder, or the teleport is disabled1028 if (!isReorder || isTeleportDisabled(props)) {
...
runtime-core.cjs.prod.js
Source:runtime-core.cjs.prod.js
...855 if (disabled) {856 if (!wasDisabled) {857 // enabled -> disabled858 // move into main container859 moveTeleport(n2, container, mainAnchor, internals, 1 /* TOGGLE */);860 }861 }862 else {863 // target changed864 if ((n2.props && n2.props.to) !== (n1.props && n1.props.to)) {865 const nextTarget = (n2.target = resolveTarget(n2.props, querySelector));866 if (nextTarget) {867 moveTeleport(n2, nextTarget, null, internals, 0 /* TARGET_CHANGE */);868 }869 }870 else if (wasDisabled) {871 // disabled -> enabled872 // move into teleport target873 moveTeleport(n2, target, targetAnchor, internals, 1 /* TOGGLE */);874 }875 }876 }877 },878 remove(vnode, { r: remove, o: { remove: hostRemove } }) {879 const { shapeFlag, children, anchor } = vnode;880 hostRemove(anchor);881 if (shapeFlag & 16 /* ARRAY_CHILDREN */) {882 for (let i = 0; i < children.length; i++) {883 remove(children[i]);884 }885 }886 },887 move: moveTeleport,888 hydrate: hydrateTeleport889};890function moveTeleport(vnode, container, parentAnchor, { o: { insert }, m: move }, moveType = 2 /* REORDER */) {891 // move target anchor if this is a target change.892 if (moveType === 0 /* TARGET_CHANGE */) {893 insert(vnode.targetAnchor, container, parentAnchor);894 }895 const { el, anchor, shapeFlag, children, props } = vnode;896 const isReorder = moveType === 2 /* REORDER */;897 // move main view anchor if this is a re-order.898 if (isReorder) {899 insert(el, container, parentAnchor);900 }901 // if this is a re-order and teleport is enabled (content is in target)902 // do not move children. So the opposite is: only move children if this903 // is not a reorder, or the teleport is disabled904 if (!isReorder || isTeleportDisabled(props)) {
...
TeleportUI.js
Source:TeleportUI.js
...38 MyModule.setWorld(60, 0, 170);39 MyModule.openWatchButton();40 MyModule.moveWatchButton(-Math.PI / 1.37, 0);41 MyModule.moveDescription(-Math.PI / 2.1, 0,);42 MyModule.moveTeleport(-Math.PI / 8, 0);43 break;44 case 1:45 MyModule.setWorld(70, 0, 250);46 MyModule.moveWatchButton(-Math.PI / 1.65, -Math.PI / 8);47 MyModule.moveDescription(-Math.PI / 2.7, 0,);48 MyModule.moveTeleport(Math.PI / 2.2, 0);49 break;50 case 2:51 MyModule.setWorld(-40, 0, 240);52 MyModule.moveWatchButton(Math.PI / 8, -Math.PI / 9);53 MyModule.moveDescription(Math.PI / 2.5, 0,);54 MyModule.moveTeleport(-Math.PI / 8, 0);55 break;56 case 3:57 MyModule.setWorld(55, 0, 430);58 MyModule.moveWatchButton(Math.PI / 1.15, -Math.PI / 6);59 MyModule.moveDescription(Math.PI / 1.7, 0,);60 MyModule.moveTeleport(Math.PI / 2, 0);61 break;62 case 4:63 MyModule.setWorld(-55, 0, 390);64 MyModule.moveWatchButton(-Math.PI / 10, -Math.PI / 10);65 MyModule.moveDescription(Math.PI / 8, 0,);66 MyModule.moveTeleport(0, 0);67 break;68 //first floor69 case 5:70 MyModule.setWorld(-55, 15, 520);71 MyModule.moveWatchButton(Math.PI / 8, -Math.PI / 8);72 MyModule.moveDescription(-Math.PI / 6, 0,);73 MyModule.moveTeleport(-Math.PI / 4, -Math.PI / 8);74 break;75 case 6:76 MyModule.setWorld(-45, 25, 530);77 MyModule.moveWatchButton(-Math.PI / 3, -Math.PI / 3.5);78 MyModule.moveDescription(-Math.PI / 12, 0,);79 MyModule.moveTeleport(-Math.PI / 1.5, Math.PI / 8);80 break;81 case 7:82 MyModule.setWorld(-35, 10, 520);83 MyModule.moveWatchButton(-Math.PI / 1.55, Math.PI / 8);84 MyModule.moveDescription(-Math.PI / 3, 0,);85 MyModule.moveTeleport(-Math.PI / 2, 0);86 break;87 case 8:88 MyModule.setWorld(20, 5, 510);89 MyModule.moveWatchButton(-Math.PI / 16, -Math.PI / 4);90 MyModule.moveDescription(Math.PI / 5, 0,);91 MyModule.moveTeleport(-Math.PI / 5.5, -Math.PI / 6);92 break;93 case 9:94 MyModule.setWorld(50, 35, 560);95 MyModule.moveWatchButton(-Math.PI / 2.8, -Math.PI / 4);96 MyModule.moveDescription(-Math.PI / 7, 0,);97 MyModule.moveTeleport(-Math.PI / 2, 0);98 break;99 case 10:100 MyModule.setWorld(90, 35, 560);101 MyModule.moveWatchButton(-Math.PI / 1.75, -Math.PI / 7);102 MyModule.moveDescription(-Math.PI / 3, 0,);103 MyModule.moveTeleport(-Math.PI / 1.2, Math.PI / 12);104 break;105 case 11:106 MyModule.setWorld(120, 25, 540);107 MyModule.moveWatchButton(Math.PI / 1.48, -Math.PI / 29);108 MyModule.moveDescription(Math.PI / 2.2, 0,);109 MyModule.moveTeleport(-Math.PI / 3.5, Math.PI / 5);110 break;111 //second floor - first room112 case 12:113 MyModule.setWorld(180, -60, 570);114 MyModule.moveWatchButton(-Math.PI / 1.3, -Math.PI / 22);115 MyModule.moveDescription(-Math.PI / 1.8, 0,);116 MyModule.moveTeleport(-Math.PI / 2.3, -Math.PI / 12);117 break;118 case 13:119 MyModule.setWorld(250, -50, 587);120 MyModule.moveWatchButton(-Math.PI / 1.8, -Math.PI / 8);121 MyModule.moveDescription(-Math.PI / 3.5, 0,);122 MyModule.moveTeleport(Math.PI / 2.5, -Math.PI / 8);123 break;124 case 14:125 MyModule.setWorld(200, -45, 600);126 MyModule.moveWatchButton(Math.PI / 18, -Math.PI / 4.5);127 MyModule.moveDescription(Math.PI / 4, 0,);128 MyModule.moveTeleport(Math.PI / 1.1, 0);129 break;130 case 15:131 MyModule.setWorld(200, -55, 580);132 MyModule.moveWatchButton(Math.PI / 3, -Math.PI / 3.5);133 MyModule.moveDescription(0, 0,);134 MyModule.moveTeleport(Math.PI / 1.7, 0);135 break;136 //outside137 case 16:138 MyModule.setWorld(140, -55, 570);139 MyModule.moveWatchButton(Math.PI / 4, -Math.PI / 4.5);140 MyModule.moveDescription(0, 0,);141 MyModule.moveTeleport(Math.PI / 2.2, -Math.PI / 25);142 break;143 //second floor - second room144 case 17:145 MyModule.setWorld(-30, -58, 590);146 MyModule.moveWatchButton(Math.PI / 1.05, Math.PI / 6);147 MyModule.moveDescription(-Math.PI / 1.2, 0,);148 MyModule.moveTeleport(Math.PI / 1.2, 0);149 break;150 case 18:151 MyModule.setWorld(-45, -70, 570);152 MyModule.moveWatchButton(Math.PI / 1.15, Math.PI / 12);153 MyModule.moveDescription(-Math.PI / 1.2, 0,);154 MyModule.moveTeleport(Math.PI / 1.9, -Math.PI / 8);155 break;156 case 19:157 MyModule.setWorld(-75, -70, 565);158 MyModule.moveWatchButton(Math.PI / 30, -Math.PI / 3.5);159 MyModule.moveDescription(Math.PI / 4, 0,);160 MyModule.moveTeleport(Math.PI / 2.5, -Math.PI / 8);161 break;162 case 20:163 MyModule.setWorld(-115, -60, 590);164 MyModule.moveWatchButton(-Math.PI / 1.75, -Math.PI / 5.5);165 MyModule.moveDescription(-Math.PI / 3, 0,);166 MyModule.moveTeleport(-Math.PI / 2, -Math.PI / 20);167 break;168 //outside169 case 21:170 MyModule.setWorld(10, -65, 570);171 MyModule.moveWatchButton(-Math.PI / 1.25, -Math.PI / 10);172 MyModule.moveDescription(-Math.PI / 1.8, 0,);173 MyModule.moveTeleport(-Math.PI / 2.5, 0);174 break;175 case 22:176 MyModule.setWorld(180, -100, 630);177 MyModule.moveWatchButton(-Math.PI / 2.5, -Math.PI / 3.5);178 MyModule.moveDescription(-Math.PI / 1.6, 0,);179 MyModule.moveTeleport(-Math.PI / 1.3, Math.PI / 20);180 break;181 case 23:182 MyModule.setWorld(200, -115, 590);183 MyModule.moveWatchButton(-Math.PI / 1.9, -Math.PI / 5.5);184 MyModule.moveDescription(-Math.PI / 1.2, 0,);185 MyModule.moveTeleport(-Math.PI / 3, -Math.PI / 7);186 break;187 case 24:188 MyModule.setWorld(220, -105, 619);189 MyModule.moveWatchButton(-Math.PI / 1.9, -Math.PI / 10);190 MyModule.moveDescription(-Math.PI / 1.35, 0,);191 MyModule.moveTeleport(Math.PI / 1.2, Math.PI / 8);192 break;193 //the end194 case 25:195 MyModule.closeWatchButton();196 MyModule.closeTeleport();197 MyModule.setWorld(-10, -180, 300);198 MyModule.moveDescription(-Math.PI / 1.35, 0,);199 MyModule.moveTeleport(Math.PI / 1.2, Math.PI / 8);200 MyModule.openEndscreen();201 break;202 }203 setStation(this.state.station + 1);204 this.setState({205 gazed: false,206 station: this.state.station + 1,207 });208 AudioModule.playOneShot({209 source: asset('swim.mp3'),210 });211 //this.setState({gazed: true,});212 };213 componentWillUnmount() {...
client.js
Source:client.js
...12 setWorld(x, y, z) {13 myLocation.setWorldPosition(x, y, z);14 }15 ////////TELEPORT UI/////////16 moveTeleport(yaw, pitch) {17 teleportSurface.setAngle(18 yaw,19 pitch,20 );21 }22 closeTeleport() {23 teleportSurface.resize(0, 0);24 }25 openTeleport() {26 teleportSurface.resize(200, 200);27 }28 ////////WATCH UI/////////29 moveWatchButton(yaw, pitch) {30 watchButtonSurface.setAngle(...
teleport.js
Source:teleport.js
...98 if (disabled) {99 if (!wasDisabled) {100 // enabled -> disabled101 // æåèç¹ç§»å¨å主容å¨102 moveTeleport(n2, container, mainAnchor, internals, 1 /* TOGGLE */)103 }104 }105 else {106 if ((n2.props && n2.props.to) !== (n1.props && n1.props.to)) {107 // ç®æ å
ç´ æ¹å108 const nextTarget = (n2.target = resolveTarget(n2.props, querySelector))109 if (nextTarget) {110 // 移å¨å°æ°çç®æ å
ç´ 111 moveTeleport(n2, nextTarget, null, internals, 0 /* TARGET_CHANGE */)112 }113 else if ((process.env.NODE_ENV !== 'production')) {114 warn('Invalid Teleport target on update:', target, `(${typeof target})`)115 }116 }117 else if (wasDisabled) {118 // disabled -> enabled119 // 移å¨å°ç®æ å
ç´ ä½ç½®120 moveTeleport(n2, target, targetAnchor, internals, 1 /* TOGGLE */)121 }122 }123 }124}125function remove(vnode, { r: remove, o: { remove: hostRemove } }) {126 const { shapeFlag, children, anchor } = vnode127 hostRemove(anchor)128 if (shapeFlag & 16 /* ARRAY_CHILDREN */) {129 for (let i = 0; i < children.length; i++) {130 remove(children[i])131 }132 }...
seven.js
Source:seven.js
...81 }82};83const teleport = () => {84 console.log("teleport");85 moveTeleport();86 sleep(2300);87 robot.keyTap("q");88 sleep(300);89 robot.keyToggle("q", "down");90 sleep(3800);91 robot.keyToggle("q", "up");92 sleep(300);93 robot.keyToggle("s", "down");94 sleep(2000);95 robot.keyToggle("s", "up");96 n = 0;97 hunt();98};99const attack = () => {...
upEvSpeed.js
Source:upEvSpeed.js
...61 sleep(300);62};63const teleport = () => {64 console.log("teleport");65 moveTeleport();66 sleep(2300);67 robot.keyTap("q");68 sleep(300);69 robot.keyToggle("q", "down");70 sleep(3800);71 robot.keyToggle("q", "up");72 sleep(300);73 robot.keyToggle("s", "down");74 sleep(2000);75 robot.keyToggle("s", "up");76 n = 0;77 hunt();78};79const attack = () => {...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.mouse.move(100, 100);7 await page.mouse.down();8 await page.mouse.move(300, 300, { steps: 10 });9 await page.mouse.up();10 await page.mouse.moveTeleport(100, 100);11 await page.mouse.down();12 await page.mouse.moveTeleport(300, 300, { steps: 10 });13 await page.mouse.up();14 await browser.close();15})();16#### mouse.down([options])17#### mouse.up([options])18#### mouse.move(x, y, [options])19#### mouse.moveTeleport(x, y, [options])20#### mouse.click(x, y, [options])
Using AI Code Generation
1const { moveTeleport } = require('@playwright/test/lib/server/transport');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const dimensions = await page.evaluate(() => {8 return {9 };10 });11 await moveTeleport(page, { x: 0, y: 0 });12 await moveTeleport(page, { x: dimensions.width, y: dimensions.height });13 await moveTeleport(page, {14 });15 await moveTeleport(page, { x: 0, y: 0 });16 await browser.close();17})();18[Apache 2.0](LICENSE)
Using AI Code Generation
1const { moveTeleport } = require('playwright-internal');2await moveTeleport(page, 100, 100);3const { moveMouse } = require('playwright-internal');4await moveMouse(page, 100, 100);5const { down } = require('playwright-internal');6await down(page, 'left');7const { up } = require('playwright-internal');8await up(page, 'left');9const { click } = require('playwright-internal');10await click(page, 100, 100);11const { doubleClick } = require('playwright-internal');12await doubleClick(page, 100, 100);13const { tap } = require('playwright-internal');14await tap(page, 100, 100);15const { doubleTap } = require('playwright-internal');16await doubleTap(page, 100, 100);17const { press } = require('playwright-internal');18await press(page, 'ArrowLeft');19const { type } = require('playwright-internal');20await type(page, 'Hello World');21const { insertText } = require('playwright
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!