Mercurial > molko
comparison src/libmlk-rpg/rpg/property.c @ 328:60a4f904da21
rpg: separate property from save
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 04 Oct 2021 13:10:11 +0200 |
parents | |
children | ea4a3af71c18 |
comparison
equal
deleted
inserted
replaced
327:42a6710629f5 | 328:60a4f904da21 |
---|---|
1 /* | |
2 * property.c -- manage game properties | |
3 * | |
4 * Copyright (c) 2020-2021 David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #include <assert.h> | |
20 | |
21 #include <assets/sql/property-save.h> | |
22 #include <assets/sql/property-remove.h> | |
23 #include <assets/sql/property-load.h> | |
24 | |
25 #include "property.h" | |
26 #include "save.h" | |
27 | |
28 int | |
29 property_save(const struct property *p, struct save *s) | |
30 { | |
31 assert(p); | |
32 assert(save_ok(s)); | |
33 | |
34 return save_exec(s, (const char *)assets_sql_property_save, "ss", p->key, p->value); | |
35 } | |
36 | |
37 int | |
38 property_load(struct property *p, struct save *s) | |
39 { | |
40 assert(p); | |
41 assert(save_ok(s)); | |
42 | |
43 struct save_stmt stmt; | |
44 int ret; | |
45 | |
46 if (save_stmt_init(s, &stmt, (const char *)assets_sql_property_load, "s", p->key) < 0) | |
47 return -1; | |
48 | |
49 switch (save_stmt_next(&stmt, "s", p->value, sizeof (p->value))) { | |
50 case SAVE_STMT_DONE: | |
51 case SAVE_STMT_ERROR: | |
52 ret = -1; | |
53 break; | |
54 default: | |
55 ret = 0; | |
56 } | |
57 | |
58 save_stmt_finish(&stmt); | |
59 | |
60 return ret; | |
61 } | |
62 | |
63 int | |
64 property_remove(struct property *p, struct save *s) | |
65 { | |
66 assert(p); | |
67 assert(save_ok(s)); | |
68 | |
69 return save_exec(s, (const char *)assets_sql_property_remove, "s", p->key); | |
70 } | |
71 |