mirror of
https://github.com/JohnBreaux/Boat-Battle.git
synced 2024-11-15 05:25:57 +00:00
All: General code cleanup
This commit is contained in:
parent
8239c133fc
commit
ff45799305
@ -3,7 +3,7 @@
|
|||||||
[ext_resource path="res://assets/font/Minecraft.ttf" type="DynamicFontData" id=1]
|
[ext_resource path="res://assets/font/Minecraft.ttf" type="DynamicFontData" id=1]
|
||||||
[ext_resource path="res://assets/backgrounds/PanelBG_Light.tres" type="StyleBox" id=2]
|
[ext_resource path="res://assets/backgrounds/PanelBG_Light.tres" type="StyleBox" id=2]
|
||||||
|
|
||||||
[sub_resource type="StyleBoxFlat" id=5]
|
[sub_resource type="StyleBoxFlat" id=1]
|
||||||
bg_color = Color( 1, 1, 1, 1 )
|
bg_color = Color( 1, 1, 1, 1 )
|
||||||
corner_radius_top_left = 3
|
corner_radius_top_left = 3
|
||||||
corner_radius_top_right = 3
|
corner_radius_top_right = 3
|
||||||
@ -11,7 +11,7 @@ corner_radius_bottom_right = 3
|
|||||||
corner_radius_bottom_left = 3
|
corner_radius_bottom_left = 3
|
||||||
shadow_size = 4
|
shadow_size = 4
|
||||||
|
|
||||||
[sub_resource type="StyleBoxFlat" id=6]
|
[sub_resource type="StyleBoxFlat" id=2]
|
||||||
bg_color = Color( 0.847059, 0.921569, 0.964706, 1 )
|
bg_color = Color( 0.847059, 0.921569, 0.964706, 1 )
|
||||||
corner_radius_top_left = 3
|
corner_radius_top_left = 3
|
||||||
corner_radius_top_right = 3
|
corner_radius_top_right = 3
|
||||||
@ -19,7 +19,7 @@ corner_radius_bottom_right = 3
|
|||||||
corner_radius_bottom_left = 3
|
corner_radius_bottom_left = 3
|
||||||
shadow_size = 3
|
shadow_size = 3
|
||||||
|
|
||||||
[sub_resource type="StyleBoxFlat" id=4]
|
[sub_resource type="StyleBoxFlat" id=3]
|
||||||
bg_color = Color( 0.941176, 0.941176, 0.941176, 1 )
|
bg_color = Color( 0.941176, 0.941176, 0.941176, 1 )
|
||||||
corner_radius_top_left = 3
|
corner_radius_top_left = 3
|
||||||
corner_radius_top_right = 3
|
corner_radius_top_right = 3
|
||||||
@ -27,11 +27,11 @@ corner_radius_bottom_right = 3
|
|||||||
corner_radius_bottom_left = 3
|
corner_radius_bottom_left = 3
|
||||||
shadow_size = 3
|
shadow_size = 3
|
||||||
|
|
||||||
[sub_resource type="StyleBoxEmpty" id=1]
|
[sub_resource type="StyleBoxEmpty" id=4]
|
||||||
content_margin_left = 5.0
|
content_margin_left = 5.0
|
||||||
content_margin_right = 5.0
|
content_margin_right = 5.0
|
||||||
|
|
||||||
[sub_resource type="StyleBoxFlat" id=2]
|
[sub_resource type="StyleBoxFlat" id=5]
|
||||||
bg_color = Color( 0.847059, 0.921569, 0.964706, 1 )
|
bg_color = Color( 0.847059, 0.921569, 0.964706, 1 )
|
||||||
border_width_left = 2
|
border_width_left = 2
|
||||||
border_width_top = 2
|
border_width_top = 2
|
||||||
@ -46,7 +46,7 @@ corner_radius_bottom_left = 4
|
|||||||
expand_margin_top = 20.0
|
expand_margin_top = 20.0
|
||||||
shadow_color = Color( 0, 0, 0, 1 )
|
shadow_color = Color( 0, 0, 0, 1 )
|
||||||
|
|
||||||
[sub_resource type="DynamicFont" id=3]
|
[sub_resource type="DynamicFont" id=6]
|
||||||
outline_size = 1
|
outline_size = 1
|
||||||
outline_color = Color( 0.847059, 0.921569, 0.964706, 0.501961 )
|
outline_color = Color( 0.847059, 0.921569, 0.964706, 0.501961 )
|
||||||
extra_spacing_top = 5
|
extra_spacing_top = 5
|
||||||
@ -55,7 +55,7 @@ extra_spacing_char = 1
|
|||||||
font_data = ExtResource( 1 )
|
font_data = ExtResource( 1 )
|
||||||
|
|
||||||
[resource]
|
[resource]
|
||||||
default_font = SubResource( 3 )
|
default_font = SubResource( 6 )
|
||||||
Button/colors/font_color = Color( 0.0784314, 0.0784314, 0.0784314, 1 )
|
Button/colors/font_color = Color( 0.0784314, 0.0784314, 0.0784314, 1 )
|
||||||
Button/colors/font_color_disabled = Color( 0.901961, 0.901961, 0.901961, 0.2 )
|
Button/colors/font_color_disabled = Color( 0.901961, 0.901961, 0.901961, 0.2 )
|
||||||
Button/colors/font_color_hover = Color( 0.0784314, 0.0784314, 0.0784314, 1 )
|
Button/colors/font_color_hover = Color( 0.0784314, 0.0784314, 0.0784314, 1 )
|
||||||
@ -64,9 +64,9 @@ Button/constants/hseparation = 2
|
|||||||
Button/fonts/font = null
|
Button/fonts/font = null
|
||||||
Button/styles/disabled = null
|
Button/styles/disabled = null
|
||||||
Button/styles/focus = null
|
Button/styles/focus = null
|
||||||
Button/styles/hover = SubResource( 5 )
|
Button/styles/hover = SubResource( 1 )
|
||||||
Button/styles/normal = SubResource( 6 )
|
Button/styles/normal = SubResource( 2 )
|
||||||
Button/styles/pressed = SubResource( 4 )
|
Button/styles/pressed = SubResource( 3 )
|
||||||
Label/colors/font_color = Color( 1, 1, 1, 1 )
|
Label/colors/font_color = Color( 1, 1, 1, 1 )
|
||||||
Label/colors/font_color_shadow = Color( 0, 0, 0, 1 )
|
Label/colors/font_color_shadow = Color( 0, 0, 0, 1 )
|
||||||
Label/colors/font_outline_modulate = Color( 0, 0, 0, 1 )
|
Label/colors/font_outline_modulate = Color( 0, 0, 0, 1 )
|
||||||
@ -87,7 +87,7 @@ LineEdit/constants/minimum_spaces = 12
|
|||||||
LineEdit/fonts/font = null
|
LineEdit/fonts/font = null
|
||||||
LineEdit/icons/clear = null
|
LineEdit/icons/clear = null
|
||||||
LineEdit/styles/focus = null
|
LineEdit/styles/focus = null
|
||||||
LineEdit/styles/normal = SubResource( 1 )
|
LineEdit/styles/normal = SubResource( 4 )
|
||||||
LineEdit/styles/read_only = null
|
LineEdit/styles/read_only = null
|
||||||
Panel/styles/panel = ExtResource( 2 )
|
Panel/styles/panel = ExtResource( 2 )
|
||||||
PanelContainer/styles/panel = ExtResource( 2 )
|
PanelContainer/styles/panel = ExtResource( 2 )
|
||||||
@ -99,4 +99,4 @@ WindowDialog/constants/title_height = 20
|
|||||||
WindowDialog/fonts/title_font = null
|
WindowDialog/fonts/title_font = null
|
||||||
WindowDialog/icons/close = null
|
WindowDialog/icons/close = null
|
||||||
WindowDialog/icons/close_highlight = null
|
WindowDialog/icons/close_highlight = null
|
||||||
WindowDialog/styles/panel = SubResource( 2 )
|
WindowDialog/styles/panel = SubResource( 5 )
|
||||||
|
@ -9,7 +9,6 @@ var hits
|
|||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
print("Fire: _ready()")
|
|
||||||
for x in 10:
|
for x in 10:
|
||||||
for y in 10:
|
for y in 10:
|
||||||
texture(Vector2(x,y))
|
texture(Vector2(x,y))
|
||||||
|
@ -6,17 +6,12 @@ extends Control
|
|||||||
enum {MISS = -1, READY = 0, HIT = 1, SUNK = 2, LOST = 3}
|
enum {MISS = -1, READY = 0, HIT = 1, SUNK = 2, LOST = 3}
|
||||||
|
|
||||||
# Signals
|
# Signals
|
||||||
signal fire # fire(position)
|
# Sent when game is ready
|
||||||
signal hit # hit (state): see Miss/Ready/Hit/Sunk enum in Board.gd)
|
|
||||||
signal miss
|
|
||||||
signal loss
|
|
||||||
signal forfeit
|
|
||||||
|
|
||||||
signal game_ready
|
signal game_ready
|
||||||
|
|
||||||
# Path to Player class, for instantiating new Players in code
|
# Path to Player class, for instantiating new Players in code
|
||||||
var Player = preload("res://scenes/Game/Player.tscn")
|
var Player = preload("res://scenes/Game/Player.tscn")
|
||||||
|
# Path to Victory class, which handles the victory screen
|
||||||
var Victory = preload("res://scenes/Game/Victory.tscn")
|
var Victory = preload("res://scenes/Game/Victory.tscn")
|
||||||
|
|
||||||
|
|
||||||
@ -44,8 +39,8 @@ func _ready():
|
|||||||
|
|
||||||
# Function used to keep track of which players are ready
|
# Function used to keep track of which players are ready
|
||||||
func player_ready(sender):
|
func player_ready(sender):
|
||||||
print("player_ready(%s), %d" % [sender, players_ready.size()])
|
|
||||||
players_ready.append(sender)
|
players_ready.append(sender)
|
||||||
|
print_debug("%s ready (%d/%d)" % [sender, players_ready.size(), Net.peer_info.size()])
|
||||||
if (players_ready.size() >= Net.peer_info.size()):
|
if (players_ready.size() >= Net.peer_info.size()):
|
||||||
emit_signal("game_ready")
|
emit_signal("game_ready")
|
||||||
|
|
||||||
@ -100,7 +95,7 @@ remote func state_win(ships):
|
|||||||
|
|
||||||
# play_hit_sound: Play a hit sound depending on the severity of the hit
|
# play_hit_sound: Play a hit sound depending on the severity of the hit
|
||||||
# value: Lost/Sunk/Hit/Miss
|
# value: Lost/Sunk/Hit/Miss
|
||||||
sync func play_hit_sound(value):
|
remote func play_hit_sound(value):
|
||||||
match value:
|
match value:
|
||||||
LOST, SUNK:
|
LOST, SUNK:
|
||||||
AudioBus.emit_signal("ship_sunk")
|
AudioBus.emit_signal("ship_sunk")
|
||||||
@ -122,16 +117,13 @@ func mark(res):
|
|||||||
|
|
||||||
# _on_Net_incoming: Handle mail.
|
# _on_Net_incoming: Handle mail.
|
||||||
func _on_Net_incoming(mail):
|
func _on_Net_incoming(mail):
|
||||||
print ("mail: ", mail, mail.size())
|
|
||||||
if mail.size() == 3:
|
if mail.size() == 3:
|
||||||
print ("mail: ", mail, mail.size())
|
|
||||||
var sender = int(mail[0])
|
var sender = int(mail[0])
|
||||||
var message = mail[1]
|
var message = mail[1]
|
||||||
var mailtype = int(mail[2])
|
var mailtype = int(mail[2])
|
||||||
printt(sender, message, mailtype)
|
|
||||||
match mailtype:
|
match mailtype:
|
||||||
Net.REPLY:
|
Net.REPLY:
|
||||||
print ("got REPLY")
|
print_debug ("got REPLY")
|
||||||
# message is a REPLY (return value)
|
# message is a REPLY (return value)
|
||||||
match message[0]:
|
match message[0]:
|
||||||
# on "fire": fire(result)
|
# on "fire": fire(result)
|
||||||
@ -143,15 +135,15 @@ func _on_Net_incoming(mail):
|
|||||||
"forfeit":
|
"forfeit":
|
||||||
pass
|
pass
|
||||||
Net.READY:
|
Net.READY:
|
||||||
print ("got READY")
|
print_debug ("got READY")
|
||||||
# Add player to the ready array
|
# Add player to the ready array
|
||||||
player_ready(sender)
|
player_ready(sender)
|
||||||
_:
|
_:
|
||||||
print ("got ", mailtype)
|
# Unhandled mail type
|
||||||
|
print_debug ("got %d?" % mailtype)
|
||||||
|
|
||||||
# _on_player_ready: Player Ready signal handler
|
# _on_player_ready: Player Ready signal handler
|
||||||
func _on_player_ready():
|
func _on_player_ready():
|
||||||
print ("_on_player_ready")
|
|
||||||
Net.send(0, [], Net.READY)
|
Net.send(0, [], Net.READY)
|
||||||
player_ready(Net.get_network_id())
|
player_ready(Net.get_network_id())
|
||||||
|
|
||||||
@ -164,8 +156,6 @@ func victory_screen(ships, winner = true):
|
|||||||
var victory = Victory.instance()
|
var victory = Victory.instance()
|
||||||
# Give it the ships received from the opponent
|
# Give it the ships received from the opponent
|
||||||
victory.reveal_ships(ships)
|
victory.reveal_ships(ships)
|
||||||
# Print a nice message to stdout
|
|
||||||
print("You won!")
|
|
||||||
# Add victory to the scene tree
|
# Add victory to the scene tree
|
||||||
add_child(victory)
|
add_child(victory)
|
||||||
else:
|
else:
|
||||||
|
@ -17,7 +17,7 @@ func _on_peers_updated():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
func set_IP_Address_text(show):
|
func set_IP_Address_text(show):
|
||||||
# Print the IP address and port
|
# Show the IP address (or nothing)
|
||||||
if show:
|
if show:
|
||||||
# ip_address.text = "IP: %sPort:%s" % [Net.get_ip(), Net.DEFAULT_PORT]
|
# ip_address.text = "IP: %sPort:%s" % [Net.get_ip(), Net.DEFAULT_PORT]
|
||||||
ip_address.text = "IP: %s" % Net.get_ip()
|
ip_address.text = "IP: %s" % Net.get_ip()
|
||||||
|
@ -38,12 +38,13 @@ var local_info = {"name": ""}
|
|||||||
# mail: The message received from the sender (implicitly JSON-decoded by JSONRPC)
|
# mail: The message received from the sender (implicitly JSON-decoded by JSONRPC)
|
||||||
# mail_type: Type of mail (see "Mail Types" enum above)
|
# mail_type: Type of mail (see "Mail Types" enum above)
|
||||||
remote func receive(mail):
|
remote func receive(mail):
|
||||||
print_debug("recv: %s" % mail)
|
|
||||||
# Unpack the mail
|
# Unpack the mail
|
||||||
# Uses json parser of unknown stability, how fun
|
# Uses json parser of unknown stability, how fun
|
||||||
mail = parse_json(mail)
|
mail = parse_json(mail)
|
||||||
# Get the sender's ID and force letter to be properly addressed
|
# Get the sender's ID and force letter to be properly addressed
|
||||||
mail[0] = get_tree().get_rpc_sender_id()
|
mail[0] = get_tree().get_rpc_sender_id()
|
||||||
|
# print_debug it, for posterity
|
||||||
|
print_debug("recv: ", mail)
|
||||||
# Add the mail to the inbox (so it can be read back later if necessary
|
# Add the mail to the inbox (so it can be read back later if necessary
|
||||||
inbox.append(mail)
|
inbox.append(mail)
|
||||||
# Sent it off to anything that expects mail
|
# Sent it off to anything that expects mail
|
||||||
@ -54,7 +55,7 @@ remote func receive(mail):
|
|||||||
# mail: Variant of a json-encodable type (non-Object) to send
|
# mail: Variant of a json-encodable type (non-Object) to send
|
||||||
# mail_type: Type of mail (see "Mail Types" enum above)
|
# mail_type: Type of mail (see "Mail Types" enum above)
|
||||||
func send(id, mail, mail_type = REPLY):
|
func send(id, mail, mail_type = REPLY):
|
||||||
print_debug("send: %d, %s, %d" % [id, mail, mail_type])
|
print_debug("send: [%d, %s, %d]" % [id, mail, mail_type])
|
||||||
# Make the recipient receive the mail
|
# Make the recipient receive the mail
|
||||||
rpc_id(id, "receive", to_json([-1, mail, mail_type]))
|
rpc_id(id, "receive", to_json([-1, mail, mail_type]))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user