Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
* Filename: /home/thomas/Documents/Perso/our_rpg/sources/Resource/resource_scene_filename.c |
3 |
|
|
* Path: /home/thomas/Documents/Perso/our_rpg/sources/Resource |
4 |
|
|
* Created Date: Tuesday, March 21st 2023, 9:45:13 am |
5 |
|
|
* Author: Thomas |
6 |
|
|
* |
7 |
|
|
* Copyright (c) 2023 our_rpg |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
#include "resources.h" |
11 |
|
|
#include <stdlib.h> |
12 |
|
|
#include <string.h> |
13 |
|
|
#include "json.h" |
14 |
|
|
#include "world_logger.h" |
15 |
|
|
|
16 |
|
|
/// @brief Check if the resource is a R_SCENE_FILENAME or not. |
17 |
|
|
/// @param resource The resource to be checked. |
18 |
|
|
/// @return 1 if the resource is a R_SCENE_FILENAME, or 0 otherwise. |
19 |
|
|
/// @note This is a static function. |
20 |
|
|
static int resource_is_scene_filename(const resource_t *resource) |
21 |
|
|
{ |
22 |
|
✗ |
if (resource->type == R_SCENE_FILENAME) |
23 |
|
|
return 1; |
24 |
|
✗ |
log_error("Resource is not scene filename."); |
25 |
|
|
return 0; |
26 |
|
|
} |
27 |
|
|
|
28 |
|
✗ |
int resource_scene_filename_constructor(resource_t *resource, void *data) |
29 |
|
|
{ |
30 |
|
|
int rvalue = 0; |
31 |
|
|
|
32 |
|
✗ |
resource->type = R_SCENE_FILENAME; |
33 |
|
✗ |
resource->data = 0; |
34 |
|
✗ |
resource->destructor = &resource_scene_filename_destructor; |
35 |
|
✗ |
rvalue = resource_scene_filename_set(resource, data); |
36 |
|
✗ |
log_info("Scene filename resource created."); |
37 |
|
✗ |
return rvalue; |
38 |
|
|
} |
39 |
|
|
|
40 |
|
✗ |
int resource_scene_filename_constructor_from_json(resource_t *resource, void *data) |
41 |
|
|
{ |
42 |
|
|
void *new_data = 0; |
43 |
|
|
|
44 |
|
✗ |
return resource_scene_filename_constructor(resource, new_data); |
45 |
|
|
} |
46 |
|
|
|
47 |
|
✗ |
int resource_scene_filename_destructor(resource_t *resource) |
48 |
|
|
{ |
49 |
|
✗ |
if (resource->data) |
50 |
|
✗ |
free(resource->data); |
51 |
|
✗ |
log_info("Scene filename resource destroyed."); |
52 |
|
✗ |
return 0; |
53 |
|
|
} |
54 |
|
|
|
55 |
|
✗ |
int resource_scene_filename_set(resource_t *resource, void *data) |
56 |
|
|
{ |
57 |
|
✗ |
if (!resource_is_scene_filename(resource) || !data) |
58 |
|
✗ |
return -1; |
59 |
|
✗ |
if (resource->data) { |
60 |
|
✗ |
if (!strcmp((char *)resource->data, (char *)data)) { |
61 |
|
✗ |
free(resource->data); |
62 |
|
✗ |
resource->data = strdup((char *)data); |
63 |
|
|
} |
64 |
|
|
} else { |
65 |
|
✗ |
resource->data = strdup((char *)data); |
66 |
|
|
} |
67 |
|
|
return 0; |
68 |
|
|
} |
69 |
|
|
|
70 |
|
✗ |
void *resource_scene_filename_get(const resource_t *resource) |
71 |
|
|
{ |
72 |
|
|
if (!resource_is_scene_filename(resource)) |
73 |
|
✗ |
return 0; |
74 |
|
✗ |
return resource->data; |
75 |
|
|
} |
76 |
|
|
|