summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/xd.c38
-rw-r--r--src/xd.h59
2 files changed, 97 insertions, 0 deletions
diff --git a/src/xd.c b/src/xd.c
new file mode 100644
index 0000000..5e9644e
--- /dev/null
+++ b/src/xd.c
@@ -0,0 +1,38 @@
+#include "xd.h"
+
+#include <raylib.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+XdData *Xd_LoadFromFile(const char *filePath) {
+ FILE *file = fopen(filePath, "rb");
+
+ if (file == NULL) {
+ return NULL;
+ }
+
+ XdData *data = malloc(sizeof(XdData));
+ fread(data, sizeof(XdData), 1, file);
+
+ fclose(file);
+ return data;
+}
+
+void Xd_SaveFile(const char *filePath, XdData *data) {
+ if (data == NULL) {
+ printf("data is null\n");
+ return;
+ }
+
+ FILE *file = fopen(filePath, "wb");
+
+ if (file == NULL) {
+ perror("Failed to open a file");
+ return;
+ }
+
+ fwrite(data, sizeof(XdData), 1, file);
+
+ fclose(file);
+ printf("saved\n");
+}
diff --git a/src/xd.h b/src/xd.h
new file mode 100644
index 0000000..5ecd465
--- /dev/null
+++ b/src/xd.h
@@ -0,0 +1,59 @@
+#ifndef __XD_H__
+#define __XD_H__
+
+#define XD_VERSION 1
+#define XD_MAX_ENTITIES 256
+#define XD_MAX_TEXTURES 256
+
+typedef enum { PLAYER_START = 0, NEXT_FLOOR, PREVIOUS_FLOOR } XdEntityType;
+
+typedef struct {
+ int id;
+ char *type;
+ unsigned char *data;
+} XdTexture;
+
+typedef struct {
+ int x, y;
+ XdTexture *texture;
+} XdMapTile;
+
+typedef struct {
+ int id;
+ XdTexture *texture;
+ XdEntityType type;
+} XdEntity;
+
+typedef struct {
+ int x, y;
+ XdEntity *entity;
+} XdMapEntity;
+
+typedef struct {
+ int zIndex;
+ XdMapEntity *entities[XD_MAX_ENTITIES];
+ XdMapTile *tiles[];
+} XdMapLayer;
+
+typedef struct {
+ int width, height;
+ XdMapLayer *layers[];
+} XdFloor;
+
+typedef struct {
+ int id;
+ XdFloor *floors[];
+} XdLevel;
+
+typedef struct {
+ char *name;
+ int version;
+ XdTexture textures[XD_MAX_TEXTURES];
+ XdEntity *entities[XD_MAX_ENTITIES];
+ XdLevel *levels[];
+} XdData;
+
+XdData *Xd_LoadFromFile(const char *filePath);
+void Xd_SaveFile(const char *filePath, XdData *xd);
+
+#endif