Mindustry/core/assets/scripts/base.js

41 lines
1.5 KiB
JavaScript
Raw Normal View History

"use strict";
2021-01-20 03:13:41 +07:00
let scriptName = "base.js"
let modName = "none"
2019-12-04 05:16:23 +07:00
2021-01-20 03:13:41 +07:00
const log = (context, obj) => Vars.mods.scripts.log(context, String(obj))
const print = text => log(modName + "/" + scriptName, text)
2020-11-10 15:02:39 +07:00
2021-01-20 03:13:41 +07:00
const newFloats = cap => Vars.mods.getScripts().newFloats(cap);
2020-07-28 07:18:07 +07:00
2021-01-20 03:13:41 +07:00
//these are not strictly necessary, but are kept for edge cases
const run = method => new java.lang.Runnable(){run: method}
const boolf = method => new Boolf(){get: method}
const boolp = method => new Boolp(){get: method}
const floatf = method => new Floatf(){get: method}
const floatp = method => new Floatp(){get: method}
const cons = method => new Cons(){get: method}
const prov = method => new Prov(){get: method}
const func = method => new Func(){get: method}
2020-02-12 05:50:16 +07:00
2021-01-20 03:13:41 +07:00
const newEffect = (lifetime, renderer) => new Effect.Effect(lifetime, new Effect.EffectRenderer({render: renderer}))
Call = Packages.mindustry.gen.Call
2020-02-12 05:50:16 +07:00
2020-11-22 03:50:44 +07:00
//js 'extend(Base, ..., {})' = java 'new Base(...) {}'
function extend(/*Base, ..., def*/){
const Base = arguments[0]
const def = arguments[arguments.length - 1]
//swap order from Base, def, ... to Base, ..., def
const args = [Base, def].concat(Array.from(arguments).splice(1, arguments.length - 2))
//forward constructor arguments to new JavaAdapter
const instance = JavaAdapter.apply(null, args)
//JavaAdapter only overrides functions; set fields too
for(var i in def){
if(typeof(def[i]) != "function"){
instance[i] = def[i]
}
}
2020-11-22 03:50:44 +07:00
return instance
}