2024-02-25 17:31:48 -06:00
|
|
|
os.cwd.doc = "Get the absolute path of the current working directory.";
|
|
|
|
os.env.doc = "Return the value of the environment variable v.";
|
2024-03-02 23:34:41 -06:00
|
|
|
os.platform = "steam";
|
2024-03-12 09:01:52 -05:00
|
|
|
if (os.sys() === 'windows')
|
2024-03-02 23:34:41 -06:00
|
|
|
os.user = os.env("USERNAME");
|
|
|
|
else
|
|
|
|
os.user = os.env("USER");
|
2024-03-12 09:01:52 -05:00
|
|
|
|
|
|
|
var appy = {};
|
|
|
|
appy.inputs = {};
|
|
|
|
if (os.sys() === 'macos') {
|
2024-03-18 08:16:25 -05:00
|
|
|
appy.inputs['S-q'] = os.quit;
|
2024-03-12 09:01:52 -05:00
|
|
|
appy.inputs['S-h'] = function() { };
|
2024-04-02 07:41:46 -05:00
|
|
|
appy.inputs['S-g'] = os.gc;
|
2024-03-12 09:01:52 -05:00
|
|
|
}
|
2024-03-02 23:34:41 -06:00
|
|
|
|
2024-03-12 09:01:52 -05:00
|
|
|
player[0].control(appy);
|
|
|
|
|
2024-04-15 15:03:23 -05:00
|
|
|
//steam.appid = 480;
|
|
|
|
//steam.userid = 8437843;
|
2024-03-02 23:34:41 -06:00
|
|
|
|
|
|
|
os.home = os.env("HOME");
|
|
|
|
|
2024-04-15 15:03:23 -05:00
|
|
|
/*steam.path = {
|
2024-03-02 23:34:41 -06:00
|
|
|
windows: `C:/Program Files (x86)/Steam/userdata/${steam.userid}/${steam.appid}`,
|
|
|
|
macos: `${os.home}/Library/Application Support/Steam/userdata/${steam.userid}/${steam.appid}`,
|
|
|
|
linux: `${os.home}/.local/share/Steam/userdata/${steam.userid}/${steam.appid}`
|
|
|
|
};
|
2024-04-15 15:03:23 -05:00
|
|
|
*/
|
2024-03-02 23:34:41 -06:00
|
|
|
var otherpath = {
|
|
|
|
windows:`C:/Users/${os.user}/Saved Games`,
|
|
|
|
macos: `${os.home}/Library/Application Support`,
|
|
|
|
linux: `${os.home}/.local/share`
|
|
|
|
}
|
|
|
|
|
|
|
|
os.prefpath = function() {
|
2024-03-18 08:16:25 -05:00
|
|
|
return otherpath[os.sys()] + "/" + (game.title ? game.title : "Untitled Prosperon Game");
|
2024-03-02 23:34:41 -06:00
|
|
|
}
|
2023-10-09 18:10:10 -05:00
|
|
|
|
2024-03-24 12:44:35 -05:00
|
|
|
os.openurl = function(url) {
|
|
|
|
if (os.sys() === 'windows')
|
|
|
|
os.system(`start ${url}`);
|
|
|
|
else
|
|
|
|
os.system(`open ${url}`);
|
|
|
|
}
|
|
|
|
|
2024-04-18 17:34:56 -05:00
|
|
|
var projectfile = "project.prosperon";
|
2024-04-20 12:55:20 -05:00
|
|
|
io.dumpfolder = '.prosperon';
|
2024-03-02 00:00:35 -06:00
|
|
|
|
2023-12-20 09:19:04 -06:00
|
|
|
Resources.is_sound = function(path) {
|
|
|
|
var ext = path.ext();
|
|
|
|
return Resources.sounds.any(x => x === ext);
|
|
|
|
}
|
|
|
|
|
2023-12-27 17:28:10 -06:00
|
|
|
Resources.is_animation = function(path)
|
|
|
|
{
|
|
|
|
if (path.ext() === 'gif' && Resources.gif.frames(path) > 1) return true;
|
2024-01-01 14:48:58 -06:00
|
|
|
if (path.ext() === 'ase') return true;
|
|
|
|
|
|
|
|
return false;
|
2023-12-27 17:28:10 -06:00
|
|
|
}
|
|
|
|
|
2024-03-02 23:34:41 -06:00
|
|
|
Resources.is_path = function(str)
|
|
|
|
{
|
|
|
|
return !/[\\\/:*?"<>|]/.test(str);
|
|
|
|
}
|
|
|
|
|
2023-12-27 17:28:10 -06:00
|
|
|
Resources.texture = {};
|
2024-03-18 14:27:52 -05:00
|
|
|
Resources.texture.dimensions = function(path) { texture.dimensions(path); }
|
2023-12-27 17:28:10 -06:00
|
|
|
|
|
|
|
Resources.gif = {};
|
2024-03-19 14:39:19 -05:00
|
|
|
Resources.gif.frames = function(path) { return render.gif_frames(path); }
|
2023-12-27 17:28:10 -06:00
|
|
|
|
2023-11-17 15:16:13 -06:00
|
|
|
/*
|
2024-02-25 17:31:48 -06:00
|
|
|
io path rules. Starts with, meaning:
|
2024-02-27 10:09:15 -06:00
|
|
|
"@": user path
|
2024-03-02 23:34:41 -06:00
|
|
|
"/": root game path
|
|
|
|
"" : relative game path
|
2023-11-17 15:16:13 -06:00
|
|
|
*/
|
2024-03-02 00:00:35 -06:00
|
|
|
|
2024-03-02 23:34:41 -06:00
|
|
|
var tmpchm = io.chmod;
|
2024-03-02 00:00:35 -06:00
|
|
|
io.chmod = function(file,mode) {
|
2024-03-02 23:34:41 -06:00
|
|
|
return tmpchm(file,parseInt(mode,8));
|
2024-03-02 00:00:35 -06:00
|
|
|
}
|
2024-03-02 23:34:41 -06:00
|
|
|
|
|
|
|
var tmpslurp = io.slurp;
|
|
|
|
io.slurp = function(path)
|
|
|
|
{
|
|
|
|
path = Resources.replpath(path);
|
|
|
|
return tmpslurp(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
var tmpslurpb = io.slurpbytes;
|
|
|
|
io.slurpbytes = function(path)
|
|
|
|
{
|
|
|
|
path = Resources.replpath(path);
|
|
|
|
return tmpslurpb(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
io.mkpath = function(dir)
|
|
|
|
{
|
2024-03-04 11:15:55 -06:00
|
|
|
if (!dir) return;
|
2024-03-02 23:34:41 -06:00
|
|
|
var mkstack = [];
|
|
|
|
while (!io.exists(dir)) {
|
|
|
|
mkstack.push(dir.fromlast('/'));
|
|
|
|
dir = dir.dir();
|
|
|
|
}
|
|
|
|
for (var d of mkstack) {
|
|
|
|
dir = dir + "/" + d;
|
|
|
|
say(`making ${dir}`);
|
|
|
|
io.mkdir(dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var tmpslurpw = io.slurpwrite;
|
|
|
|
io.slurpwrite = function(path, c)
|
|
|
|
{
|
|
|
|
path = Resources.replpath(path);
|
|
|
|
io.mkpath(path.dir());
|
|
|
|
return tmpslurpw(path, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
var tmpcp = io.cp;
|
|
|
|
io.cp = function(f1,f2)
|
|
|
|
{
|
|
|
|
io.mkpath(f2.dir());
|
|
|
|
tmpcp(f1,f2);
|
|
|
|
}
|
|
|
|
|
|
|
|
var tmprm = io.rm;
|
|
|
|
io.rm = function(f)
|
|
|
|
{
|
|
|
|
tmprm(Resources.replpath(f));
|
|
|
|
}
|
|
|
|
|
2024-02-27 10:09:15 -06:00
|
|
|
io.mixin({
|
2023-09-13 01:08:32 -05:00
|
|
|
extensions(ext) {
|
2024-02-25 17:31:48 -06:00
|
|
|
var paths = io.ls();
|
2023-09-13 01:08:32 -05:00
|
|
|
paths = paths.filter(function(str) { return str.ext() === ext; });
|
|
|
|
return paths;
|
|
|
|
},
|
2024-02-27 10:09:15 -06:00
|
|
|
|
2023-09-13 01:08:32 -05:00
|
|
|
glob(pat) {
|
2024-03-04 11:15:55 -06:00
|
|
|
var paths = io.ls('.');
|
2023-09-13 01:08:32 -05:00
|
|
|
pat = pat.replaceAll(/([\[\]\(\)\^\$\.\|\+])/g, "\\$1");
|
|
|
|
pat = pat.replaceAll('**', '.*');
|
|
|
|
pat = pat.replaceAll(/[^\.]\*/g, '[^\\/]*');
|
|
|
|
pat = pat.replaceAll('?', '.');
|
|
|
|
|
|
|
|
var regex = new RegExp("^"+pat+"$", "");
|
2024-03-04 11:15:55 -06:00
|
|
|
paths = paths.filter(str => str.match(regex)).sort();
|
|
|
|
return paths;
|
2023-09-13 01:08:32 -05:00
|
|
|
},
|
2024-02-27 10:09:15 -06:00
|
|
|
});
|
2023-09-07 16:46:35 -05:00
|
|
|
|
2024-02-25 17:31:48 -06:00
|
|
|
io.doc = {
|
2023-10-23 08:08:11 -05:00
|
|
|
doc: "Functions for filesystem input/output commands.",
|
|
|
|
exists: "Returns true if a file exists.",
|
|
|
|
slurp: "Returns the contents of given file as a string.",
|
2024-02-23 16:05:30 -06:00
|
|
|
slurpbytes: "Return the contents of a file as a byte array.",
|
2023-10-23 08:08:11 -05:00
|
|
|
slurpwrite: "Write a given string to a given file.",
|
2024-02-23 16:05:30 -06:00
|
|
|
cp: "Copy file f1 to f2.",
|
|
|
|
mv: "Rename file f1 to f2.",
|
|
|
|
rm: "Remove file f.",
|
|
|
|
mkdir: "Make dir.",
|
2023-10-23 08:08:11 -05:00
|
|
|
ls: "List contents of the game directory.",
|
|
|
|
glob: "Glob files in game directory.",
|
|
|
|
};
|
|
|
|
|
2023-09-07 16:46:35 -05:00
|
|
|
var Cmdline = {};
|
|
|
|
|
|
|
|
Cmdline.cmds = [];
|
2024-02-23 16:05:30 -06:00
|
|
|
Cmdline.orders = {};
|
2023-09-07 16:46:35 -05:00
|
|
|
Cmdline.register_cmd = function(flag, fn, doc) {
|
|
|
|
Cmdline.cmds.push({
|
|
|
|
flag: flag,
|
|
|
|
fn: fn,
|
|
|
|
doc: doc
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2024-04-07 13:16:54 -05:00
|
|
|
Cmdline.register_order = function(order, fn, doc, usage = "") {
|
2024-02-23 16:05:30 -06:00
|
|
|
Cmdline.orders[order] = fn;
|
|
|
|
fn.doc = doc;
|
|
|
|
fn.usage = `${order} ${usage}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
Cmdline.register_order("edit", function() {
|
2024-04-20 12:55:20 -05:00
|
|
|
if (!io.exists(projectfile)) {
|
2024-02-25 17:31:48 -06:00
|
|
|
say("No game to edit. Try making one with 'prosperon init'.");
|
|
|
|
return;
|
2024-02-23 16:05:30 -06:00
|
|
|
}
|
2024-04-03 17:17:32 -05:00
|
|
|
|
|
|
|
window.size = [1280, 720];
|
2024-04-04 17:28:11 -05:00
|
|
|
window.mode = window.modetypes.full;
|
|
|
|
sim.pause();
|
2024-04-09 16:48:15 -05:00
|
|
|
|
2024-03-18 08:16:25 -05:00
|
|
|
game.engine_start(function() {
|
2024-03-02 00:00:35 -06:00
|
|
|
global.mixin("scripts/editor.js");
|
2024-02-27 10:09:15 -06:00
|
|
|
use("editorconfig.js");
|
2024-04-04 17:28:11 -05:00
|
|
|
use("config.js");
|
2024-04-09 16:48:15 -05:00
|
|
|
render.set_font("fonts/c64.ttf", 8);
|
2024-02-23 16:05:30 -06:00
|
|
|
editor.enter_editor();
|
|
|
|
});
|
|
|
|
}, "Edit the project in this folder. Give it the name of an UR to edit that specific object.", "?UR?");
|
|
|
|
|
2024-02-25 17:31:48 -06:00
|
|
|
Cmdline.register_order("init", function() {
|
2024-03-02 23:34:41 -06:00
|
|
|
if (io.exists(projectfile)) {
|
2024-02-25 17:31:48 -06:00
|
|
|
say("Already a game here.");
|
|
|
|
return;
|
|
|
|
}
|
2024-04-18 17:34:56 -05:00
|
|
|
|
2024-04-20 12:55:20 -05:00
|
|
|
if (!(io.ls().filter(x => x[0] !== '.').length === 0)) {
|
2024-02-25 17:31:48 -06:00
|
|
|
say("Directory is not empty. Make an empty one and init there.");
|
|
|
|
return;
|
|
|
|
}
|
2024-04-18 17:34:56 -05:00
|
|
|
|
2024-04-20 12:55:20 -05:00
|
|
|
io.mkdir(io.dumpfolder);
|
2024-02-25 17:31:48 -06:00
|
|
|
var project = {};
|
|
|
|
project.version = prosperon.version;
|
|
|
|
project.revision = prosperon.revision;
|
2024-03-02 00:00:35 -06:00
|
|
|
io.slurpwrite(projectfile, json.encode(project));
|
2024-02-25 17:31:48 -06:00
|
|
|
}, "Turn the directory into a Prosperon game.");
|
|
|
|
|
2024-02-29 13:54:33 -06:00
|
|
|
Cmdline.register_order("debug", function() {
|
2024-03-05 22:23:38 -06:00
|
|
|
Cmdline.orders.play([]);
|
2024-02-29 13:54:33 -06:00
|
|
|
}, "Play the game with debugging enabled.");
|
|
|
|
|
2024-04-18 17:34:56 -05:00
|
|
|
Cmdline.register_order("web", function() {
|
|
|
|
Cmdline.orders.play([]);
|
|
|
|
}, "Play the game in a web browser.");
|
|
|
|
|
2024-03-04 11:15:55 -06:00
|
|
|
Cmdline.register_order("play", function(argv) {
|
|
|
|
if (argv[0])
|
|
|
|
io.chdir(argv[0]);
|
2024-04-17 06:32:25 -05:00
|
|
|
|
2024-03-18 08:16:25 -05:00
|
|
|
game.loadurs();
|
2024-03-04 11:15:55 -06:00
|
|
|
|
2024-03-02 00:00:35 -06:00
|
|
|
if (!io.exists(projectfile)) {
|
2024-02-25 17:31:48 -06:00
|
|
|
say("No game to play. Try making one with 'prosperon init'.");
|
|
|
|
return;
|
2024-02-23 16:05:30 -06:00
|
|
|
}
|
2024-02-25 17:31:48 -06:00
|
|
|
|
2024-03-02 00:00:35 -06:00
|
|
|
var project = json.decode(io.slurp(projectfile));
|
2024-03-18 08:16:25 -05:00
|
|
|
game.title = project.title;
|
|
|
|
window.mode = window.modetypes.expand;
|
2024-03-02 00:00:35 -06:00
|
|
|
global.mixin("config.js");
|
2024-04-16 22:27:29 -05:00
|
|
|
if (project.title) window.title = project.title;
|
|
|
|
|
2024-03-18 08:16:25 -05:00
|
|
|
if (window.rendersize.equal([0,0])) window.rendersize = window.size;
|
|
|
|
console.info(`Starting game with window size ${window.size} and render ${window.rendersize}.`);
|
2024-03-13 16:30:55 -05:00
|
|
|
|
2024-03-18 08:16:25 -05:00
|
|
|
game.engine_start(function() {
|
2024-04-16 07:48:34 -05:00
|
|
|
render.set_font("fonts/c64.ttf", 8);
|
2024-03-19 17:00:49 -05:00
|
|
|
global.app = actor.spawn("game.js");
|
2024-04-01 08:13:57 -05:00
|
|
|
if (project.icon) window.set_icon(game.texture(project.icon));
|
2024-04-03 00:44:08 -05:00
|
|
|
game.camera = world.spawn("scripts/camera2d");
|
2024-02-23 16:05:30 -06:00
|
|
|
});
|
|
|
|
}, "Play the game present in this folder.");
|
|
|
|
|
|
|
|
Cmdline.register_order("pack", function(str) {
|
|
|
|
var packname;
|
|
|
|
if (str.length === 0)
|
2024-04-16 22:27:29 -05:00
|
|
|
packname = "game.zip";
|
2024-02-23 16:05:30 -06:00
|
|
|
else if (str.length > 1) {
|
2024-02-25 17:31:48 -06:00
|
|
|
console.warn("Give me a single filename for the pack.");
|
2024-02-23 16:05:30 -06:00
|
|
|
return;
|
|
|
|
} else
|
|
|
|
packname = str[0];
|
|
|
|
|
|
|
|
say(`Packing into ${packname}`);
|
2024-04-17 06:32:25 -05:00
|
|
|
|
|
|
|
io.pack_start(packname);
|
|
|
|
var files = io.ls('.');
|
|
|
|
files = files.filter(f => !f.startsWith('.git'));
|
|
|
|
files = files.filter(f => !f.startsWith('.nova'));
|
|
|
|
files = files.filter(f => !f.includes('.DS_Store'));
|
|
|
|
files = files.filter(f => !f.startsWith('.gitignore'));
|
|
|
|
say(files);
|
|
|
|
for (var f of files)
|
|
|
|
io.pack_add(f);
|
|
|
|
io.pack_end();
|
2024-02-23 16:05:30 -06:00
|
|
|
}, "Pack the game into the given name.", "NAME");
|
|
|
|
|
2024-03-02 00:00:35 -06:00
|
|
|
Cmdline.register_order("cdb", function(argv) {
|
2024-04-16 22:27:29 -05:00
|
|
|
var cdb = "game.zip";
|
2024-03-02 00:00:35 -06:00
|
|
|
if (!io.exists(cdb)) {
|
2024-04-16 22:27:29 -05:00
|
|
|
say(`No 'game.zip' present.`);
|
2024-03-02 00:00:35 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (argv.length === 0) {
|
|
|
|
say(`cdb name: ${cdb}`);
|
|
|
|
|
|
|
|
}
|
|
|
|
}, "CDB commands.");
|
|
|
|
|
|
|
|
Cmdline.register_order("qoa", function(argv) {
|
|
|
|
var sounds = Resources.sounds.filter(x => x !== "qoa");
|
|
|
|
for (var file of argv) {
|
|
|
|
if (!sounds.includes(file.ext())) continue;
|
|
|
|
say(`converting ${file}`);
|
2024-03-18 08:16:25 -05:00
|
|
|
io.save_qoa(file);
|
2024-03-02 00:00:35 -06:00
|
|
|
}
|
|
|
|
}, "Convert file(s) to qoa.");
|
|
|
|
|
|
|
|
Cmdline.register_order("about", function(argv) {
|
|
|
|
|
|
|
|
if (!argv[0]) {
|
|
|
|
say('About your game');
|
|
|
|
say(`Prosperon version ${prosperon.version}`);
|
|
|
|
say(`Total entities ${ur._list.length}`);
|
|
|
|
}
|
|
|
|
switch (argv[0]) {
|
|
|
|
case "entities":
|
|
|
|
for (var i of ur._list) say(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}, "Get information about this game.");
|
|
|
|
|
|
|
|
Cmdline.register_order("ur", function(argv) {
|
2024-03-18 08:16:25 -05:00
|
|
|
game.loadurs();
|
2024-03-02 00:00:35 -06:00
|
|
|
for (var i of ur._list.sort()) say(i);
|
|
|
|
}, "Get information about the ur types in your game.");
|
|
|
|
|
|
|
|
Cmdline.register_order("env", function(argv) {
|
|
|
|
if (argv.length > 2) return;
|
|
|
|
var gg = json.decode(io.slurp(projectfile));
|
|
|
|
if (argv.length === 0) {
|
|
|
|
say(json.encode(gg,null,1));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argv.length === 1) {
|
|
|
|
var v = gg[argv[0]];
|
|
|
|
if (!v) {
|
|
|
|
say(`Value ${argv[0]} not found.`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
say(`${argv[0]}:${v}`);
|
|
|
|
} else {
|
|
|
|
gg[argv[0]] = argv[1];
|
|
|
|
say(`Set ${argv[0]}:${v}`);
|
|
|
|
say(json.encode(gg,null,1));
|
|
|
|
io.slurpwrite(projectfile, json.encode(gg));
|
|
|
|
}
|
|
|
|
}, "Get or set game variables.");
|
|
|
|
|
2024-02-23 16:05:30 -06:00
|
|
|
Cmdline.register_order("unpack", function() {
|
|
|
|
say("Unpacking not implemented.");
|
|
|
|
}, "Unpack this binary's contents into this folder for editing.");
|
|
|
|
|
|
|
|
Cmdline.register_order("build", function() {
|
|
|
|
say("Building not implemented.");
|
|
|
|
}, "Build static assets for this project.");
|
|
|
|
|
2024-03-02 00:00:35 -06:00
|
|
|
Cmdline.register_order("nota", function(argv) {
|
|
|
|
for (var file of argv) {
|
|
|
|
if (!io.exists(file)) {
|
|
|
|
say(`File ${file} does not exist.`);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var obj = json.decode(io.slurp(file));
|
|
|
|
var nn = nota.encode(obj);
|
|
|
|
io.slurpwrite(file.set_ext(".nota"), nn);
|
|
|
|
}
|
|
|
|
}, "Create a nota file from a json.");
|
|
|
|
|
|
|
|
Cmdline.register_order("json", function(argv) {
|
|
|
|
for (var file of argv) {
|
|
|
|
if (!io.exists(file)) {
|
|
|
|
say(`File ${file} does not exist.`);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
say(file.ext());
|
|
|
|
var obj = nota.decode(io.slurp(file));
|
|
|
|
var nn = json.encode(obj);
|
|
|
|
io.slurpwrite(file.set_ext(".json", nn));
|
|
|
|
}
|
|
|
|
}, "Create a JSON from a nota.");
|
|
|
|
|
2024-02-23 16:05:30 -06:00
|
|
|
Cmdline.register_order("api", function(obj) {
|
2024-02-25 17:31:48 -06:00
|
|
|
if (!obj[0]) {
|
2024-02-23 16:05:30 -06:00
|
|
|
Cmdline.print_order("api");
|
2024-02-25 17:31:48 -06:00
|
|
|
return;
|
|
|
|
}
|
2024-02-23 16:05:30 -06:00
|
|
|
|
2024-03-21 11:33:36 -05:00
|
|
|
use("scripts/editor.js");
|
2024-03-19 23:01:31 -05:00
|
|
|
var api = debug.api.print_doc(obj[0]);
|
2024-02-23 16:05:30 -06:00
|
|
|
if (!api)
|
|
|
|
return;
|
|
|
|
|
|
|
|
say(api);
|
|
|
|
}, "Print the API for an object as markdown. Give it a file to save the output to.", "OBJECT");
|
|
|
|
|
|
|
|
Cmdline.register_order("input", function(pawn) {
|
2024-03-21 11:33:36 -05:00
|
|
|
use("scripts/editor.js");
|
2024-02-23 16:05:30 -06:00
|
|
|
say(`## Input for ${pawn}`);
|
2024-02-25 17:31:48 -06:00
|
|
|
eval(`say(input.print_md_kbm(${pawn}));`);
|
2024-02-23 16:05:30 -06:00
|
|
|
}, "Print input documentation for a given object as markdown. Give it a file to save the output to", "OBJECT ?FILE?");
|
|
|
|
|
|
|
|
Cmdline.register_order("run", function(script) {
|
|
|
|
script = script.join(" ");
|
|
|
|
if (!script) {
|
|
|
|
say("Need something to run.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-21 11:33:36 -05:00
|
|
|
say(use(script));
|
2024-02-23 16:05:30 -06:00
|
|
|
}, "Run a given script. SCRIPT can be the script itself, or a file containing the script", "SCRIPT");
|
|
|
|
|
2024-02-25 17:31:48 -06:00
|
|
|
Cmdline.orders.script = Cmdline.orders.run;
|
|
|
|
|
2024-02-23 16:05:30 -06:00
|
|
|
Cmdline.print_order = function(fn)
|
|
|
|
{
|
|
|
|
if (typeof fn === 'string')
|
|
|
|
fn = Cmdline.orders[fn];
|
|
|
|
|
|
|
|
if (!fn) return;
|
|
|
|
say(`Usage: prosperon ${fn.usage}`);
|
|
|
|
say(fn.doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
Cmdline.register_order("help", function(order) {
|
|
|
|
|
|
|
|
if (!Object.empty(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())
|
|
|
|
say(cmd);
|
|
|
|
|
|
|
|
Cmdline.orders.version();
|
|
|
|
}, "Give help with a specific command.", "TOPIC");
|
|
|
|
|
|
|
|
Cmdline.register_order("version", function() {
|
|
|
|
say(`Prosperon version ${prosperon.version} [${prosperon.revision}]`);
|
|
|
|
}, "Display Prosperon info.");
|
|
|
|
|
2023-09-07 16:46:35 -05:00
|
|
|
function cmd_args(cmdargs)
|
|
|
|
{
|
|
|
|
var play = false;
|
2024-02-23 16:05:30 -06:00
|
|
|
var cmds = cmdargs.split(/\s+/).slice(1);
|
|
|
|
|
|
|
|
if (cmds.length === 0)
|
|
|
|
cmds[0] = "play";
|
|
|
|
else if (!Cmdline.orders[cmds[0]]) {
|
2024-05-15 16:34:03 -05:00
|
|
|
console.warn(`Command ${cmds[0]} not found. Playing instead.`);
|
|
|
|
cmds[0] = "play";
|
2024-02-23 16:05:30 -06:00
|
|
|
}
|
2024-03-28 17:40:14 -05:00
|
|
|
|
2024-02-23 16:05:30 -06:00
|
|
|
Cmdline.orders[cmds[0]](cmds.slice(1));
|
2024-03-28 17:40:14 -05:00
|
|
|
if (!game.startengine)
|
|
|
|
os.exit(0);
|
2023-09-07 16:46:35 -05:00
|
|
|
}
|
|
|
|
|
2024-02-25 17:31:48 -06:00
|
|
|
Cmdline.register_order("clean", function(argv) {
|
|
|
|
say("Cleaning not implemented.");
|
|
|
|
}, "Clean up a given object file.", "JSON ...");
|
2023-10-26 11:48:02 -05:00
|
|
|
|
2024-03-14 10:21:44 -05:00
|
|
|
Cmdline.register_order("test", function(argv) {
|
|
|
|
use("scripts/test.js");
|
|
|
|
}, "Run tests.");
|
|
|
|
|
2024-02-25 17:31:48 -06:00
|
|
|
Cmdline.register_cmd("l", function(n) {
|
|
|
|
console.level = n;
|
|
|
|
}, "Set log level.");
|
2024-02-27 10:09:15 -06:00
|
|
|
|
2024-04-28 13:33:37 -05:00
|
|
|
function convertYAMLtoJSON(yamlString) {
|
|
|
|
const lines = yamlString.split('\n');
|
|
|
|
const jsonObj = {};
|
|
|
|
|
|
|
|
let currentKey = '';
|
|
|
|
let currentValue = '';
|
|
|
|
let currentDepth = 0;
|
|
|
|
|
|
|
|
for (let i = 0; i < lines.length; i++) {
|
|
|
|
const line = lines[i].trim();
|
|
|
|
if (!line || line.startsWith('#')) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const depth = (line.match(/^\s+/g) || [''])[0].length;
|
|
|
|
const keyValue = line.split(':');
|
|
|
|
const key = keyValue[0].trim();
|
|
|
|
const value = keyValue[1].trim();
|
|
|
|
|
|
|
|
if (depth > currentDepth) {
|
|
|
|
jsonObj[currentKey] = convertYAMLtoJSON(currentValue);
|
|
|
|
currentKey = key;
|
|
|
|
currentValue = value;
|
|
|
|
} else if (depth === currentDepth) {
|
|
|
|
jsonObj[currentKey] = convertYAMLtoJSON(currentValue);
|
|
|
|
currentKey = key;
|
|
|
|
currentValue = value;
|
|
|
|
} else {
|
|
|
|
jsonObj[currentKey] = convertYAMLtoJSON(currentValue);
|
|
|
|
currentKey = '';
|
|
|
|
currentValue = '';
|
|
|
|
i--; // To reprocess the current line with updated values
|
|
|
|
}
|
|
|
|
|
|
|
|
currentDepth = depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentKey) {
|
|
|
|
jsonObj[currentKey] = convertYAMLtoJSON(currentValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
return jsonObj;
|
|
|
|
}
|
|
|
|
|
2024-02-27 10:09:15 -06:00
|
|
|
return {
|
|
|
|
Resources,
|
|
|
|
Cmdline,
|
2024-04-28 13:33:37 -05:00
|
|
|
cmd_args,
|
|
|
|
convertYAMLtoJSON
|
2024-02-27 10:09:15 -06:00
|
|
|
};
|
2024-04-15 15:03:23 -05:00
|
|
|
|