]> git.lizzy.rs Git - nothing.git/blob - src/game/level_script.c
(#525) Make level_script functions static
[nothing.git] / src / game / level_script.c
1 #include <assert.h>
2
3 #include "ebisp/gc.h"
4 #include "ebisp/interpreter.h"
5 #include "ebisp/scope.h"
6 #include "game/level/player/rigid_rect.h"
7 #include "level.h"
8 #include "level_script.h"
9 #include "system/log.h"
10
11 static struct EvalResult
12 hide_goal(void *param, Gc *gc, struct Scope *scope, struct Expr args)
13 {
14     assert(param);
15     assert(gc);
16     assert(scope);
17
18     Level * const level = (Level*)param;
19     const char * const goal_id = NULL;
20
21     struct EvalResult result = unpack_args(gc, "s", args, &goal_id);
22     if (result.is_error) {
23         return result;
24     }
25
26     level_hide_goal(level, goal_id);
27
28     return eval_success(NIL(gc));
29 }
30
31 static struct EvalResult
32 show_goal(void *param, Gc *gc, struct Scope *scope, struct Expr args)
33 {
34     assert(param);
35     assert(gc);
36     assert(scope);
37
38     Level * const level = (Level*)param;
39     const char *goal_id = NULL;
40
41     struct EvalResult result = unpack_args(gc, "s", args, &goal_id);
42     if (result.is_error) {
43         return result;
44     }
45
46     level_show_goal(level, goal_id);
47
48     return eval_success(NIL(gc));
49 }
50
51 static struct EvalResult
52 rect_apply_force(void *param, Gc *gc, struct Scope *scope, struct Expr args)
53 {
54     assert(gc);
55     assert(scope);
56     assert(param);
57
58     /* TODO(#401): rect_apply_force doesn't sanitize it's input */
59
60     Level *level = (Level*) param;
61     const char *rect_id = CAR(args).atom->str;
62     struct Expr vector_force_expr = CAR(CDR(args));
63     const float force_x = (float) CAR(vector_force_expr).atom->num;
64     const float force_y = (float) CDR(vector_force_expr).atom->num;
65
66     print_expr_as_sexpr(stdout, args); printf("\n");
67
68     Rigid_rect *rigid_rect = level_rigid_rect(level, rect_id);
69     if (rigid_rect != NULL) {
70         log_info("Found rect `%s`\n", rect_id);
71         log_info("Applying force (%f, %f)\n", force_x, force_y);
72         rigid_rect_apply_force(rigid_rect, vec(force_x, force_y));
73     } else {
74         log_fail("Couldn't find rigid_rect `%s`\n", rect_id);
75     }
76
77     return eval_success(NIL(gc));
78 }
79
80 static struct EvalResult
81 hide_label(void *param, Gc *gc, struct Scope *scope, struct Expr args)
82 {
83     assert(param);
84     assert(gc);
85     assert(scope);
86     (void) args;
87
88     /* TODO(#522): hide-label is not implemented */
89
90     return not_implemented(gc);
91 }
92
93 static struct EvalResult
94 show_label(void *param, Gc *gc, struct Scope *scope, struct Expr args)
95 {
96     assert(param);
97     assert(gc);
98     assert(scope);
99     (void) args;
100
101     /* TODO(#523): show-label is not implemented */
102
103     return not_implemented(gc);
104 }
105
106 static struct EvalResult
107 get_player_jump_count(void *param, Gc *gc, struct Scope *scope, struct Expr args)
108 {
109     assert(param);
110     assert(gc);
111     assert(scope);
112     (void) args;
113
114     /* TODO(#524): get-player-jump-count is not implemented */
115
116     return not_implemented(gc);
117 }
118
119 void load_level_library(Gc *gc, struct Scope *scope, Level *level)
120 {
121     set_scope_value(
122         gc,
123         scope,
124         SYMBOL(gc, "rect-apply-force"),
125         NATIVE(gc, rect_apply_force, level));
126     set_scope_value(
127         gc,
128         scope,
129         SYMBOL(gc, "hide-goal"),
130         NATIVE(gc, hide_goal, level));
131     set_scope_value(
132         gc,
133         scope,
134         SYMBOL(gc, "show-goal"),
135         NATIVE(gc, show_goal, level));
136     set_scope_value(
137         gc,
138         scope,
139         SYMBOL(gc, "show-label"),
140         NATIVE(gc, show_label, level));
141     set_scope_value(
142         gc,
143         scope,
144         SYMBOL(gc, "hide-label"),
145         NATIVE(gc, hide_label, level));
146     set_scope_value(
147         gc,
148         scope,
149         SYMBOL(gc, "get-player-jump-count"),
150         NATIVE(gc, get_player_jump_count, level));
151 }