eco2d/code/game/src/debug_ui_actions.c

235 lines
5.5 KiB
C
Raw Normal View History

2021-05-13 12:36:07 +00:00
#include "debug_ui.h"
2021-08-11 10:22:46 +00:00
#include "world/blocks.h"
2021-08-25 21:36:20 +00:00
#include "items.h"
2021-08-10 15:21:25 +00:00
2021-08-11 19:51:15 +00:00
void
2021-05-13 12:36:07 +00:00
ActExitGame(void) {
2021-05-13 14:12:18 +00:00
game_request_close();
2021-08-09 13:35:47 +00:00
}
2021-08-11 19:51:15 +00:00
void
2021-08-09 13:35:47 +00:00
ActSpawnCar(void) {
2021-08-09 17:30:39 +00:00
ecs_entity_t e = vehicle_spawn();
ecs_entity_t plr = camera_get().ent_id;
Position const* origin = ecs_get(world_ecs(), plr, Position);
Position * dest = ecs_get_mut(world_ecs(), e, Position, NULL);
*dest = *origin;
debug_replay_special_action(RPKIND_SPAWN_CAR);
2021-08-09 17:30:39 +00:00
}
2021-08-10 15:21:25 +00:00
2021-08-25 21:36:20 +00:00
void
ActSpawnIcemaker(void) {
2021-08-30 16:14:35 +00:00
ecs_entity_t e = item_spawn(IKIND_DEMO_ICEMAKER, 32);
2021-08-25 21:36:20 +00:00
ecs_entity_t plr = camera_get().ent_id;
Position const* origin = ecs_get(world_ecs(), plr, Position);
Position * dest = ecs_get_mut(world_ecs(), e, Position, NULL);
*dest = *origin;
2021-09-08 10:04:35 +00:00
debug_replay_special_action(RPKIND_SPAWN_ICEMAKER_ITEM);
2021-08-25 21:36:20 +00:00
}
2021-08-15 16:32:11 +00:00
void
ActSpawnCirclingDriver(void) {
ecs_entity_t plr = camera_get().ent_id;
ecs_entity_t ve = vehicle_spawn();
ecs_entity_t e = entity_spawn(EKIND_DEMO_NPC);
Position const *origin = ecs_get(world_ecs(), plr, Position);
Position *veh_dest = ecs_get_mut(world_ecs(), ve, Position, NULL);
Position *dest = ecs_get_mut(world_ecs(), e, Position, NULL);
*veh_dest = *origin;
*dest = *origin;
Input *input = ecs_get_mut(world_ecs(), e, Input, NULL);
2021-08-29 15:56:58 +00:00
zpl_zero_item(input);
2021-08-15 16:32:11 +00:00
input->x = input->y = 1.0f;
Vehicle *veh = ecs_get_mut(world_ecs(), ve, Vehicle, NULL);
veh->seats[0] = e;
ecs_set(world_ecs(), e, IsInVehicle, { .veh = ve });
debug_replay_special_action(RPKIND_SPAWN_CIRCLING_DRIVER);
}
2021-08-11 19:51:15 +00:00
void
2021-08-11 10:22:46 +00:00
ActPlaceIceRink(void) {
ecs_entity_t plr = camera_get().ent_id;
uint8_t watr_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_WATER);
Position const *p = ecs_get(world_ecs(), plr, Position);
float const bs = WORLD_BLOCK_SIZE;
for (int y = 0; y < 100; y++) {
for (int x = 0; x < 100; x++) {
world_block_lookup l = world_block_from_realpos((p->x - (x*bs)/2.0f), p->y - (y*bs)/2.0f);
2021-08-30 16:14:35 +00:00
world_chunk_replace_block(l.chunk_id, l.id, watr_id);
2021-08-11 10:22:46 +00:00
}
}
debug_replay_special_action(RPKIND_PLACE_ICE_RINK);
}
2021-08-30 09:59:36 +00:00
void
ActEraseWorldChanges(void) {
ecs_entity_t plr = camera_get().ent_id;
Position const *p = ecs_get(world_ecs(), plr, Position);
float const bs = WORLD_BLOCK_SIZE;
for (int y = 0; y < 100; y++) {
for (int x = 0; x < 100; x++) {
world_block_lookup l = world_block_from_realpos((p->x - (x*bs)/2.0f), p->y - (y*bs)/2.0f);
2021-08-30 16:14:35 +00:00
world_chunk_place_block(l.chunk_id, l.id, 0);
2021-08-30 09:59:36 +00:00
}
}
debug_replay_special_action(RPKIND_PLACE_ERASE_CHANGES);
}
2021-08-10 15:21:25 +00:00
// NOTE(zaklaus): Replay system
2021-08-11 19:51:15 +00:00
uint8_t
2021-08-10 15:21:25 +00:00
CondReplayStatusOn(void) {
2021-08-10 23:06:12 +00:00
return is_recording && !is_playing;
2021-08-10 15:21:25 +00:00
}
2021-08-11 19:51:15 +00:00
uint8_t
2021-08-10 15:21:25 +00:00
CondReplayStatusOff(void) {
2021-08-10 23:06:12 +00:00
return !is_recording && !is_playing;
2021-08-10 15:21:25 +00:00
}
2021-08-11 19:51:15 +00:00
uint8_t
2021-08-10 23:06:12 +00:00
CondReplayDataPresentAndNotPlaying(void) {
return records != NULL && !is_recording && !is_playing;
}
2021-08-11 19:51:15 +00:00
uint8_t
2021-08-10 23:06:12 +00:00
CondReplayIsPlaying(void) {
return records != NULL && !is_recording && is_playing;
}
2021-08-11 19:51:15 +00:00
uint8_t
2021-08-10 23:06:12 +00:00
CondReplayIsNotPlaying(void) {
return !is_recording && !is_playing;
}
2021-08-11 19:51:15 +00:00
uint8_t
2021-08-10 23:06:12 +00:00
CondReplayIsNotPlayingOrRecordsNotClear(void) {
return records != NULL && !is_recording && !is_playing;
2021-08-10 15:21:25 +00:00
}
2021-08-11 19:51:15 +00:00
void
2021-08-10 15:21:25 +00:00
ActReplayBegin(void) {
debug_replay_start();
}
2021-08-11 19:51:15 +00:00
void
2021-08-10 15:21:25 +00:00
ActReplayEnd(void) {
debug_replay_stop();
}
2021-08-11 19:51:15 +00:00
void
2021-08-10 15:21:25 +00:00
ActReplayRun(void) {
debug_replay_run();
}
2021-08-11 19:51:15 +00:00
void
2021-08-10 15:21:25 +00:00
ActReplayClear(void) {
debug_replay_clear();
}
2021-08-11 19:51:15 +00:00
void
ActReplayNew(void) {
debug_replay_clear();
zpl_zero_size(replay_filename, sizeof(replay_filename));
}
2021-08-11 19:51:15 +00:00
void
ActReplaySaveAs(void) {
if (!records) return;
char const *workdir = GetWorkingDirectory();
sfd_Options sfd = {
.title = "Save Macro",
.path = "art",
.filter_name = "eco2d Macro",
.filter = "*.dem",
};
char const *path = sfd_save_dialog(&sfd);
ChangeDirectory(workdir);
if (path) {
zpl_strcpy(replay_filename, zpl_bprintf("%s.dem", path));
debug_replay_store();
}
}
2021-08-11 19:51:15 +00:00
void
ActReplaySave(void) {
if (!replay_filename[0]) {
ActReplaySaveAs();
}
else debug_replay_store();
}
2021-08-11 19:51:15 +00:00
void
ActReplayLoad(void) {
char const *workdir = GetWorkingDirectory();
sfd_Options sfd = {
.title = "Load Macro",
.path = "art",
.filter_name = "eco2d Macro",
.filter = "*.dem",
};
char const *path = sfd_open_dialog(&sfd);
ChangeDirectory(workdir);
if (path) {
2021-08-10 23:19:00 +00:00
zpl_zero_size(replay_filename, sizeof(replay_filename));
zpl_strcpy(replay_filename, path);
debug_replay_clear();
debug_replay_load();
}
}
2021-08-10 22:02:11 +00:00
// NOTE(zaklaus): Demo NPCs
static ecs_entity_t *demo_npcs = NULL;
2021-08-11 19:51:15 +00:00
void
2021-08-10 22:02:11 +00:00
ActSpawnDemoNPCs(void) {
if (!demo_npcs) zpl_array_init(demo_npcs, zpl_heap());
if (zpl_array_count(demo_npcs) >= 10000) return;
for (uint32_t i = 0; i < 1000; i++) {
uint64_t e = entity_spawn(EKIND_DEMO_NPC);
ecs_add(world_ecs(), e, EcsDemoNPC);
Position *pos = ecs_get_mut(world_ecs(), e, Position, NULL);
pos->x=rand() % world_dim();
pos->y=rand() % world_dim();
Velocity *v = ecs_get_mut(world_ecs(), e, Velocity, NULL);
2021-08-29 10:48:29 +00:00
v->x = (rand()%3-1) * 10;
v->y = (rand()%3-1) * 10;
2021-08-10 22:02:11 +00:00
zpl_array_append(demo_npcs, e);
}
}
2021-08-11 19:51:15 +00:00
void
2021-08-10 22:02:11 +00:00
ActDespawnDemoNPCs(void) {
if (!demo_npcs) return;
for (uint32_t i = 0; i < zpl_array_count(demo_npcs); i++) {
entity_despawn(demo_npcs[i]);
}
zpl_array_free(demo_npcs);
demo_npcs = 0;
}