Skip to content
This repository was archived by the owner on May 8, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions game/audio_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ func _ready():


func _on_building_finished_audio(building):
var system = Store.game_data.get_system(building.system)
if Store.game_data.does_belong_to_current_player(system):
$AudioStackingBuildingFinished.play_sound_positioned(system.coordinates * Utils.SCALE_SYSTEMS_COORDS)
play_system_sound(building.system)


func _on_ship_queue_finished_audio(ship_queue):
var system = Store.game_data.get_system(ship_queue.system)
play_system_sound(ship_queue.system)


func play_system_sound(system_id):
var system = Store.game_data.get_system(system_id)
if Store.game_data.does_belong_to_current_player(system):
$AudioStackingShipQueueFinished.play_sound_positioned(system.coordinates * Utils.SCALE_SYSTEMS_COORDS)
44 changes: 24 additions & 20 deletions game/game.gd
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,26 @@ func _process(delta):
new_zoom.y = min(new_zoom.y, _target_zoom.y) if sign_vector.y > 0 else max(new_zoom.y, _target_zoom.y)
camera2D.zoom = new_zoom

func get_directions():
return {
"left": Vector2.LEFT,
"right": Vector2.RIGHT,
"up": Vector2.UP,
"down": Vector2.DOWN
}


func direct_camera(event, value):
var directions = get_directions()
for d in directions:
if event.is_action_released("ui_move_map_" + d):
_motion_camera[directions[d]] = value


func _input(event):
# mouse event has priority on the GUI
if event is InputEventKey or event is InputEventMouseButton:
if event.is_action_released("ui_move_map_left"):
_motion_camera[Vector2.LEFT] = false
if event.is_action_released("ui_move_map_right"):
_motion_camera[Vector2.RIGHT] = false
if event.is_action_released("ui_move_map_up"):
_motion_camera[Vector2.UP] = false
if event.is_action_released("ui_move_map_down"):
_motion_camera[Vector2.DOWN] = false
direct_camera(event, false)
if event.is_action_released("ui_drag_map"):
_is_map_being_dragged = false
elif event is InputEventMouseMotion:
Expand All @@ -122,14 +130,7 @@ func _input(event):
func _unhandled_input(event):
# key events has not priority over gui
if event is InputEventKey or event is InputEventMouseButton:
if event.is_action_pressed("ui_move_map_left"):
_motion_camera[Vector2.LEFT] = true
if event.is_action_pressed("ui_move_map_right"):
_motion_camera[Vector2.RIGHT] = true
if event.is_action_pressed("ui_move_map_up"):
_motion_camera[Vector2.UP] = true
if event.is_action_pressed("ui_move_map_down"):
_motion_camera[Vector2.DOWN] = true
direct_camera(event, true)
if event.is_action("ui_map_center_system"):
center_on_selected_system()

Expand Down Expand Up @@ -209,14 +210,17 @@ func _on_fleet_sailed(fleet):
fleet_container.add_child(sailing_fleet)


func _get_camera_zoom(axis, factor, max_zoom_factor_fit):
return clamp(axis * factor, pow(_ZOOM_FACTOR, _MIN_ZOOM_FACTOR), \
pow(_ZOOM_FACTOR, min(_MAX_ZOOM_FACTOR, max_zoom_factor_fit)))


func _zoom_camera(factor):
var max_screen_size = Vector2(camera2D.limit_right - camera2D.limit_left, camera2D.limit_bottom - camera2D.limit_top)
var max_zoom_factor_fit = floor(min(log(max_screen_size.x / OS.window_size.x), \
log(max_screen_size.y / OS.window_size.y)) / log(_ZOOM_FACTOR))
_target_zoom.x = clamp(camera2D.zoom.x * factor, pow(_ZOOM_FACTOR, _MIN_ZOOM_FACTOR), \
pow(_ZOOM_FACTOR, min(_MAX_ZOOM_FACTOR, max_zoom_factor_fit)))
_target_zoom.y = clamp(camera2D.zoom.y * factor, pow(_ZOOM_FACTOR, _MIN_ZOOM_FACTOR), \
pow(_ZOOM_FACTOR, min(_MAX_ZOOM_FACTOR, max_zoom_factor_fit)))
_target_zoom.x = _get_camera_zoom(camera2D.zoom.x, factor, max_zoom_factor_fit)
_target_zoom.y = _get_camera_zoom(camera2D.zoom.y, factor, max_zoom_factor_fit)


func _move_camera(vector):
Expand Down
38 changes: 15 additions & 23 deletions game/map/system.gd
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ func _modulate_color(alpha):
func _on_mouse_input(event):
if event is InputEventMouseButton and event.is_pressed():
if event.get_button_index() == BUTTON_LEFT:
_game_data.selected_state.select_system(system)
# no need to add sound because it is alreay played in the element
_game_data.selected_state.select_system(system)
elif event.get_button_index() == BUTTON_RIGHT \
Expand Down Expand Up @@ -291,35 +290,28 @@ func get_color_of_system():
else _game_data.get_player_color(_game_data.get_player(system.player), is_victory_system)


