-
-
Save LaylBongers/38173c293014305b28e6614e7a3caaea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Scoping issue with emscripten in node modules, included until fix is in stable. | |
// Fixed in: https://github.com/kripken/emscripten/commit/fe5ad199c5ab4d6f3615a24d6868190352455da6 | |
global.simdPhase2 = true; | |
let rust = require('screeps-layl'); | |
// Provide the global link between screeps and Rust | |
if (typeof __globals !== 'undefined') { | |
// We're in sim | |
global.screepsEmbindLink = __globals; | |
} else { | |
// We're in server | |
global.screepsEmbindLink = global; | |
} | |
// Let rust load its cached data | |
let data = rust.Module._load(); | |
// Bootstrap the actual rust tick function | |
module.exports.loop = function () { | |
// Clean up all creeps that don't exist anymore | |
for (let name in Memory.creeps) { | |
if (Game.creeps[name] == undefined) { | |
console.log("Creep " + name + " died"); | |
delete Memory.creeps[name]; | |
} | |
} | |
// Run the actual rust code | |
rust.Module._tick(data); | |
} | |
// Add the command function | |
global.cc = function(command, params) { | |
// Validate parameters commands | |
if (!_.isString(command)) { | |
return "The first argument of \"cc\" has to be a string!"; | |
} | |
if (!params) { | |
params = []; | |
} else if (!_.isArray(params)) { | |
return "The second argument of \"cc\" has to be an array or undefined/null!"; | |
} | |
Memory.corrosion.commands.push({ | |
command: command, | |
params: params, | |
}); | |
return "Command queued!"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment