Can now script maze gen with a json.

This commit is contained in:
Zed A. Shaw 2026-03-13 01:55:26 -04:00
parent a71d6340db
commit c615f4fc1e
3 changed files with 79 additions and 10 deletions

View file

@ -452,4 +452,46 @@ namespace maze {
// didn't find a way to make it valid
return now_valid;
}
std::pair<Builder, bool> script(Map& map, nlohmann::json& config) {
maze::Builder maze(map);
for(auto& action : config) {
std::string aname = action["action"];
fmt::println("ACTION {}", aname);
if(aname == "hunt_and_kill") {
maze.hunt_and_kill();
} else if(aname == "clear") {
maze.clear();
} else if(aname == "inner_box") {
std::vector<int> data = action["data"];
maze.inner_box(data[0], data[1]);
} else if(aname == "randomize_rooms") {
std::vector<int> data = action["data"];
maze.randomize_rooms(data[0]);
} else if(aname == "open_box") {
std::vector<int> data = action["data"];
maze.open_box(data[0]);
} else if(aname == "make_doors") {
maze.make_doors();
} else if(aname == "divide") {
std::vector<size_t> data = action["data"];
maze.divide({data[0], data[1]}, {data[2], data[3]});
} else if(aname == "inner_donut") {
std::vector<float> data = action["data"];
maze.inner_donut(data[0], data[1]);
} else if(aname == "remove_dead_ends") {
maze.remove_dead_ends();
} else if(aname == "enclose") {
maze.enclose();
} else {
dbc::sentinel(fmt::format("Invalid maze action {}", aname));
}
}
bool valid = maze.repair();
return {maze, valid};
}
}

View file

@ -46,4 +46,6 @@ namespace maze {
void punch_dead_end(size_t at_x, size_t at_y, size_t x, size_t y);
void in_bounds(size_t x, size_t y);
};
std::pair<Builder, bool> script(Map& map, nlohmann::json& config);
}