comparison src/libmlk-rpg/rpg/battle-state-menu.c @ 382:43d155668a55

rpg: expose battle state functions
author David Demelier <markand@malikania.fr>
date Sun, 13 Feb 2022 10:35:26 +0100
parents 460c78706989
children c458441ff472
comparison
equal deleted inserted replaced
381:f48367c5a92e 382:43d155668a55
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */ 17 */
18 18
19 #include <assert.h> 19 #include <assert.h>
20 #include <stdlib.h>
21
22 #include <core/alloc.h>
20 23
21 #include "battle.h" 24 #include "battle.h"
22 #include "battle-bar.h" 25 #include "battle-bar.h"
23 #include "battle-state.h" 26 #include "battle-state.h"
27 #include "battle-state-menu.h"
28 #include "battle-state-selection.h"
29 #include "battle-state-sub.h"
24 #include "character.h" 30 #include "character.h"
25 #include "spell.h" 31 #include "spell.h"
26 32
27 static void 33 static void
28 open_spells(struct battle *bt) 34 open_spells(struct battle *bt)
52 static void 58 static void
53 handle(struct battle_state *st, struct battle *bt, const union event *ev) 59 handle(struct battle_state *st, struct battle *bt, const union event *ev)
54 { 60 {
55 (void)st; 61 (void)st;
56 62
63 battle_state_menu_handle(bt, ev);
64 }
65
66 static void
67 finish(struct battle_state *st, struct battle *bt)
68 {
69 (void)bt;
70
71 free(st);
72 }
73
74 void
75 battle_state_menu_handle(struct battle *bt, const union event *ev)
76 {
77 assert(bt);
78
57 if (battle_bar_handle(&bt->bar, bt, ev)) { 79 if (battle_bar_handle(&bt->bar, bt, ev)) {
58 switch (bt->bar.menu) { 80 switch (bt->bar.menu) {
59 case BATTLE_BAR_MENU_ATTACK: 81 case BATTLE_BAR_MENU_ATTACK:
60 open_attack(bt); 82 open_attack(bt);
61 break; 83 break;
76 void 98 void
77 battle_state_menu(struct battle *bt) 99 battle_state_menu(struct battle *bt)
78 { 100 {
79 assert(bt); 101 assert(bt);
80 102
81 static struct battle_state self = { 103 struct battle_state *state;
82 .handle = handle, 104
83 }; 105 state = alloc_new0(sizeof (*state));
106 state->data = bt;
107 state->handle = handle;
108 state->finish = finish;
84 109
85 battle_bar_open_menu(&bt->bar); 110 battle_bar_open_menu(&bt->bar);
86 battle_switch(bt, &self); 111 battle_switch(bt, state);
87 } 112 }