Cleanup client

This commit is contained in:
Layla 2020-08-16 22:26:30 -04:00
parent 336133d875
commit f982fd0130
No known key found for this signature in database
GPG Key ID: A494D9357BA1BE31
5 changed files with 96 additions and 10 deletions

File diff suppressed because one or more lines are too long

View File

@ -41,6 +41,7 @@ func login(_text=""):
else:
display_message("Connected to server!", Color.green)
# Load World
get_tree().change_scene("res://scenes/World.tscn")
func display_message(message="", color=Color.red):
errorLabel.add_color_override("font_color", color)

View File

@ -61,7 +61,7 @@ func join_world_async() -> Dictionary:
for precense in match_join_result.presences:
_precenses[precense.user_id] = precense
print("Currently connected: %s" % _precenses.size())
print("Joined matched with %s other players!" % _precenses.size())
return _precenses

View File

@ -1,15 +1,47 @@
extends Node
export(NodePath) var tilemapPath
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var tilemap : TileMap
# Called when the node enters the scene tree for the first time.
func _ready():
# Setup tilemap
tilemap = get_node(tilemapPath)
tilemap.clear()
# Setup connections and join wolrd
ServerConnection.connect("tile_update", self, "on_tile_update")
yield(ServerConnection.join_world_async(), "completed")
func on_tile_update(tile_data):
print(tile_data)
func on_tile_update(tile_data, update_bitmask=true):
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!")

View 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)