Upgrade level editor for moon campaign support
Preserve tileset path and parallax style on save instead of hardcoding tileset.png. Add tileset cycling (T key), tile flag editing (F key for solid/platform/hazard/none), and 8x8 pixel mini-icons for all entity types in the palette and canvas. Fix entity palette not appearing when editor starts without a prior level load by splitting entity_registry_init into populate and init phases. Fix bitmap font rendering dropping the top row by correcting FONT_H from 6 to 7. Widen toolbar button spacing. Fix invisible collision from placed tiles lacking TileDefs by calling ensure_tile_def on pencil and fill placement. Fix editor hotkeys not working in the web build by latching key presses from SDL_KEYDOWN events instead of comparing keyboard state snapshots.
This commit is contained in:
@@ -24,7 +24,6 @@ static int s_mouse_scroll;
|
||||
|
||||
/* ── Raw keyboard state ───────────────────────────── */
|
||||
static const Uint8 *s_key_state = NULL;
|
||||
static Uint8 s_prev_keys[SDL_NUM_SCANCODES];
|
||||
static Uint8 s_latched_keys[SDL_NUM_SCANCODES];
|
||||
|
||||
/* Default key bindings (primary + alternate) */
|
||||
@@ -53,7 +52,7 @@ void input_init(void) {
|
||||
memset(s_mouse_previous, 0, sizeof(s_mouse_previous));
|
||||
memset(s_mouse_latched_pressed, 0, sizeof(s_mouse_latched_pressed));
|
||||
memset(s_mouse_latched_released, 0, sizeof(s_mouse_latched_released));
|
||||
memset(s_prev_keys, 0, sizeof(s_prev_keys));
|
||||
|
||||
memset(s_latched_keys, 0, sizeof(s_latched_keys));
|
||||
s_mouse_x = s_mouse_y = 0;
|
||||
s_mouse_scroll = 0;
|
||||
@@ -67,11 +66,6 @@ void input_poll(void) {
|
||||
s_quit_requested = false;
|
||||
s_mouse_scroll = 0;
|
||||
|
||||
/* Save previous raw key state */
|
||||
if (s_key_state) {
|
||||
memcpy(s_prev_keys, s_key_state, SDL_NUM_SCANCODES);
|
||||
}
|
||||
|
||||
/* Process SDL events */
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
@@ -82,6 +76,16 @@ void input_poll(void) {
|
||||
case SDL_MOUSEWHEEL:
|
||||
s_mouse_scroll += event.wheel.y;
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
/* Latch raw key press directly from the event.
|
||||
* More reliable than state-snapshot comparison,
|
||||
* especially on Emscripten where SDL_GetKeyboardState
|
||||
* may not reflect keys pressed within the same frame. */
|
||||
if (!event.key.repeat &&
|
||||
event.key.keysym.scancode < SDL_NUM_SCANCODES) {
|
||||
s_latched_keys[event.key.keysym.scancode] = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,15 +106,6 @@ void input_poll(void) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Latch raw key edges */
|
||||
if (s_key_state) {
|
||||
for (int i = 0; i < SDL_NUM_SCANCODES; i++) {
|
||||
if (s_key_state[i] && !s_prev_keys[i]) {
|
||||
s_latched_keys[i] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Read mouse state */
|
||||
Uint32 buttons = SDL_GetMouseState(&s_mouse_x, &s_mouse_y);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user