forked from oahassan/way-of-the-stick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
onlinematchloader.py
176 lines (134 loc) · 4.97 KB
/
onlinematchloader.py
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
import pygame
import gamestate
import button
import versusclient
import versusserver
import player
import onlineversusmode
import movesetdata
import splash
from versusmode import PlayerData
from functools import reduce
from enumerations import PlayerTypes, PlayerStates, PlayerPositions, PlayerDataKeys, PlayerSelectActions
LOADING_MATCH_TEXT = "Loading Match"
loading_match_label = None
loaded_indicator = False
load_match_progress_timer = 0
player_data = {
PlayerPositions.PLAYER1 : PlayerData(
PlayerPositions.PLAYER1,
None,
None,
None,
None,
None
), PlayerPositions.PLAYER2 : PlayerData(
PlayerPositions.PLAYER2,
None,
None,
None,
None,
None
)}
def set_color(data):
global player_data
player_data[data[PlayerDataKeys.PLAYER_POSITION]].color = data[PlayerDataKeys.COLOR]
def set_size(data):
global player_data
player_data[data[PlayerDataKeys.PLAYER_POSITION]].size = data[PlayerDataKeys.SIZE]
def set_difficulty(data):
global player_data
player_data[data[PlayerDataKeys.PLAYER_POSITION]].difficulty = data[PlayerDataKeys.DIFFICULTY]
def set_player_type(data):
global player_data
if gamestate.hosting:
player_data[data[PlayerDataKeys.PLAYER_POSITION]].player_type = data[PlayerDataKeys.PLAYER_TYPE]
else:
player_data[data[PlayerDataKeys.PLAYER_POSITION]].player_type = PlayerTypes.REMOTE
def set_moveset(data):
global player_data
player_data[data[PlayerDataKeys.PLAYER_POSITION]].moveset = data[PlayerDataKeys.MOVESET_NAME]
def register_network_callbacks():
versusclient.listener.register_callback(
PlayerSelectActions.SET_COLOR,
set_color
)
versusclient.listener.register_callback(
PlayerSelectActions.SET_SIZE,
set_size
)
versusclient.listener.register_callback(
PlayerSelectActions.SET_DIFFICULTY,
set_difficulty
)
versusclient.listener.register_callback(
PlayerSelectActions.SET_PLAYER_TYPE,
set_player_type
)
versusclient.listener.register_callback(
PlayerSelectActions.SET_MOVESET,
set_moveset
)
def unregister_network_callbacks():
versusclient.listener.clear_callback(PlayerSelectActions.SET_COLOR)
versusclient.listener.clear_callback(PlayerSelectActions.SET_SIZE)
versusclient.listener.clear_callback(PlayerSelectActions.SET_DIFFICULTY)
versusclient.listener.clear_callback(PlayerSelectActions.SET_PLAYER_TYPE)
versusclient.listener.clear_callback(PlayerSelectActions.SET_MOVESET)
def load():
global loading_match_label
global load_match_progress_timer
global player_data
loading_match_label = button.Label((0, 0), LOADING_MATCH_TEXT, (255,255,255),40)
loading_match_label.set_position(get_layout_label_pos())
splash.draw_loading_splash()
pygame.display.flip()
load_match_progress_timer = 0
versusmode_player_data = []
#swap actual moveset with moveset name
for player_data_object in player_data.values():
versusmode_player_data.append(
PlayerData(
player_data_object.player_position,
player_data_object.player_type,
movesetdata.get_moveset(player_data_object.moveset),
player_data_object.size,
player_data_object.color,
player_data_object.difficulty
)
)
onlineversusmode.init(versusmode_player_data)
if versusclient.local_player_is_in_match():
versusclient.listener.send_all_movesets_loaded()
elif versusclient.dummies_only():
versusclient.listener.start_match()
def unload():
global loading_match_label
global loaded_indicator
loaded_indicator = False
loading_match_label = None
def handle_events():
global loaded_indicator
global load_match_progress_timer
if loaded_indicator == False:
load()
loaded_indicator = True
#loading_match_label.draw(gamestate.screen)
#load_match_progress_timer += gamestate.clock.get_time()
#if load_match_progress_timer > 3000:
# loading_match_label.set_text(loading_match_label.text + ".")
# load_match_progress_timer = 0
#if loading_match_label.text == LOADING_MATCH_TEXT + "....":
# loading_match_label.set_text(LOADING_MATCH_TEXT)
if versusclient.listener.server_mode == versusserver.ServerModes.MATCH:
unload()
gamestate.mode = gamestate.Modes.ONLINEVERSUSMODE
versusclient.get_network_messages()
versusclient.listener.Pump()
def get_layout_label_pos():
"""returns a position that centers the loading match label in the middle of the
screen"""
global loading_match_label
x_pos = (gamestate._WIDTH / 2) - (loading_match_label.width / 2)
y_pos = (gamestate._HEIGHT / 2) - (loading_match_label.height / 2)
return (x_pos, y_pos)