Kept the level editor local-only
- Ignored/untracked src/editor and docs/LEVEL_EDITOR.md (files stay on disk) - Guarded the editor CMake target so fresh clones configure without it - Trimmed README to level-data/bake docs and dropped stale editor doc links
This commit is contained in:
parent
517dbbdc38
commit
cc28057851
8 changed files with 26 additions and 1508 deletions
7
.gitignore
vendored
7
.gitignore
vendored
|
|
@ -2,3 +2,10 @@ build/
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.blend1
|
*.blend1
|
||||||
|
|
||||||
|
# The standalone level editor is local-only, never pushed.
|
||||||
|
src/editor/
|
||||||
|
docs/LEVEL_EDITOR.md
|
||||||
|
|
||||||
|
# Local Pi Forgejo credentials; never commit.
|
||||||
|
pi-forgejo-credentials.md
|
||||||
|
|
|
||||||
|
|
@ -111,12 +111,16 @@ add_test(NAME level_fixture_bad_gap
|
||||||
COMMAND level_tool --check ${CMAKE_SOURCE_DIR}/tests/data/bad_gap.json)
|
COMMAND level_tool --check ${CMAKE_SOURCE_DIR}/tests/data/bad_gap.json)
|
||||||
set_tests_properties(level_fixture_bad_gap PROPERTIES WILL_FAIL TRUE)
|
set_tests_properties(level_fixture_bad_gap PROPERTIES WILL_FAIL TRUE)
|
||||||
|
|
||||||
add_executable(editor
|
# The standalone level editor is local-only and not shipped with the game.
|
||||||
src/editor/main.cpp
|
# Build it only when its sources are present in the working tree.
|
||||||
src/editor/editor_app.cpp
|
if(EXISTS ${CMAKE_SOURCE_DIR}/src/editor/main.cpp)
|
||||||
src/render/raygui_impl.cpp)
|
add_executable(editor
|
||||||
target_include_directories(editor PRIVATE src third_party/raygui third_party/clay)
|
src/editor/main.cpp
|
||||||
target_link_libraries(editor PRIVATE raylib level_core)
|
src/editor/editor_app.cpp
|
||||||
|
src/render/raygui_impl.cpp)
|
||||||
|
target_include_directories(editor PRIVATE src third_party/raygui third_party/clay)
|
||||||
|
target_link_libraries(editor PRIVATE raylib level_core)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_executable(cntrl
|
add_executable(cntrl
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
|
|
|
||||||
41
README.md
41
README.md
|
|
@ -103,41 +103,16 @@ F9 hides it.
|
||||||
raylib 6.2 is fetched automatically by CMake (FetchContent). Needs a C++23 compiler
|
raylib 6.2 is fetched automatically by CMake (FetchContent). Needs a C++23 compiler
|
||||||
(GCC 13+) and OpenGL/X11 dev headers (already required by GLFW).
|
(GCC 13+) and OpenGL/X11 dev headers (already required by GLFW).
|
||||||
|
|
||||||
## Level editor
|
## Level data
|
||||||
|
|
||||||
The editor is a **separate binary** (`editor`) and shares only the raylib-free
|
The standalone level editor is a local-only tool; its sources and docs are not
|
||||||
`level_core` library with the game:
|
part of this repository. `cntrl --level <path>` can still playtest any level
|
||||||
|
JSON directly.
|
||||||
|
|
||||||
```sh
|
`assets/levels/floor01.json` is the authoring source of truth. It is baked into
|
||||||
cmake --build build -j6
|
the client at build time (`src/game/level_baked.hpp`, regenerated by
|
||||||
./build/editor # loads assets/levels/floor01.json
|
`level_tool --bake` when the JSON changes), so `cntrl` ships without a runtime
|
||||||
./build/editor --level my_level.json
|
level-file dependency. Baking refuses invalid levels:
|
||||||
./build/editor --level my_level.json --game ./build/cntrl
|
|
||||||
```
|
|
||||||
|
|
||||||
LMB selects/drags props, RMB orbits, MMB pans, wheel zooms, `F` frames the
|
|
||||||
level. Keys `1`–`4` switch between Select, Wall, Door and Decor tools: walls
|
|
||||||
and doors are drawn by clicking two ground points, decor is dragged from the
|
|
||||||
asset browser (all GLBs under `assets/models/`) into the 3D view. `Del` deletes
|
|
||||||
the selection, `Ctrl+Z`/`Ctrl+Y` (`Ctrl+Shift+Z`) undo/redo, `Ctrl+S` saves,
|
|
||||||
`Tab` toggles the inspector, `Esc` quits. Deleting a wall segment opens a gap
|
|
||||||
which can be restored from the inspector. See `docs/LEVEL_EDITOR.md` for the
|
|
||||||
full key map and field reference.
|
|
||||||
|
|
||||||
The **inspector** (right dock) edits every field of the current selection:
|
|
||||||
prop kind, position, size, yaw, scale, model, `solid`/`destructible`; wall
|
|
||||||
lines and gaps; doors; rooms; rituals; thermo doors; and the spawn/key/exit
|
|
||||||
anchors. With nothing selected it edits the level name and map dimensions.
|
|
||||||
The validation panel runs a walkable-grid flood fill from the spawn (with
|
|
||||||
gated doors both open and closed) and reports unreachable rooms, the key or
|
|
||||||
the exit, overlapping rooms, duplicate ids and missing models.
|
|
||||||
|
|
||||||
`Ctrl+P` saves if needed and launches the game on the current level
|
|
||||||
(`cntrl --level <path>`), so drafts can be playtested without baking. The
|
|
||||||
level file is the authoring source of truth; `Floor 01` is baked into the
|
|
||||||
client at build time (`src/game/level_baked.hpp`, regenerated by
|
|
||||||
`level_tool --bake` when the JSON changes), so `cntrl` ships without a level
|
|
||||||
file dependency. Baking refuses invalid levels:
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./build/level_tool --dump-floor01 assets/levels/floor01.json
|
./build/level_tool --dump-floor01 assets/levels/floor01.json
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ The findings above are the audit baseline. Fixes have since landed in four phase
|
||||||
|
|
||||||
Verification performed: `cmake --build build -j6` clean; standalone C++ harnesses for the ritual state machine and clearance/side-room flow pass; `--floor-overview` screenshots confirm the new corridor, projector marker, locked doors and HUD stamp.
|
Verification performed: `cmake --build build -j6` clean; standalone C++ harnesses for the ritual state machine and clearance/side-room flow pass; `--floor-overview` screenshots confirm the new corridor, projector marker, locked doors and HUD stamp.
|
||||||
|
|
||||||
**Level-editor iteration (same date, follow-up work):** the standalone editor gained a raygui inspector covering every `LevelData` field, stable wall/segment IDs (deleting a segment opens a reversible gap), two-state connectivity validation (doors open *and* closed), a bake gate that refuses invalid levels, `cntrl --level <path>` for playtesting drafts, and fixture-backed CTest coverage. This is tooling only; the open gameplay findings below are unchanged. See `docs/LEVEL_EDITOR.md`.
|
**Level-editor iteration (same date, follow-up work):** the standalone editor gained a raygui inspector covering every `LevelData` field, stable wall/segment IDs (deleting a segment opens a reversible gap), two-state connectivity validation (doors open *and* closed), a bake gate that refuses invalid levels, `cntrl --level <path>` for playtesting drafts, and fixture-backed CTest coverage. This is tooling only; the open gameplay findings below are unchanged. The editor is local-only and not shipped with the game.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,95 +0,0 @@
|
||||||
# FBC: NIGHT SHIFT — Level Editor
|
|
||||||
|
|
||||||
The editor authors `assets/levels/*.json`, the single source of truth for the
|
|
||||||
playable floor. The game reads a JSON at runtime (`cntrl --level <path>`) and
|
|
||||||
falls back to the build-time baked copy (`src/game/level_baked.hpp`), which is
|
|
||||||
regenerated by `level_tool --bake` whenever the JSON changes.
|
|
||||||
|
|
||||||
## Build and launch
|
|
||||||
|
|
||||||
```sh
|
|
||||||
cmake --build build -j6
|
|
||||||
./build/editor # assets/levels/floor01.json
|
|
||||||
./build/editor --level my_level.json --game ./build/cntrl
|
|
||||||
./build/editor --screenshot /tmp/editor.png # headless smoke capture
|
|
||||||
./build/editor --place plant 12.5 44 # debug: place an asset by name
|
|
||||||
```
|
|
||||||
|
|
||||||
`--game` sets the binary launched by `Ctrl+P`; without it the editor detects
|
|
||||||
`./cntrl`, `./build/cntrl` or `../cntrl` in that order. `--place`
|
|
||||||
selects the placed prop so its inspector fields can be inspected in a capture.
|
|
||||||
|
|
||||||
## Controls
|
|
||||||
|
|
||||||
| Input | Action |
|
|
||||||
|---|---|
|
|
||||||
| LMB (Select) | Select nearest prop/wall/door/room/ritual/thermo/anchor; drag props |
|
|
||||||
| LMB (Wall / Door) | First click starts the span, second click finishes it |
|
|
||||||
| LMB (Decor) | Place the selected asset from the browser |
|
|
||||||
| LMB drag from browser | Place the selected asset at the drop point |
|
|
||||||
| RMB or Alt+LMB | Orbit |
|
|
||||||
| MMB | Pan |
|
|
||||||
| Wheel | Zoom (scrolls the asset browser over its panel) |
|
|
||||||
| `1`–`4` | Select / Wall / Door / Decor tools |
|
|
||||||
| `Del` / `Backspace` | Delete the selection (anchors can only be moved) |
|
|
||||||
| `Ctrl+Z` / `Ctrl+Y` / `Ctrl+Shift+Z` | Undo / redo |
|
|
||||||
| `Ctrl+S` | Save to the current level path |
|
|
||||||
| `Ctrl+P` | Save if dirty, then launch `cntrl --level <path>` |
|
|
||||||
| `F` | Frame the whole level |
|
|
||||||
| `Tab` | Toggle the inspector |
|
|
||||||
| `Esc` | Quit |
|
|
||||||
|
|
||||||
## Inspector field reference
|
|
||||||
|
|
||||||
The right-hand dock edits the current selection. Numeric fields are sliders,
|
|
||||||
enums are combo boxes, booleans are check boxes and names/paths are text boxes.
|
|
||||||
Edits share one undo step per interaction (one per drag or text-box focus).
|
|
||||||
|
|
||||||
| Selection | Fields |
|
|
||||||
|---|---|
|
|
||||||
| none (level) | `name`, `map_width`, `map_height`, `scale` |
|
|
||||||
| Prop | `kind`, `pos`, `w`, `d`, `h`, `y offset`, `yaw deg`, `scale`, `model`, `room_kind`, `solid`, `destructible` |
|
|
||||||
| Wall line | `axis`, `coord`, `from`, `to`, `height`, each gap's start/end, **DEL GAP**, **OPEN SEGMENT GAP** |
|
|
||||||
| Door | `id`, `rect` (`x0/y0/x1/y1`), `height` |
|
|
||||||
| Room | `name`, `rect`, `kind`, `flow`, `side idx` |
|
|
||||||
| Ritual | `type`, `pos`, `radius`, `duration`, `ring radius`, `ring count`, `light radius`, `light mult`, `light dur` |
|
|
||||||
| Thermo door | `pos`, `span`, `yaw deg` |
|
|
||||||
| Spawn / Key / Exit | `pos`; Key/Exit also their pickup/trigger radius |
|
|
||||||
|
|
||||||
**Scale convention:** `scale` is the multiplier passed straight to raylib's
|
|
||||||
`DrawModelEx`, identical to the game's presenter. `w/d/h` are metadata used for
|
|
||||||
selection boxes and (for `solid` props) collision. Deleting a wall segment
|
|
||||||
adds a gap to the wall line; gaps are normalized (clamped, sorted, merged) and
|
|
||||||
can be removed from the inspector to close a passage again.
|
|
||||||
|
|
||||||
## Validation and baking
|
|
||||||
|
|
||||||
The validation readout at the top of the inspector is computed by
|
|
||||||
`level::validate()` (the same code `level_tool --validate` uses):
|
|
||||||
|
|
||||||
- gated doors are tested both open and closed; a main room reachable only
|
|
||||||
through a gated door is an error, a gated side room is expected;
|
|
||||||
- solid props and walls both block the walkable-grid flood fill from spawn;
|
|
||||||
- spawn/key/exit must lie inside the map and outside walls;
|
|
||||||
- rooms must be reachable from spawn, key and exit too;
|
|
||||||
- duplicate door ids, duplicate ritual types, overlapping rooms, malformed
|
|
||||||
gaps, missing/out-of-range numeric fields and missing model files are
|
|
||||||
reported.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
./build/level_tool --check assets/levels/floor01.json # round-trip + validation
|
|
||||||
./build/level_tool --validate assets/levels/floor01.json # validation only
|
|
||||||
./build/level_tool --bake <level.json> <baked.hpp> # refuses invalid levels
|
|
||||||
cmake --build build --target check_level
|
|
||||||
ctest --test-dir build --output-on-failure
|
|
||||||
```
|
|
||||||
|
|
||||||
Schema is `version: 1`; `from_json` accepts unknown optional fields but
|
|
||||||
rejects out-of-range values. New fields should default safely when absent.
|
|
||||||
|
|
||||||
## Other tools
|
|
||||||
|
|
||||||
`tools/blender/import_level.py` reads the same JSON into a reviewable Blender
|
|
||||||
blockout (set `CNTRL_LEVEL` for a different file, `CNTRL_OUT` for a different
|
|
||||||
`.blend` output). `tests/data/` holds a valid fixture and an intentionally
|
|
||||||
invalid one wired into CTest.
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,132 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "level/asset_catalog.hpp"
|
|
||||||
#include "level/level_data.hpp"
|
|
||||||
#include "level/validation.hpp"
|
|
||||||
#include "raylib.h"
|
|
||||||
|
|
||||||
namespace editor {
|
|
||||||
|
|
||||||
enum class Tool { Select, Wall, Door, Decor };
|
|
||||||
|
|
||||||
enum class Entity { None, Prop, Room, Wall, Door, Ritual, Thermo, Spawn };
|
|
||||||
|
|
||||||
struct Selection {
|
|
||||||
Entity kind = Entity::None;
|
|
||||||
int index = -1; // entity index; for Wall this is the WallLine index
|
|
||||||
int sub = -1; // visible segment index for Wall
|
|
||||||
};
|
|
||||||
|
|
||||||
class App {
|
|
||||||
public:
|
|
||||||
explicit App(std::string path);
|
|
||||||
|
|
||||||
void init();
|
|
||||||
void update();
|
|
||||||
void draw();
|
|
||||||
void shutdown();
|
|
||||||
|
|
||||||
bool should_close() const { return should_close_; }
|
|
||||||
const std::string& path() const { return path_; }
|
|
||||||
bool dirty() const { return dirty_; }
|
|
||||||
void debug_place(const std::string& asset_name, Vec2 map_pos);
|
|
||||||
void set_game_path(const std::string& path) { game_path_ = path; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
void update_camera();
|
|
||||||
void handle_keys();
|
|
||||||
void handle_pointer();
|
|
||||||
void select_at(Vector2 mouse);
|
|
||||||
void place_decor(Vec2 map_pos);
|
|
||||||
void finish_wall(Vec2 map_pos);
|
|
||||||
void finish_door(Vec2 map_pos);
|
|
||||||
void delete_selection();
|
|
||||||
void push_undo();
|
|
||||||
void push_snapshot(const std::string& snapshot);
|
|
||||||
void begin_edit();
|
|
||||||
void end_edit();
|
|
||||||
void commit();
|
|
||||||
void revalidate();
|
|
||||||
void undo();
|
|
||||||
void redo();
|
|
||||||
void restore(const std::string& snapshot);
|
|
||||||
void frame_level();
|
|
||||||
void playtest();
|
|
||||||
|
|
||||||
bool ground_point(Vec2& map_pos) const;
|
|
||||||
bool inside_panel(Vector2 mouse) const;
|
|
||||||
bool inside_inspector(Vector2 mouse) const;
|
|
||||||
int asset_at(Vector2 mouse) const;
|
|
||||||
Model& model_for(const std::string& path);
|
|
||||||
Vector3 model_size(const std::string& path);
|
|
||||||
void draw_model(const std::string& path, Vec2 world_pos, float yaw,
|
|
||||||
float scale, float y);
|
|
||||||
|
|
||||||
Vector3 camera_offset() const;
|
|
||||||
Vector3 world(Vec2 p, float y = 0.0f) const;
|
|
||||||
Vector3 world_direct(Vec2 p, float y = 0.0f) const;
|
|
||||||
Vec2 prop_world_pos(const level::Prop& p) const;
|
|
||||||
void draw_rooms() const;
|
|
||||||
void draw_grid() const;
|
|
||||||
void draw_walls() const;
|
|
||||||
void draw_props();
|
|
||||||
void draw_anchors() const;
|
|
||||||
void draw_ui() const;
|
|
||||||
void draw_asset_panel() const;
|
|
||||||
void draw_inspector();
|
|
||||||
void draw_inspector_fields(float x, float y, float w);
|
|
||||||
|
|
||||||
bool field_header(const char* text, float x, float y, float w);
|
|
||||||
bool field_bool(float x, float y, float w, const char* label, bool& value);
|
|
||||||
bool field_float(float x, float y, float w, const char* label, float& value,
|
|
||||||
float lo, float hi);
|
|
||||||
bool field_int(float x, float y, float w, const char* label, int& value,
|
|
||||||
int lo, int hi);
|
|
||||||
bool field_enum(float x, float y, float w, const char* label, int& value,
|
|
||||||
const char* items, int count);
|
|
||||||
bool field_text(float x, float y, float w, int id, const char* label,
|
|
||||||
std::string& value);
|
|
||||||
void commit_text();
|
|
||||||
|
|
||||||
level::LevelData level_;
|
|
||||||
level::ValidationResult validation_;
|
|
||||||
std::string path_;
|
|
||||||
std::string game_path_ = "./cntrl";
|
|
||||||
Camera3D camera_{};
|
|
||||||
Vector3 target_{};
|
|
||||||
float yaw_ = 0.0f;
|
|
||||||
float pitch_ = 0.85f;
|
|
||||||
float distance_ = 320.0f;
|
|
||||||
Selection selection_;
|
|
||||||
bool dirty_ = false;
|
|
||||||
bool should_close_ = false;
|
|
||||||
Vector2 last_mouse_{};
|
|
||||||
|
|
||||||
Tool tool_ = Tool::Select;
|
|
||||||
std::vector<level::Asset> assets_;
|
|
||||||
int selected_asset_ = -1;
|
|
||||||
int asset_scroll_ = 0;
|
|
||||||
bool dragging_panel_asset_ = false;
|
|
||||||
bool dragging_prop_ = false;
|
|
||||||
int dragged_prop_ = -1;
|
|
||||||
bool pending_set_ = false;
|
|
||||||
Vec2 pending_{};
|
|
||||||
std::vector<std::string> undo_;
|
|
||||||
std::vector<std::string> redo_;
|
|
||||||
std::unordered_map<std::string, Model> models_;
|
|
||||||
std::unordered_map<std::string, Vector3> model_sizes_;
|
|
||||||
|
|
||||||
bool inspector_ = true;
|
|
||||||
bool interacting_ = false;
|
|
||||||
int text_focus_ = -1;
|
|
||||||
Rectangle text_rect_{};
|
|
||||||
char text_buf_[256] = {};
|
|
||||||
std::string status_message_;
|
|
||||||
float status_timer_ = 0.0f;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace editor
|
|
||||||
|
|
@ -1,64 +0,0 @@
|
||||||
#include <cstdio>
|
|
||||||
#include <cstring>
|
|
||||||
#include <filesystem>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "editor/editor_app.hpp"
|
|
||||||
#include "raylib.h"
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
|
||||||
std::string path = "assets/levels/floor01.json";
|
|
||||||
std::string game_path;
|
|
||||||
std::string screenshot;
|
|
||||||
std::string place_asset;
|
|
||||||
float place_x = 0.0f;
|
|
||||||
float place_y = 0.0f;
|
|
||||||
for (int i = 1; i < argc; ++i) {
|
|
||||||
if (std::strcmp(argv[i], "--level") == 0 && i + 1 < argc) {
|
|
||||||
path = argv[++i];
|
|
||||||
} else if (std::strcmp(argv[i], "--game") == 0 && i + 1 < argc) {
|
|
||||||
game_path = argv[++i];
|
|
||||||
} else if (std::strcmp(argv[i], "--screenshot") == 0 && i + 1 < argc) {
|
|
||||||
screenshot = argv[++i];
|
|
||||||
} else if (std::strcmp(argv[i], "--place") == 0 && i + 3 < argc) {
|
|
||||||
place_asset = argv[++i];
|
|
||||||
place_x = std::stof(argv[++i]);
|
|
||||||
place_y = std::stof(argv[++i]);
|
|
||||||
} else if (std::strcmp(argv[i], "--help") == 0) {
|
|
||||||
std::printf("usage: editor [--level <path>] [--game <path>]\n"
|
|
||||||
" [--screenshot <path>]\n"
|
|
||||||
" [--place <asset-name> <map-x> <map-y>]\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (game_path.empty()) {
|
|
||||||
for (const char* candidate : {"./cntrl", "./build/cntrl", "../cntrl"}) {
|
|
||||||
if (std::filesystem::exists(candidate)) {
|
|
||||||
game_path = candidate;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (game_path.empty()) game_path = "./build/cntrl";
|
|
||||||
}
|
|
||||||
|
|
||||||
SetTraceLogLevel(LOG_WARNING);
|
|
||||||
InitWindow(1400, 900, "FBC: NIGHT SHIFT - Level Editor");
|
|
||||||
SetTargetFPS(60);
|
|
||||||
|
|
||||||
editor::App app(path);
|
|
||||||
app.set_game_path(game_path);
|
|
||||||
app.init();
|
|
||||||
if (!place_asset.empty()) app.debug_place(place_asset, {place_x, place_y});
|
|
||||||
int frames = 0;
|
|
||||||
while (!WindowShouldClose() && !app.should_close()) {
|
|
||||||
app.update();
|
|
||||||
app.draw();
|
|
||||||
if (!screenshot.empty() && ++frames == 30) {
|
|
||||||
TakeScreenshot(screenshot.c_str());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
app.shutdown();
|
|
||||||
CloseWindow();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Loading…
Add table
Reference in a new issue