4 #include "ebisp/interpreter.h"
5 #include "ebisp/scope.h"
6 #include "game/level/player/rigid_rect.h"
8 #include "level_script.h"
9 #include "system/log.h"
11 static struct EvalResult
12 hide_goal(void *param, Gc *gc, struct Scope *scope, struct Expr args)
18 Level * const level = (Level*)param;
19 const char * const goal_id = NULL;
21 struct EvalResult result = match_list(gc, "s", args, &goal_id);
22 if (result.is_error) {
26 level_hide_goal(level, goal_id);
28 return eval_success(NIL(gc));
31 static struct EvalResult
32 show_goal(void *param, Gc *gc, struct Scope *scope, struct Expr args)
38 Level * const level = (Level*)param;
39 const char *goal_id = NULL;
41 struct EvalResult result = match_list(gc, "s", args, &goal_id);
42 if (result.is_error) {
46 level_show_goal(level, goal_id);
48 return eval_success(NIL(gc));
51 static struct EvalResult
52 rect_apply_force(void *param, Gc *gc, struct Scope *scope, struct Expr args)
58 /* TODO(#401): rect_apply_force doesn't sanitize it's input */
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;
66 print_expr_as_sexpr(stdout, args); printf("\n");
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));
74 log_fail("Couldn't find rigid_rect `%s`\n", rect_id);
77 return eval_success(NIL(gc));
80 static struct EvalResult
81 hide_label(void *param, Gc *gc, struct Scope *scope, struct Expr args)
87 Level *level = (Level*) param;
88 const char *label_id = NULL;
90 struct EvalResult result = match_list(gc, "s", args, &label_id);
91 if (result.is_error) {
95 level_hide_label(level, label_id);
97 return eval_success(NIL(gc));
100 static struct EvalResult
101 show_label(void *param, Gc *gc, struct Scope *scope, struct Expr args)
108 /* TODO(#523): show-label is not implemented */
110 return not_implemented(gc);
113 void load_level_library(Gc *gc, struct Scope *scope, Level *level)
118 SYMBOL(gc, "rect-apply-force"),
119 NATIVE(gc, rect_apply_force, level));
123 SYMBOL(gc, "hide-goal"),
124 NATIVE(gc, hide_goal, level));
128 SYMBOL(gc, "show-goal"),
129 NATIVE(gc, show_goal, level));
133 SYMBOL(gc, "show-label"),
134 NATIVE(gc, show_label, level));
138 SYMBOL(gc, "hide-label"),
139 NATIVE(gc, hide_label, level));