From 54256a51610baaa0ccf930dc7a5d931fc2c1d241 Mon Sep 17 00:00:00 2001 From: KonAki Date: Sun, 18 Oct 2026 04:04:59 +0800 Subject: build.c: konedit target and fs module --- README.md | 15 ++++++++++++++- build.c | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 537bcb0..9ee1417 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ The reusable stuff is single-header and lives in [kon](kon). Those are the ones - konfont: text, built-in bitmap font or a ttf - kontime: timing and sleeping - kontoml: a very minimal toml parser +- konfs: folders and paths, listing a folder and walking up it, on POSIX and Windows - koninput: input state on top of konwinlib The engine modules are a `.h` and a `.c` pair, they depend on each other a bit, and you pick which ones to build: @@ -30,6 +31,7 @@ The engine modules are a `.h` and a `.c` pair, they depend on each other a bit, | --- | --- | | font | konfont | | toml | kontoml | +| fs | konfs | | tile | tilemaps and sprite sheets | | 2d | what any 2D game needs: a scrolling camera, frame animation, drawing frames of a sprite sheet | | fx | whole screen effects done on the pixels: fade to a colour, flash, shake and tone (adds 2d) | @@ -97,7 +99,7 @@ yes, it's just that. If a module needs another one it adds it for you, so `debug - `-j` is how many files to compile at once, one for each processor if you leave it out. - `-v` shows the compiler commands as they run. -targets are `all`, `run`, `clean`, `tools`, `pack` and `examples`. +targets are `all`, `run`, `clean`, `tools`, `pack`, `examples` and `konedit`. @@ -149,6 +151,17 @@ Loose files in the `assets` folder override the ones in the pack only in the dev obj/konmodel art/models/Fox.glb assets/models/fox.kmdl -t models/ ``` +## Editor + +konedit is the editor, a program built on the engine's own ui. It works on plain files in a project folder, the same ones the engine loads, plus a `project.toml` for the name and the assets folder. + +```sh +./build.sh -d konedit +obj/konedit [project folder] +``` + +It adds the modules it needs itself. File > New Project makes a project.toml and an assets folder, File > Open Project opens one, Ctrl+S saves. The tabs for the tilemap, script and level editors are not written yet. + ## Examples The examples are their own little programs, in the [examples](examples) folder. Each one says how to build it at the top of the file. diff --git a/build.c b/build.c index 9938016..b69c3c2 100644 --- a/build.c +++ b/build.c @@ -30,7 +30,7 @@ typedef struct module } module_t; static const module_t known[] = { - {"font", ""}, {"toml", ""}, {"tile", ""}, {"pack", ""}, {"ui", "font"}, {"debug", "font assets"}, + {"font", ""}, {"toml", ""}, {"fs", ""}, {"tile", ""}, {"pack", ""}, {"ui", "font"}, {"debug", "font assets"}, {"assets", "pack"}, {"image", ""}, {"audio", ""}, {"mic", ""}, {"sound", "audio"}, {"model", "assets"}, {"2d", ""}, {"fx", "2d"}, {"particles", ""}, {"picture", "2d"}, {"rm", ""}, {"rmmap", ""}, {"rmtile", ""}, {"rmdraw", "rmmap rmtile"}, {"rmfield", "rmmap"}, {"rmplugin", ""}, {"rmdata", "battle party save"}, @@ -118,7 +118,7 @@ static void usage(void) fprintf(stderr, "modules: "); for (i = 0; i < KNOWN; i++) fprintf(stderr, " %s", known[i].name); fprintf(stderr, "\nplatforms: native linux bsd windows\n"); - fprintf(stderr, "targets: all run clean tools pack examples\n"); + fprintf(stderr, "targets: all run clean tools pack examples konedit\n"); exit(1); } @@ -609,6 +609,8 @@ static void targetRun(void) static const char *toolNames[] = {"konpack", "konmodel", "mzsurvey", "mzscript", "kons2c", "mzmap", "mzdata"}; +static const char *editorName = "konedit"; + static const char *examples[] = {"modelview", "sound", "ui", "platform", "dialog", "script", "corridor", "hills", "sectorview"}; /* only is the name of one example, or NULL for all of them */ @@ -634,6 +636,30 @@ static void targetExamples(const char *only) runJobs(); } +/* the editor is a program of its own with the modules it needs, so asking for it adds them */ +static void targetEditor(void) +{ + const char *all[OBJECTS_MAX + 16]; + int n = 0, k; + + queueObjects(0); + queueCompile("editor/konedit.c", objPath(editorName), 0, NULL); + runJobs(); + all[n++] = objPath(editorName); + for (k = 0; k < objectCount; k++) all[n++] = objects[k]; + queueLink(exePath(editorName), all, (size_t)n, 1); + runJobs(); +} + +static int isEditorTarget(const char *t) +{ + size_t d = strlen(objdir); + + if (strcmp(t, editorName) == 0) return 1; + if (strncmp(t, objdir, d) != 0 || t[d] != 0x2f) return 0; + return strcmp(t + d + 1, editorName) == 0 || strcmp(t + d + 1, "konedit.exe") == 0; +} + /* a program made straight from some files, with the headers they read checked too. the converters do not link the engine */ static void queueTool(const char *name, const char **sources, size_t count, const KonCmd *flags, int withEngineFlags, int withMath) { @@ -783,6 +809,7 @@ static void targetClean(void) removeFile(exePath(PROGRAM)); for (i = 0; i < sizeof(toolNames) / sizeof(toolNames[0]); i++) removeFile(exePath(toolNames[i])); for (i = 0; i < sizeof(examples) / sizeof(examples[0]); i++) removeFile(exePath(examples[i])); + removeFile(exePath(editorName)); removeFile(kon_fmt("%s/data.kpk", objdir)); removeFile(kon_fmt("%s/assets.lst", objdir)); } @@ -811,6 +838,10 @@ static int targetFile(const char *t) return 1; } } + if (strcmp(name, editorName) == 0) { + targetEditor(); + return 1; + } if (strcmp(name, PROGRAM) == 0) { targetAll(); return 1; @@ -868,6 +899,9 @@ int main(int argc, char **argv) } } if (targetCount == 0) targets[targetCount++] = "all"; + for (i = 0; i < targetCount; i++) { + if (isEditorTarget(targets[i])) addModuleList("ui,font,toml,fs"); + } maxJobs = jobsAsked > 0 ? jobsAsked : kon_cpuCount(); setup(); @@ -887,6 +921,7 @@ int main(int argc, char **argv) else if (strcmp(t, "tools") == 0) targetTools(); else if (strcmp(t, "pack") == 0) targetPack(); else if (strcmp(t, "examples") == 0) targetExamples(NULL); + else if (strcmp(t, editorName) == 0) targetEditor(); else if (!targetFile(t)) { fprintf(stderr, "build: unknown target '%s'\n", t); usage(); -- cgit