Some checks failed
Build and Deploy / build-linux (push) Failing after 1m45s
Build and Deploy / build-windows (CLANG64) (push) Failing after 8m5s
Build and Deploy / package-dist (push) Has been skipped
Build and Deploy / deploy-itch (push) Has been skipped
Build and Deploy / deploy-gitea (push) Has been skipped
216 lines
4.9 KiB
JavaScript
216 lines
4.9 KiB
JavaScript
var io = use('io')
|
|
var util = use('util')
|
|
|
|
var dumpfolder = ".prosperon";
|
|
|
|
io.mkdir(dumpfolder)
|
|
|
|
var Cmdline = {};
|
|
|
|
Cmdline.cmds = [];
|
|
Cmdline.orders = {};
|
|
Cmdline.register_cmd = function (flag, fn, doc) {
|
|
Cmdline.cmds.push({
|
|
flag: flag,
|
|
fn: fn,
|
|
doc: doc,
|
|
});
|
|
};
|
|
|
|
Cmdline.register_order = function (order, fn, doc, usage = "") {
|
|
Cmdline.orders[order] = fn;
|
|
fn.doc = doc;
|
|
fn.usage = `${order} ${usage}`;
|
|
};
|
|
|
|
Cmdline.register_order(
|
|
"makedoc",
|
|
function() {
|
|
var doc = use('doc')
|
|
|
|
var gs = ['console', 'prosperon', 'actor', 'use']
|
|
|
|
for (var g of gs)
|
|
io.slurpwrite(`.src/docs/api/${g}.md`, doc.writeDocFile(globalThis[g], g))
|
|
|
|
var coredocs = io.enumerate("scripts/modules", 0)
|
|
coredocs = coredocs.filter(x => io.match("**/*.js", x)).map(x => x.name())
|
|
|
|
var APIPATH = '.src/docs/api/modules/'
|
|
|
|
for (var m of coredocs) {
|
|
var u = use(m)
|
|
var path = `${APIPATH}${m}.md`
|
|
io.slurpwrite(path, doc.writeDocFile(u, m))
|
|
}
|
|
|
|
var TYPEPATH = '.src/docs/api/types/'
|
|
for (var c in prosperon.c_types)
|
|
io.slurpwrite(`${TYPEPATH}${c}.md`, doc.writeDocFile(prosperon.c_types[c], c))
|
|
|
|
var DULLPATH = '.src/docs/dull/'
|
|
var mixins = ['Object', 'String', 'Array', 'Map', 'WeakMap', 'Symbol','Set', 'WeakSet', 'ArrayBuffer', 'Function']
|
|
for (var m of mixins) {
|
|
var path = `${DULLPATH}${m}.md`
|
|
io.slurpwrite(path, doc.writeDocFile(globalThis[m].prototype, m))
|
|
}
|
|
|
|
var dullgpath = '.src/docs/dull/globals/'
|
|
var globals = ['Object', 'String', 'Array', 'Symbol', 'Number', 'Error','Function', 'Math']
|
|
for (var m of globals) {
|
|
var path = `${dullgpath}${m}.md`
|
|
io.slurpwrite(path, doc.writeDocFile(globalThis[m], m))
|
|
}
|
|
"Make documentation."
|
|
})
|
|
|
|
Cmdline.register_order(
|
|
"play",
|
|
function (argv) {
|
|
var app
|
|
if (io.exists("main.js"))
|
|
app = actor.spawn("main.js")
|
|
else
|
|
app = actor.spawn("nogame.js")
|
|
|
|
// rm actor so it can't be tampered
|
|
globalThis.actor = undefined
|
|
|
|
var loop = use('loop')
|
|
while(1) loop.step();
|
|
},
|
|
"Play the game present in this folder.",
|
|
);
|
|
|
|
Cmdline.register_order(
|
|
"about",
|
|
function (argv) {
|
|
if (!argv[0]) {
|
|
console.print("About your game");
|
|
console.print(`Prosperon version ${prosperon.version}`);
|
|
console.print(`Total entities ${ur._list.length}`);
|
|
}
|
|
switch (argv[0]) {
|
|
case "entities":
|
|
for (var i of ur._list) console.print(i);
|
|
break;
|
|
}
|
|
},
|
|
"Get information about this game.",
|
|
);
|
|
|
|
Cmdline.register_order(
|
|
"api",
|
|
function (obj) {
|
|
var doc = use('doc')
|
|
doc.write_modules()
|
|
doc.write_c_types()
|
|
},
|
|
"Print the API for an object as markdown. Give it a file to save the output to.",
|
|
"OBJECT",
|
|
);
|
|
|
|
Cmdline.register_order(
|
|
"input",
|
|
function (pawn) {
|
|
use("editor.js");
|
|
console.print(`## Input for ${pawn}`);
|
|
eval(`console.print(input.print_md_kbm(${pawn}));`);
|
|
},
|
|
"Print input documentation for a given object as markdown. Give it a file to save the output to",
|
|
"OBJECT ?FILE?",
|
|
);
|
|
|
|
Cmdline.print_order = function (fn) {
|
|
if (typeof fn === "string") fn = Cmdline.orders[fn];
|
|
|
|
if (!fn) return;
|
|
console.print(`Usage: prosperon ${fn.usage}` + "\n");
|
|
console.print(fn.doc + "\n");
|
|
};
|
|
|
|
function parse_args(argv)
|
|
{
|
|
var args = {};
|
|
for (var i = 0; i < argv.length; i++) {
|
|
if (argv[i].startsWith("--")) {
|
|
var key = argv[i].slice(2);
|
|
if (i + 1 < argv.length && !argv[i + 1].startsWith("--")) {
|
|
args[key] = argv[i + 1];
|
|
i++; // Skip the value
|
|
} else {
|
|
args[key] = true; // Flag without value
|
|
}
|
|
}
|
|
}
|
|
return args;
|
|
}
|
|
|
|
Cmdline.register_order(
|
|
"spawn",
|
|
function(argv) {
|
|
prosperon.args = parse_args(argv)
|
|
if (!prosperon.args.program)
|
|
os.exit()
|
|
|
|
prosperon.guid = prosperon.args.guid
|
|
prosperon.overling = prosperon.args.overling
|
|
prosperon.program = prosperon.args.program
|
|
prosperon.parentpub = prosperon.args.parentpub
|
|
},
|
|
"Spawn a new prosperon actor.",
|
|
"TOPIC"
|
|
);
|
|
|
|
Cmdline.register_order(
|
|
"help",
|
|
function (order) {
|
|
if (!util.isEmpty(order)) {
|
|
var orfn = Cmdline.orders[order];
|
|
|
|
if (!orfn) {
|
|
console.warn(`No command named ${order}.`);
|
|
return;
|
|
}
|
|
|
|
Cmdline.print_order(orfn);
|
|
return;
|
|
}
|
|
|
|
Cmdline.print_order("help");
|
|
|
|
for (var cmd of Object.keys(Cmdline.orders).sort()) console.print(cmd + "\n");
|
|
|
|
Cmdline.orders.version();
|
|
},
|
|
"Give help with a specific command.",
|
|
"TOPIC",
|
|
);
|
|
|
|
Cmdline.register_order(
|
|
"version",
|
|
function () {
|
|
console.print(`Prosperon version ${prosperon.version} [${prosperon.revision}]` + "\n");
|
|
},
|
|
"Display Prosperon info.",
|
|
);
|
|
|
|
function cmd_args(cmds) {
|
|
cmds.shift()
|
|
if (cmds.length === 0) {
|
|
cmds[0] = "spawn";
|
|
cmds[1] = "--program"
|
|
cmds[2] = "main.js"
|
|
}
|
|
else if (!Cmdline.orders[cmds[0]]) {
|
|
// assume it's a script
|
|
cmds[2] = cmds[0]
|
|
cmds[1] = "--program"
|
|
cmds[0] = "spawn"
|
|
}
|
|
|
|
Cmdline.orders[cmds[0]](cmds.slice(1));
|
|
}
|
|
|
|
return cmd_args;
|