Cleanup client
This commit is contained in:
parent
336133d875
commit
f982fd0130
File diff suppressed because one or more lines are too long
@ -41,6 +41,7 @@ func login(_text=""):
|
|||||||
else:
|
else:
|
||||||
display_message("Connected to server!", Color.green)
|
display_message("Connected to server!", Color.green)
|
||||||
# Load World
|
# Load World
|
||||||
|
get_tree().change_scene("res://scenes/World.tscn")
|
||||||
|
|
||||||
func display_message(message="", color=Color.red):
|
func display_message(message="", color=Color.red):
|
||||||
errorLabel.add_color_override("font_color", color)
|
errorLabel.add_color_override("font_color", color)
|
||||||
|
@ -61,7 +61,7 @@ func join_world_async() -> Dictionary:
|
|||||||
for precense in match_join_result.presences:
|
for precense in match_join_result.presences:
|
||||||
_precenses[precense.user_id] = precense
|
_precenses[precense.user_id] = precense
|
||||||
|
|
||||||
print("Currently connected: %s" % _precenses.size())
|
print("Joined matched with %s other players!" % _precenses.size())
|
||||||
|
|
||||||
return _precenses
|
return _precenses
|
||||||
|
|
||||||
|
@ -1,15 +1,47 @@
|
|||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
export(NodePath) var tilemapPath
|
||||||
|
|
||||||
# Declare member variables here. Examples:
|
var tilemap : TileMap
|
||||||
# var a = 2
|
|
||||||
# var b = "text"
|
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
|
||||||
|
# Setup tilemap
|
||||||
|
tilemap = get_node(tilemapPath)
|
||||||
|
tilemap.clear()
|
||||||
|
|
||||||
|
# Setup connections and join wolrd
|
||||||
ServerConnection.connect("tile_update", self, "on_tile_update")
|
ServerConnection.connect("tile_update", self, "on_tile_update")
|
||||||
yield(ServerConnection.join_world_async(), "completed")
|
yield(ServerConnection.join_world_async(), "completed")
|
||||||
|
|
||||||
func on_tile_update(tile_data):
|
func on_tile_update(tile_data, update_bitmask=true):
|
||||||
print(tile_data)
|
print("Updating tilemap")
|
||||||
|
|
||||||
|
var max_pos_x : int
|
||||||
|
var min_pos_x : int
|
||||||
|
var max_pos_y : int
|
||||||
|
var min_pos_y : int
|
||||||
|
|
||||||
|
for x in tile_data:
|
||||||
|
|
||||||
|
# Find max & min x
|
||||||
|
if not max_pos_x or max_pos_x > int(x):
|
||||||
|
max_pos_x = int(x)
|
||||||
|
if not min_pos_x or min_pos_x < int(x):
|
||||||
|
min_pos_x = int(x)
|
||||||
|
|
||||||
|
for y in tile_data[x]:
|
||||||
|
|
||||||
|
# Find max & min y
|
||||||
|
if not max_pos_y or max_pos_y > int(y):
|
||||||
|
max_pos_y = int(y)
|
||||||
|
if not min_pos_y or min_pos_y < int(y):
|
||||||
|
min_pos_y = int(y)
|
||||||
|
|
||||||
|
# Update tile data
|
||||||
|
tilemap.set_cell(int(x),int(y), int(tile_data[x][y]), false, false, false, tilemap.get_cell_autotile_coord(int(x), int(y)))
|
||||||
|
|
||||||
|
if update_bitmask:
|
||||||
|
tilemap.update_bitmask_region(Vector2(min_pos_x, min_pos_y), Vector2(max_pos_x, max_pos_y))
|
||||||
|
|
||||||
|
print("Update complete!")
|
||||||
|
50
client/tests/test_worldmanager.gd
Normal file
50
client/tests/test_worldmanager.gd
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
extends "res://addons/gut/test.gd"
|
||||||
|
|
||||||
|
var world_manager = load("res://scripts/singletons/WorldManager.gd")
|
||||||
|
|
||||||
|
func test_adding_tiles_to_map():
|
||||||
|
# Configure world to have a
|
||||||
|
var world = world_manager.new()
|
||||||
|
world.tilemap = TileMap.new()
|
||||||
|
|
||||||
|
world.on_tile_update({
|
||||||
|
"0" : {
|
||||||
|
"0" : "0",
|
||||||
|
"1" : "0",
|
||||||
|
"2" : "0",
|
||||||
|
"3" : "1",
|
||||||
|
"4" : "0"
|
||||||
|
},
|
||||||
|
"1" : {
|
||||||
|
"0" : "1"
|
||||||
|
}
|
||||||
|
}, false)
|
||||||
|
|
||||||
|
assert_eq(world.tilemap.get_cell(0,0), 0)
|
||||||
|
assert_eq(world.tilemap.get_cell(0,1), 0)
|
||||||
|
assert_eq(world.tilemap.get_cell(0,2), 0)
|
||||||
|
assert_eq(world.tilemap.get_cell(0,3), 1)
|
||||||
|
assert_eq(world.tilemap.get_cell(0,4), 0)
|
||||||
|
assert_eq(world.tilemap.get_cell(1,0), 1)
|
||||||
|
|
||||||
|
# Test Updates
|
||||||
|
world.on_tile_update({
|
||||||
|
"0" : {
|
||||||
|
"1" : "0",
|
||||||
|
"2" : "1"
|
||||||
|
}
|
||||||
|
}, false)
|
||||||
|
|
||||||
|
assert_eq(world.tilemap.get_cell(0,1), 0)
|
||||||
|
assert_eq(world.tilemap.get_cell(0,2), 1)
|
||||||
|
|
||||||
|
# Test New Additions
|
||||||
|
world.on_tile_update({
|
||||||
|
"1" : {
|
||||||
|
"6" : "0",
|
||||||
|
"7" : "1"
|
||||||
|
}
|
||||||
|
}, false)
|
||||||
|
|
||||||
|
assert_eq(world.tilemap.get_cell(1,6), 0)
|
||||||
|
assert_eq(world.tilemap.get_cell(1,7), 1)
|
Reference in New Issue
Block a user