-
Notifications
You must be signed in to change notification settings - Fork 1
/
ygamestate.h
256 lines (215 loc) · 8.96 KB
/
ygamestate.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
//
// Created by Daniel on 2024-03-19.
//
#ifndef YGAMESTATE_H
#define YGAMESTATE_H
#include "yarnengine.h"
#include "core/object/ref_counted.h"
#include "core/variant/typed_array.h"
#include "ygameaction.h"
#include "ygameplayer.h"
#include "yvisualaction.h"
#include "yvisualelement3d.h"
/// Forward Declaring YGameAction for use.
class YGameAction;
class YGamePlayer;
class YVisualAction;
class YEngine;
class YActionStep;
///////////////////////////////
/// YGAMESTATE
///////////////////////////////
class YGameState : public RefCounted {
GDCLASS(YGameState, RefCounted);
protected:
static Ref<YGameState> singleton;
static void _bind_methods();
public:
static YGameState *get_singleton();
static void set_singleton(const Ref<YGameState> &ref) {
singleton = ref;
}
bool has_started=false;
int next_execution_order_number;
int next_game_action_unique_id;
int next_visual_action_unique_id;
int next_player_unique_id;
int next_visual_element_unique_id;
String get_current_game_action_name();
double wait_before_going_to_next_action =0.0;
void set_wait_before_going_to_next_action(double f) {wait_before_going_to_next_action = f;}
double get_wait_before_going_to_next_action() const {return wait_before_going_to_next_action;}
double wait_before_going_to_next_step =0.0;
void set_wait_before_going_to_next_step(double f) {wait_before_going_to_next_step = f;}
double get_wait_before_going_to_next_step() const {return wait_before_going_to_next_step;}
Dictionary serialize();
void deserialize_individual_game_action_into(Vector<Ref<YGameAction>> &list_into, const Dictionary &action_dict, bool p_front_instead);
void deserialize_game_actions_into(Vector<Ref<YGameAction>> &list_into, Array serialized_actions);
Dictionary deserialize(Dictionary dict, bool p_playback_after, bool p_instant_playback);
YGamePlayer* current_turn_player;
Ref<YGameAction> current_game_action;
Vector<Ref<YGameAction>> overriding_game_actions;
Vector<Ref<YGameAction>> future_game_actions;
Vector<Ref<YGameAction>> past_game_actions;
HashMap<int,YGamePlayer*> game_players;
HashMap<int,YVisualElement3D*> visual_elements_3d;
int game_actions_done_since_started_counting = 0;
int get_game_actions_counted() const {return game_actions_done_since_started_counting;}
void restart_action_counting() {
game_actions_done_since_started_counting = 0;
}
int prevent_proceed_to_next_action = 0;
void set_prevent_proceed_to_next_action(int v) { prevent_proceed_to_next_action = MAX(v,0); }
int get_prevent_proceed_to_next_action() const { return prevent_proceed_to_next_action; }
bool showed_out_of_actions_message=false;
int register_player(YGamePlayer* ygp);
int register_player_specific_id(YGamePlayer *ygp, int desired_id);
bool remove_player_with_id(int ygp_id);
bool set_player_id(YGamePlayer* ygp,int new_pid);
bool remove_player(YGamePlayer* ygp);
YGamePlayer* get_game_player(int ypg_id);
YGamePlayer* get_game_player_by_controller(int ypg_id);
TypedArray<YGamePlayer> get_all_players();
YGamePlayer *get_game_player_by_type(int ypg_type);
double frame_count_before_doing_slow_process;
void do_process(double delta);
Ref<YGameAction> get_current_game_action() const {
return current_game_action;
}
int get_overridinge_game_action_count() const {
return overriding_game_actions.size();
}
int get_future_game_action_count() const {
return future_game_actions.size();
}
int get_past_game_action_count() const {
return past_game_actions.size();
}
Ref<YGameAction> get_previous_game_action() const {
if (past_game_actions.size() > 0)
return past_game_actions[past_game_actions.size()-1];
return nullptr;
}
Ref<YGameAction> get_next_game_action() const {
if (overriding_game_actions.size() > 0)
return overriding_game_actions[0];
if (future_game_actions.size() > 0)
return future_game_actions[0];
return nullptr;
}
Ref<YGameAction> get_past_game_action_by_index(int future_index) const {
if (future_index>=0 && future_index < past_game_actions.size())
return past_game_actions[future_index];
return nullptr;
}
Ref<YGameAction> get_future_game_action_by_index(int future_index) const {
if (future_index>=0 && future_index < future_game_actions.size())
return future_game_actions[future_index];
return nullptr;
}
Ref<YGameAction> get_overriding_game_action_by_index(int future_index) const {
if (future_index>=0 && future_index < overriding_game_actions.size())
return overriding_game_actions[future_index];
return nullptr;
}
bool has_current_game_action() const {
return !current_game_action.is_null() && current_game_action.is_valid();
}
bool end_current_game_action() const;
int last_turn_player_id=-1;
bool is_playing_back = false;
bool stop_playing_back_when_current_action_steps_done = false;
int stop_playing_back_at_id = -1;
void set_is_playing_back(bool b) {
is_playing_back = b;
}
bool get_is_playing_back() const {
return is_playing_back;
}
Ref<YGameAction> add_game_action(const Ref<YGameAction>& ygs, int desired_game_state_id = -1);
Ref<YGameAction> add_override_game_action(const Ref<YGameAction>& ygs, int desired_game_state_id = -1);
Ref<YGameAction> add_game_action_with_param(const Ref<YGameAction>& ygs, int desired_initial_param, const Variant &desired_param_data, int desired_game_state_id = -1);
Ref<YGameAction> add_override_game_action_with_param(const Ref<YGameAction>& ygs, int desired_initial_param, const Variant &desired_param_data, int desired_game_state_id = -1);
bool has_current_turn_player() const {return current_turn_player != nullptr;}
YGamePlayer* get_current_turn_player() const {return current_turn_player;}
void set_current_turn_player(YGamePlayer* _new_current_player) {
if (current_turn_player != nullptr) {
current_turn_player->turn_ended();
current_turn_player->owns_current_turn=false;
current_turn_player = nullptr;
}
if (_new_current_player != nullptr) {
current_turn_player = _new_current_player;
current_turn_player->owns_current_turn=true;
current_turn_player->turn_started();
}
}
void clear_all_players() {
for (auto gmp: game_players) {
if (gmp.value != nullptr) {
if (current_turn_player != nullptr && current_turn_player == gmp.value)
current_turn_player = nullptr;
gmp.value->queue_free();
}
}
game_players.clear();
if (current_turn_player != nullptr) {
current_turn_player = nullptr;
}
}
void clear_all_game_actions() {
if (!current_game_action.is_null() && current_game_action.is_valid()) {
current_game_action.unref();
}
last_turn_player_id = -1;
if (current_turn_player != nullptr) {
current_turn_player = nullptr;
}
overriding_game_actions.clear();
future_game_actions.clear();
past_game_actions.clear();
showed_out_of_actions_message=false;
}
HashMap<int,Variant> state_parameters;
void set_state_parameter(int param, Variant v) {state_parameters[param] = v;}
void remove_state_parameter(int param) {state_parameters.erase(param);}
Variant get_state_parameter(int param,const Variant& def) {
if (state_parameters.has(param))
return state_parameters[param];
else
return def;
}
bool has_state_parameter(int param) const { return state_parameters.has(param); }
Dictionary get_all_state_parameters() {
Dictionary returndict;
for (auto actpq: state_parameters) {
returndict[actpq.key] = actpq.value;
}
return returndict;
}
YGameState() {
next_execution_order_number = 0;
next_game_action_unique_id = 1;
next_visual_action_unique_id = 1;
next_player_unique_id = 1;
next_visual_element_unique_id = 1;
frame_count_before_doing_slow_process = 0;
wait_before_going_to_next_action = 0.0;
wait_before_going_to_next_step = 0.0;
current_turn_player = nullptr;
stop_playing_back_when_current_action_steps_done = false;
has_started = false;
is_playing_back = false;
}
~YGameState() {
if(singleton.is_valid() && singleton == this) {
singleton.unref();
}
current_turn_player = nullptr;
if (!current_game_action.is_null() && current_game_action.is_valid()) current_game_action.unref();
overriding_game_actions.clear();
future_game_actions.clear();
past_game_actions.clear();
}
};
#endif //YGAMESTATE_H