func _get_events():
return [
"fleet_added",
"hangar_updated",
"building_updated",
"building_contructed",
"fleet_owner_updated",
]


func _connect_system(system_p = system):
if system_p == null:
return
if not system_p.is_connected("fleet_added", self, "_on_fleet_created"):
system_p.connect("fleet_added", self, "_on_fleet_created")
if not system_p.is_connected("hangar_updated", self, "_on_hangar_updated"):
system_p.connect("hangar_updated", self, "_on_hangar_updated")
if not system_p.is_connected("building_updated", self, "_on_building_updated"):
system_p.connect("building_updated", self, "_on_building_updated")
if not system_p.is_connected("building_contructed", self, "_on_building_contructed"):
system_p.connect("building_contructed", self, "_on_building_contructed")
if not system_p.is_connected("fleet_owner_updated", self, "_on_fleet_owner_updated"):
system_p.connect("fleet_owner_updated", self, "_on_fleet_owner_updated")

for e in _get_events():
Utils.unique_external_connect(system_p, e, self, "_on_" + e)


func _disconnect_system(system_p = system):
if system_p == null:
return
if system_p.is_connected("fleet_added", self, "_on_fleet_created"):
system_p.disconnect("fleet_added", self, "_on_fleet_created")
if system_p.is_connected("hangar_updated", self, "_on_hangar_updated"):
system_p.disconnect("hangar_updated", self, "_on_hangar_updated")
if system_p.is_connected("building_updated", self, "_on_building_updated"):
system_p.disconnect("building_updated", self, "_on_building_updated")
if system_p.is_connected("building_contructed", self, "_on_building_contructed"):
system_p.disconnect("building_contructed", self, "_on_building_contructed")
if system_p.is_connected("fleet_owner_updated", self, "_on_fleet_owner_updated"):
system_p.disconnect("fleet_owner_updated", self, "_on_fleet_owner_updated")
for e in _get_events():
system_p.disconnect(e, self, "_on_" + e)


func _on_building_contructed(building):
Expand All @@ -330,7 +322,7 @@ func _on_fleet_owner_updated(_fleet):
refresh_fleet_pins()


func _on_fleet_created(_fleet : Fleet):
func _on_fleet_added(_fleet : Fleet):
refresh_fleet_pins()


Expand Down
27 changes: 13 additions & 14 deletions global/loading_screen.gd
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,22 @@ func _on_notification_added(notif):
set_state_label(STATE_NETWORK_ELEMENT.ERROR, label_building_status)
quit_button.visible = true

func set_error_label(label):
set_state_label(STATE_NETWORK_ELEMENT.ERROR, label)
quit_button.visible = true

func _on_timeout_auth():
if Network.token == null:
set_state_label(STATE_NETWORK_ELEMENT.ERROR, label_network_status)
quit_button.visible = true
if not cached_data.dict_loaded[CachedResource.Resource_elements.FACTIONS]:
set_state_label(STATE_NETWORK_ELEMENT.ERROR, label_faction_status)
quit_button.visible = true
if not cached_data.dict_loaded[CachedResource.Resource_elements.SHIP_MODELS]:
set_state_label(STATE_NETWORK_ELEMENT.ERROR, label_ship_status)
quit_button.visible = true
if not cached_data.dict_loaded[CachedResource.Resource_elements.CONSTANTS]:
set_state_label(STATE_NETWORK_ELEMENT.ERROR, label_constant_status)
quit_button.visible = true
if not cached_data.dict_loaded[CachedResource.Resource_elements.BUILDING]:
set_state_label(STATE_NETWORK_ELEMENT.ERROR, label_building_status)
quit_button.visible = true
set_error_label(label_network_status)
var resources = {
"FACTIONS": label_faction_status,
"SHIP_MODELS": label_ship_status,
"CONSTANTS": label_constant_status,
"BUILDING": label_building_status
}
for r in resources:
if not cached_data.dict_loaded[r]:
set_error_label(resources[r])


func _on_resource_loaded(res_name):
Expand Down
10 changes: 10 additions & 0 deletions global/utils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,13 @@ static func int_max(a: int, b: int) -> int:
return a
else:
return b


static func unique_connect(event, node, callback):
unique_external_connect(node, event, node, callback)


static func unique_external_connect(node, event, callback_node, callback):
if not node.is_connected(event, callback_node, callback):
node.connect(event, callback_node, callback)

6 changes: 2 additions & 4 deletions gui/button_panel_container.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ var _is_pressed = false


func _ready():
if not is_connected("mouse_entered", self, "_on_mouse_entered"):
connect("mouse_entered", self, "_on_mouse_entered")
if not is_connected("mouse_exited", self, "_on_mouse_exited"):
connect("mouse_exited", self, "_on_mouse_exited")
Utils.unique_connect("mouse_entered", self, "_on_mouse_entered")
Utils.unique_connect("mouse_exited", self, "_on_mouse_exited")
update_style()


Expand Down
Loading