summaryrefslogtreecommitdiff
path: root/src/editor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/editor.c')
-rw-r--r--src/editor.c52
1 files changed, 44 insertions, 8 deletions
diff --git a/src/editor.c b/src/editor.c
index 118b1f9..0bb31b2 100644
--- a/src/editor.c
+++ b/src/editor.c
@@ -1,6 +1,7 @@
#include "editor.h"
#include <stdbool.h>
+#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@@ -30,12 +31,49 @@ void SE_DrawEditor(Editor *editor, Camera2D *camera) {
(ry < mousePos.y && mousePos.y < ry + zoom)) {
innerColor = SKYBLUE;
borderColor = BLUE;
+
+ // placing tiles
+ if (IsMouseButtonDown(MOUSE_BUTTON_LEFT) &&
+ editor->state.selectedTile != NULL) {
+ EditorTile *t = NULL;
+ // checking for existing tiles on the position
+ for (int i = 0; i < editor->state.cache.tilesCount; i++) {
+ EditorTile *tt = editor->state.cache.tiles[i];
+
+ if (tt == NULL) continue;
+
+ if (tt->position.x == x && tt->position.y == y) {
+ t = tt;
+ break;
+ }
+ }
+
+ if (t == NULL) {
+ t = malloc(sizeof(EditorTile));
+ t->position = (Vector2){x, y};
+ editor->state.cache.tiles[editor->state.cache.tilesCount] = t;
+ editor->state.cache.tilesCount++;
+ }
+
+ t->tile = editor->state.selectedTile;
+ }
}
DrawRectangle(rx, ry, zoom, zoom, innerColor);
DrawRectangleLines(rx, ry, zoom, zoom, borderColor);
}
}
+
+ // rendering placed tiles
+ for (int i = 0; i < editor->state.cache.tilesCount; i++) {
+ EditorTile *t = editor->state.cache.tiles[i];
+ if (t == NULL) continue;
+
+ 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);
+ }
}
void drawBuildTab(Editor *editor, int x, int y, int width, int height) {
@@ -83,10 +121,8 @@ void drawBuildTab(Editor *editor, int x, int y, int width, int height) {
// rendering floor tiles in grid
int row = 0, column = 0, texturesPerRow = 10;
- for (int i = 0; i < sizeof(editor->state.cache.tiles) /
- sizeof(editor->state.cache.tiles[0]);
- i++) {
- EditorTile *tile = editor->state.cache.tiles[i];
+ for (int i = 0; i < editor->state.cache.tileDataSize; i++) {
+ EditorTileData *tile = editor->state.cache.tileData[i];
if (tile == NULL) continue;
row = i / texturesPerRow;
@@ -308,10 +344,10 @@ void drawCreatingNewBlock(Editor *editor) {
close = true;
if (state->isFloor) {
- int id = editor->state.cache.tileCacheSize;
+ int id = editor->state.cache.tileDataSize;
- EditorTile *tile = malloc(sizeof(EditorTile));
- editor->state.cache.tiles[id] = tile;
+ EditorTileData *tile = malloc(sizeof(EditorTileData));
+ editor->state.cache.tileData[id] = tile;
tile->data = (XdTileData){};
tile->data.id = id;
@@ -319,7 +355,7 @@ void drawCreatingNewBlock(Editor *editor) {
tile->texture = state->upTexture;
- editor->state.cache.tileCacheSize++;
+ editor->state.cache.tileDataSize++;
}
}