diff options
| author | ilotterytea <iltsu@alright.party> | 2025-01-28 02:13:38 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-01-28 02:13:38 +0500 |
| commit | 352cc47d315d262b0114399029fc66f1c65f90f8 (patch) | |
| tree | 8b06a42b6f043ef85aceeb6b7bf4e4d3e4e8599a | |
| parent | 5f78a97620329b1b2859fe737ddc3a3ad92d3ee5 (diff) | |
upd/fix: EditorState wasn't free + wall creation + default values for state
| -rw-r--r-- | src/editor.c | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/src/editor.c b/src/editor.c index 0f637b5..65476a1 100644 --- a/src/editor.c +++ b/src/editor.c @@ -77,12 +77,12 @@ void SE_DrawEditor(Editor *editor, Camera2D *camera) { for (int ti = 0; ti < layer->tilesCount; ti++) { EditorTile *t = layer->tiles[ti]; - if (t == NULL) continue; + if (t == NULL) continue; - Rectangle s = {0, 0, 16, 16}; - Rectangle d = {t->position.x * zoom, t->position.y * zoom, zoom, zoom}; + Rectangle s = {0, 0, 16, 16}; + Rectangle d = {t->position.x * zoom, t->position.y * zoom, zoom, zoom}; - DrawTexturePro(t->tile->texture, s, d, (Vector2){0, 0}, 0.0f, WHITE); + DrawTexturePro(t->tile->texture, s, d, (Vector2){0, 0}, 0.0f, WHITE); } } @@ -240,6 +240,9 @@ void drawBuildTab(Editor *editor, int x, int y, int width, int height, editor->state.createBlockState == NULL) { SE_LOG_INFO("Creating a new block"); EditorCreateBlockState *state = malloc(sizeof(EditorCreateBlockState)); + state->isFloor = true; + state->isWall = false; + state->upFilePath = NULL; editor->state.createBlockState = state; } } @@ -407,24 +410,31 @@ void drawCreatingNewBlock(Editor *editor) { if (createButton) { close = true; - if (state->isFloor) { - int id = editor->state.cache.tileDataSize; + int id = editor->state.cache.tileDataSize; - EditorTileData *tile = malloc(sizeof(EditorTileData)); - editor->state.cache.tileData[id] = tile; + EditorTileData *tile = malloc(sizeof(EditorTileData)); + editor->state.cache.tileData[id] = tile; - tile->data = (XdTileData){}; - tile->data.id = id; - tile->data.type = TILE_FLOOR; + tile->data = (XdTileData){}; + tile->data.id = id; + tile->data.type = state->isFloor ? TILE_FLOOR : TILE_WALL; - tile->texture = state->upTexture; + tile->texture = state->upTexture; - editor->state.cache.tileDataSize++; - } + editor->state.cache.tileDataSize++; } if (close) { - // free(state); + if (state->upFilePath != NULL) { + free(state->upFilePath); + state->upFilePath = NULL; + + if (!createButton) { + UnloadTexture(state->upTexture); + } + } + + free(state); editor->state.createBlockState = NULL; } } |
