summaryrefslogtreecommitdiff
path: root/src/puzzles
diff options
context:
space:
mode:
Diffstat (limited to 'src/puzzles')
-rw-r--r--src/puzzles/collection.c14
-rw-r--r--src/puzzles/puzzle.h15
2 files changed, 26 insertions, 3 deletions
diff --git a/src/puzzles/collection.c b/src/puzzles/collection.c
index 71eaadf..ca2743c 100644
--- a/src/puzzles/collection.c
+++ b/src/puzzles/collection.c
@@ -151,7 +151,7 @@ void InitializeCollection(CollectionElement *el, void (*callback)(CollectionElem
initCollectionFromDir(el, callback);
break;
default:
- TraceLog(LOG_WARNING, "Invalid CollectionElement type");
+ TraceLog(LOG_WARNING, "Invalid CollectionElement type for %s", el->path);
break;
}
}
@@ -191,3 +191,15 @@ void UpdateCollectionElement(CollectionElement *el) {
}
}
}
+
+void DeinitCollectionElement(CollectionElement *el) {
+ if (el == NULL || !el->IsInitialized) return;
+ if (el->path != NULL) free(el->path);
+ if (el->name != NULL) free(el->name);
+ if (el->hasIcon) UnloadTexture(el->icon);
+
+ for (size_t i = 0; i < el->childCount; ++i) {
+ DeinitCollectionElement(&el->children[i]);
+ }
+ free(el);
+}
diff --git a/src/puzzles/puzzle.h b/src/puzzles/puzzle.h
index 21d8944..5af6d6e 100644
--- a/src/puzzles/puzzle.h
+++ b/src/puzzles/puzzle.h
@@ -100,17 +100,27 @@ typedef enum {
} CollectionElementType;
+/// A collection node. Corresponds to either a directory in the FS or a .pz file
typedef struct CollectionElement {
+ /// The icon used for the puzzles in the collection
Texture2D icon;
+ /// Used in the click detection. Do not modify from user space
Rectangle _previousFramePosition;
+ /// The path to the directory/puzzle
char *path;
+ /// The display name of an element
char *name;
+ /// The tree child nodes array
struct CollectionElement *children;
- void (*callback)(struct CollectionElement *);
+ /// The tree child nodes count
size_t childCount;
+ /// OnClick callback
+ void (*callback)(struct CollectionElement *);
+ /// If the element is initialized it has children and an icon loaded into mem
bool IsInitialized;
+ /// The element has an icon
bool hasIcon;
- bool isPressed;
+ /// The type of the element
CollectionElementType type;
} CollectionElement;
@@ -120,5 +130,6 @@ typedef struct CollectionElement {
void InitializeCollection(CollectionElement *el, void (*callback)(CollectionElement *));
void DrawCollectionElement(CollectionElement *el, CollectionElement *parent, Rectangle rec);
void UpdateCollectionElement(CollectionElement *el);
+void DeinitCollectionElement(CollectionElement *el);
#endif // PUZZLE_H