summaryrefslogtreecommitdiff
path: root/src/main.c
blob: 8ce056b1e0a756a0b1d5e6c6e03d83ad69a255c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>

#include "editor.h"
#include "logger.h"
#include "raylib.h"
#include "xd.h"

int main() {
  SetTraceLogCallback(SE_Logger);

  SetConfigFlags(FLAG_WINDOW_RESIZABLE);
  InitWindow(800, 600, "sillyeditor");
  SetTargetFPS(60);

  // Getting list of files
  XdData* datas[] = {};
  FilePathList list = LoadDirectoryFilesEx("datas", ".xd", true);

  for (int i = 0; i < list.count; i++) {
    XdData data = Xd_LoadFromFile(list.paths[i]);
    printf("%s\n", data.name);
    datas[i] = &data;
  }

  UnloadDirectoryFiles(list);

  XdData* data = NULL;
  Editor editor = {data, {0, 0, 0, NULL, {0, 0, 0, 0}, {0, 0}, NULL, {}}};

  // creating a new xd data
  data = malloc(sizeof(XdData));
  editor.data = data;
  data->name = "xd";
  data->levels[0] = malloc(sizeof(XdLevel));
  data->levels[0]->floors[0] = malloc(sizeof(XdFloor));
  data->levels[0]->floors[0]->width = 30;
  data->levels[0]->floors[0]->height = 30;

  Camera2D camera = {0};
  camera.target = (Vector2){0.0f, 0.0f};
  camera.offset = (Vector2){0.0f, 0.0f};
  camera.rotation = 0.0f;
  camera.zoom = 4.0f;

  while (!WindowShouldClose()) {
    // interact with the map if the mouse is outside build tab
    if (GetMousePosition().x < EDITOR_TOOLKIT_X) {
      if (GetMouseWheelMove() != 0.0) {
        camera.zoom += (int)GetMouseWheelMove();

        if (camera.zoom > 6.0f)
          camera.zoom = 6.0f;
        else if (camera.zoom < 4.0f)
          camera.zoom = 4.0f;
      }

      if (IsMouseButtonDown(MOUSE_BUTTON_MIDDLE)) {
        Vector2 mousePos = GetMouseDelta();
        camera.target.x -= mousePos.x / 5.0f;
        camera.target.y -= mousePos.y / 5.0f;
      }
    }

    BeginDrawing();
    ClearBackground(RAYWHITE);

    BeginMode2D(camera);
    SE_DrawEditor(&editor, &camera);
    EndMode2D();

    SE_DrawEditorToolkit(&editor);

    EndDrawing();
  }

  return 0;
}