Mercurial > molko
comparison libmlk-rpg/mlk/rpg/battle-state-menu.c @ 434:4e78f045e8c0
rpg: cleanup hierarchy
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sat, 15 Oct 2022 21:24:17 +0200 |
parents | src/libmlk-rpg/rpg/battle-state-menu.c@8f59201dc76b |
children | 9c3b3935f0aa |
comparison
equal
deleted
inserted
replaced
433:862b15c3a3ae | 434:4e78f045e8c0 |
---|---|
1 /* | |
2 * battle-state-menu.h -- battle state (menu) | |
3 * | |
4 * Copyright (c) 2020-2022 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 #include <stdlib.h> | |
21 | |
22 #include <mlk/core/alloc.h> | |
23 | |
24 #include "battle-bar.h" | |
25 #include "battle-state-menu.h" | |
26 #include "battle-state.h" | |
27 #include "battle.h" | |
28 | |
29 static void | |
30 handle(struct battle_state *st, struct battle *bt, const union event *ev) | |
31 { | |
32 (void)st; | |
33 | |
34 battle_state_menu_handle(bt, ev); | |
35 } | |
36 | |
37 static int | |
38 update(struct battle_state *st, struct battle *bt, unsigned int ticks) | |
39 { | |
40 (void)st; | |
41 | |
42 battle_state_menu_update(bt, ticks); | |
43 | |
44 return 0; | |
45 } | |
46 | |
47 static void | |
48 draw(const struct battle_state *st, const struct battle *bt) | |
49 { | |
50 (void)st; | |
51 | |
52 battle_state_menu_draw(bt); | |
53 } | |
54 | |
55 static void | |
56 finish(struct battle_state *st, struct battle *bt) | |
57 { | |
58 (void)bt; | |
59 | |
60 free(st); | |
61 } | |
62 | |
63 void | |
64 battle_state_menu_handle(struct battle *bt, const union event *ev) | |
65 { | |
66 assert(bt); | |
67 assert(ev); | |
68 | |
69 battle_bar_handle(bt->bar, bt, ev); | |
70 } | |
71 | |
72 void | |
73 battle_state_menu_update(struct battle *bt, unsigned int ticks) | |
74 { | |
75 assert(battle_ok(bt)); | |
76 | |
77 battle_update_component(bt, ticks, BATTLE_COMPONENT_ALL); | |
78 } | |
79 | |
80 void | |
81 battle_state_menu_draw(const struct battle *bt) | |
82 { | |
83 assert(battle_ok(bt)); | |
84 | |
85 battle_draw_component(bt, BATTLE_COMPONENT_ALL); | |
86 } | |
87 | |
88 void | |
89 battle_state_menu(struct battle *bt) | |
90 { | |
91 assert(bt); | |
92 | |
93 struct battle_state *state; | |
94 | |
95 state = alloc_new0(sizeof (*state)); | |
96 state->data = bt; | |
97 state->handle = handle; | |
98 state->update = update; | |
99 state->draw = draw; | |
100 state->finish = finish; | |
101 | |
102 battle_bar_start(bt->bar, bt); | |
103 battle_switch(bt, state); | |
104 } |