diff options
| -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; } } |
