aboutsummaryrefslogtreecommitdiff
path: root/plugins/inventory
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2021-06-13 20:41:17 +0200
committerElias Fleckenstein <eliasfleckenstein@web.de>2021-06-13 20:41:17 +0200
commitbfcda608695b83ce6a3caefceaa79c8e392405d7 (patch)
treedbd4dcaebbc8157d536553ad03d7afb64031a34b /plugins/inventory
parent67dc975a29da3abed0834f0fefbeb7c905c16316 (diff)
downloaddungeon_game-bfcda608695b83ce6a3caefceaa79c8e392405d7.tar.xz
Add on_create callback for items
Diffstat (limited to 'plugins/inventory')
-rw-r--r--plugins/inventory/inventory.c9
-rw-r--r--plugins/inventory/inventory.h1
2 files changed, 9 insertions, 1 deletions
diff --git a/plugins/inventory/inventory.c b/plugins/inventory/inventory.c
index c3b533d..9923561 100644
--- a/plugins/inventory/inventory.c
+++ b/plugins/inventory/inventory.c
@@ -29,7 +29,11 @@ void inventory_add(struct inventory *self, struct itemstack stack)
}
}
- *ptr = add_element(*ptr, make_buffer(&stack, sizeof(struct itemstack)));
+ struct itemstack *buf = make_buffer(&stack, sizeof(struct itemstack));
+ *ptr = add_element(*ptr, buf);
+
+ if (buf->item->on_create)
+ buf->item->on_create(buf);
}
/*
@@ -81,6 +85,9 @@ static void decrease_item_count(struct list **ptr, struct itemstack *stack)
if (stack->item->on_destroy)
stack->item->on_destroy(stack);
+ if (stack->meta)
+ free(stack->meta);
+
free(stack);
free(*ptr);
diff --git a/plugins/inventory/inventory.h b/plugins/inventory/inventory.h
index 4b13f94..437ffb6 100644
--- a/plugins/inventory/inventory.h
+++ b/plugins/inventory/inventory.h
@@ -16,6 +16,7 @@ struct item
bool (*on_use)(struct itemstack *stack);
void (*on_destroy)(struct itemstack *stack);
+ void (*on_create)(struct itemstack *stack);
};
struct inventory