Use format strings where it makes sense
This commit is contained in:
parent
f57e1c433b
commit
4d1d37a169
8 changed files with 25 additions and 27 deletions
|
@ -5,9 +5,9 @@ onready var scene = $"/root/scene" as GameInstance
|
|||
func _physics_process(_delta):
|
||||
if not visible:
|
||||
return
|
||||
var speed_str = str(round(scene.world.map.current_ship_speed * 10000)) + " u/s"
|
||||
var speed_str = "%.0f u/s" % (scene.world.map.current_ship_speed * 10000)
|
||||
$Margin/Container/VelocityBox/HBoxContainer3/CurrentSpeed.text = speed_str
|
||||
var dir_str = str(round(rad2deg(scene.world.map.current_ship_direction))) + " deg"
|
||||
var dir_str = "%.0f deg" % rad2deg(scene.world.map.current_ship_direction)
|
||||
$Margin/Container/VelocityBox/HBoxContainer2/CurrentDirection.text = dir_str
|
||||
var current_position_str = Coordinates.as_string(scene.world.map.current_ship_position + scene.world.map.current_ship_subpos, true)
|
||||
$Margin/Container/VelocityBox/HBoxContainer4/CurrentPosition.text = current_position_str
|
||||
|
|
|
@ -15,8 +15,8 @@ func _physics_process(_delta):
|
|||
total_sink += network.total_usage
|
||||
total_source += network.total_source
|
||||
total_alerts += network.unpowered
|
||||
$Margin/Container/EnergyBox/CurrentSource/Value.text = str(round(total_source)) + " kW"
|
||||
$Margin/Container/EnergyBox/CurrentSink/Value.text = str(round(total_sink)) + " kW"
|
||||
$Margin/Container/EnergyBox/CurrentSource/Value.text = "%.0f kW" % total_source
|
||||
$Margin/Container/EnergyBox/CurrentSink/Value.text = "%.0f kW" % total_sink
|
||||
$Margin/Container/EnergyBox/CurrentAlerts/Value.text = str(total_alerts)
|
||||
|
||||
func _map_button_pressed():
|
||||
|
|
|
@ -2,8 +2,8 @@ extends Control
|
|||
|
||||
onready var scene = $"/root/scene" as GameInstance
|
||||
|
||||
func set_current_charge(val):
|
||||
$Container/CurrentBox/HBoxContainer/CurrentChargeLabel.text = "(" + str(round(val/10)/100) + "MJ)"
|
||||
func set_current_charge(val: float):
|
||||
$Container/CurrentBox/HBoxContainer/CurrentChargeLabel.text = "(%.2fMJ)" % (val / 1000.0)
|
||||
$Container/CurrentBox/ProgressBar.value = val
|
||||
|
||||
func set_max_charge(val: float):
|
||||
|
|
|
@ -9,9 +9,7 @@ static func as_string(coord: Vector2, include_subcoord: bool = false) -> String:
|
|||
else:
|
||||
sector_name += str(int(y))
|
||||
if include_subcoord:
|
||||
var x_sub = floor((coord.x - x) * 100)
|
||||
var y_sub = floor((coord.y - y) * 100)
|
||||
sector_name += "." + str(int(x_sub)).pad_zeros(2) + "/" + str(int(y_sub)).pad_zeros(2)
|
||||
sector_name += ".%02d/%02d" % [(coord.x - x) * 100, (coord.y - y) * 100]
|
||||
return sector_name
|
||||
|
||||
static func to_letter(num: int) -> String:
|
||||
|
|
|
@ -30,7 +30,7 @@ master func send_map() -> void:
|
|||
var id = get_tree().get_rpc_sender_id()
|
||||
var map_data = world.map.serialize()
|
||||
var systems_data = systems.serialize()
|
||||
print("sending map data to ", id)
|
||||
print("sending map data to %d" % id)
|
||||
rpc_id(id, "receive_data", {
|
||||
"map": map_data,
|
||||
"systems": systems_data
|
||||
|
@ -44,7 +44,7 @@ puppet func receive_data(data: Dictionary) -> void:
|
|||
|
||||
master func ready_to_spawn() -> void:
|
||||
var id = get_tree().get_rpc_sender_id()
|
||||
print(id, " is ready to spawn players")
|
||||
print("%d is ready to spawn players" % id)
|
||||
|
||||
# Tell him everyone to spawn
|
||||
var players = $world/players.get_children()
|
||||
|
|
|
@ -54,7 +54,7 @@ func punch_nat():
|
|||
yield(get_tree().create_timer(.3), "timeout")
|
||||
if socketUDP.get_available_packet_count() < 1:
|
||||
failed += 1
|
||||
print("no reply (attempt #", failed, ")")
|
||||
print("no reply (attempt #%d)" % failed)
|
||||
continue
|
||||
port = socketUDP.get_var(false)
|
||||
print("Received ", port)
|
||||
|
@ -66,7 +66,7 @@ func discover_upnp():
|
|||
upnp.discover(2000, 2, "InternetGatewayDevice")
|
||||
return upnp.add_port_mapping(SERVER_PORT)
|
||||
|
||||
func host():
|
||||
func host(map_name: String = "odyssey"):
|
||||
scene_manager.enter_loader()
|
||||
scene_manager.loading_text = "Starting server"
|
||||
|
||||
|
@ -81,9 +81,9 @@ func host():
|
|||
push_warning("UPNP magicks fail, punching NAT in the face")
|
||||
yield(punch_nat(), "completed")
|
||||
|
||||
server_name = player_name + "'s server"
|
||||
server_name = "%s's server" % player_name
|
||||
player_info[1] = { "name": player_name }
|
||||
round_info = { "map": "odyssey" }
|
||||
round_info = { "map": map_name }
|
||||
|
||||
bind_events()
|
||||
var peer = NetworkedMultiplayerENet.new()
|
||||
|
@ -103,7 +103,7 @@ func host():
|
|||
scene_manager.loading_text = null
|
||||
|
||||
scene_manager.load_scene("res://Scenes/Game.tscn", [
|
||||
"res://Scenes/Maps/odyssey.tscn"
|
||||
"res://Scenes/Maps/%s.tscn" % map_name
|
||||
])
|
||||
|
||||
# Add to master server after hosting
|
||||
|
@ -124,7 +124,7 @@ func join(server):
|
|||
|
||||
peer.create_client(addr, SERVER_PORT)
|
||||
get_tree().network_peer = peer
|
||||
print("Connecting to ", addr)
|
||||
print("Connecting to %s" % addr)
|
||||
|
||||
func leave():
|
||||
var peer = get_tree().network_peer
|
||||
|
@ -145,7 +145,7 @@ func _player_connected(id):
|
|||
rpc_id(id, "_handshake", { "round": round_info, "players": player_info })
|
||||
|
||||
func _player_disconnected(id):
|
||||
print(player_info[id].name, " (", id, ") disconnected")
|
||||
print("%s (%d) disconnected" % [player_info[id].name, id])
|
||||
player_info.erase(id)
|
||||
|
||||
func _connected_ok():
|
||||
|
@ -162,7 +162,7 @@ func _connected_fail():
|
|||
remote func register_player(username: String):
|
||||
var id = get_tree().get_rpc_sender_id()
|
||||
player_info[id] = { name=username }
|
||||
print(player_info[id].name, " (", id, ") connected")
|
||||
print("%s (%d) connected" % [player_info[id].name, id])
|
||||
|
||||
remote func _handshake(infos):
|
||||
round_info = infos["round"]
|
||||
|
@ -172,9 +172,9 @@ func _ms_request(endpoint: String, data):
|
|||
var http_request = HTTPRequest.new()
|
||||
add_child(http_request)
|
||||
http_request.connect("request_completed", self, "_ms_response", [endpoint])
|
||||
print_debug("Telling ms to " + endpoint)
|
||||
print_debug("Telling ms to %s" % endpoint)
|
||||
var error = http_request.request(
|
||||
"https://" + MASTER_SERVER_ADDR + "/" + endpoint,
|
||||
"https://%s/%s" % [MASTER_SERVER_ADDR, endpoint],
|
||||
["Content-Type: application/json"],
|
||||
true, HTTPClient.METHOD_POST, JSON.print(data))
|
||||
if error != OK:
|
||||
|
@ -185,7 +185,7 @@ func ms_get_entries():
|
|||
add_child(http_request)
|
||||
http_request.connect("request_completed", self, "_ms_response", ["list_games"])
|
||||
var error = http_request.request(
|
||||
"https://" + MASTER_SERVER_ADDR + "/" + MS_GAME_CODE,
|
||||
"https://%s/%s" % [MASTER_SERVER_ADDR, MS_GAME_CODE],
|
||||
["Content-Type: application/json"],
|
||||
true, HTTPClient.METHOD_GET)
|
||||
if error != OK:
|
||||
|
@ -222,9 +222,9 @@ func _process(delta):
|
|||
time_left = 30
|
||||
|
||||
func _ms_response(_result: int, response_code: int, _headers: PoolStringArray, body: PoolByteArray, action: String):
|
||||
print_debug("MS said " + str(response_code))
|
||||
print_debug("MS said %s" % response_code)
|
||||
if response_code > 299:
|
||||
push_error("ms action \"" + action + "\" returned error: " + str(response_code) + " - " + body.get_string_from_utf8())
|
||||
push_error("ms action '%s' returned error: %s - %s" % [action, response_code, body.get_string_from_utf8()])
|
||||
return
|
||||
var json = JSON.parse(body.get_string_from_utf8())
|
||||
match action:
|
||||
|
|
|
@ -46,4 +46,4 @@ func get_progress() -> String:
|
|||
var current = 0
|
||||
for path in queue.pending:
|
||||
current += queue.get_progress(path)
|
||||
return "Loading scene (" + str(round(current/count*100)) + "%)"
|
||||
return "Loading scene (%.0f%%)" % (current/count*100)
|
||||
|
|
|
@ -34,8 +34,8 @@ func _physics_process(delta):
|
|||
radar_next_remaining = RADAR_EFFECT_DELAY
|
||||
if not visible:
|
||||
return
|
||||
speed_text.text = str(round(scene.world.map.current_ship_speed * 10000)) + " u/s"
|
||||
dir_text.text = str(round(rad2deg(scene.world.map.current_ship_direction))) + " deg"
|
||||
speed_text.text = "%.0f u/s" % (scene.world.map.current_ship_speed * 10000)
|
||||
dir_text.text = "%.0f deg" % rad2deg(scene.world.map.current_ship_direction)
|
||||
update()
|
||||
|
||||
func _draw():
|
||||
|
|
Reference in a new issue