diff --git a/Client/autoloads/Network.gd b/Client/autoloads/Network.gd index b2e1125..1105be3 100644 --- a/Client/autoloads/Network.gd +++ b/Client/autoloads/Network.gd @@ -19,8 +19,6 @@ func _ready(): get_tree().connect('network_peer_disconnected', self, '_on_player_disconnected') get_tree().connect('network_peer_connected', self, '_on_player_connected') connect_to_server("name","","") - yield(get_tree().create_timer(1),"timeout") - rpc_id(1, 'TESTFUNCTION', "TEST TEST TEST") func connect_to_server(playerName,pw,serverpassword): self.serverpassword = serverpassword diff --git a/Client/autoloads/WorldManager.gd b/Client/autoloads/WorldManager.gd index 25fc3d2..9b5bf4f 100644 --- a/Client/autoloads/WorldManager.gd +++ b/Client/autoloads/WorldManager.gd @@ -232,8 +232,8 @@ func _load_worldmap(): -func requestTiles(unit = null): - rpc_id(1, 'requestTiles', unit) +func requestTiles(unit, RegionId): + rpc_id(1, 'requestTiles', unit, RegionId) signal receiveTiles @@ -243,17 +243,17 @@ remote func receiveTiles(bundledTileStuff): var newSuperTiles = bundledTileStuff[2] emit_signal("receiveTiles", newTileRect, newTiles, newSuperTiles) -func requestUnits(): - rpc_id(1, 'requestUnits') +func requestUnits(RegionId): + rpc_id(1, 'requestUnits', RegionId) signal receiveUnits remote func receiveUnits(newBoardUnits): emit_signal("receiveUnits", newBoardUnits) -func requestMove(route, unitID): - rpc_id(1, 'requestMove', route, unitID) +func requestMove(route, unitID, RegionID): + rpc_id(1, 'requestMove', route, unitID, RegionID) -func endTurn(): - rpc_id(1, 'endTurn') +func endTurn(RegionId): + rpc_id(1, 'endTurn', RegionId) diff --git a/Client/region/Region.gd b/Client/region/Region.gd index 5a49f15..6c8c310 100644 --- a/Client/region/Region.gd +++ b/Client/region/Region.gd @@ -15,6 +15,7 @@ var enemyOccupiedTiles=[] var route var routeVertices var hoveredCoords +var regionID = 123 func _ready():#this mostly just builds a bunch of stuff WorldManager.connect("receiveTiles", self, "receiveTiles") @@ -27,7 +28,7 @@ func buildWorld(): requestUnits() func requestTiles(unit = null): - WorldManager.requestTiles(unit) + WorldManager.requestTiles(unit, regionID) func receiveTiles(newTileRect, newTiles, newSuperTiles): tileRect = newTileRect @@ -36,9 +37,9 @@ func receiveTiles(newTileRect, newTiles, newSuperTiles): $TileMap.buildTileMap(tiles) func requestUnits(): - WorldManager.requestUnits() + WorldManager.requestUnits(regionID) -func receiveUnits(newBoardUnits): +func receiveUnits(newBoardUnits):#overwork this boardUnits = newBoardUnits for child in $TileMap/Units.get_children(): child.queue_free() @@ -54,12 +55,17 @@ func receiveUnits(newBoardUnits): newUnit.on_ready() boardUnitsIndex +=1 -func unitSelectedMethod(unit):#this is called when a unit is selected +func unitSelectedMethod(unit, debugOriginUnit):#this is called when a unit is selected + print("from: ",boardUnits[debugOriginUnit.boardUnitsIndex].id) if unit == null: clearPathingInfo() $moveapcost.text = "" $unitapcounter.text = "" selectedFaction = null + selectedUnit = null + for unit in boardUnits: + unit.isSelected = false + $TileMap/LineManager.drawAdvancedLine([],[],0,0) else: selectedNode = unit selectedUnit = boardUnits[unit.boardUnitsIndex] @@ -68,12 +74,10 @@ func unitSelectedMethod(unit):#this is called when a unit is selected for unit in boardUnits: if unit.id != selectedUnit.id: unit.isSelected = false - $TileMap/LineManager.drawAdvancedLine([],[],0,0) -# getOccupiedTiles(selectedUnit) + $TileMap/LineManager.drawAdvancedLine([],[],0,0) + print(selectedUnit) func _input(event):#this responds to any input. Has various functions depending on input -# print("region ",boardUnits) -# print("server ",server.boardUnits) if selectedUnit != null: if event is InputEventMouseButton and Input.is_action_just_released("ui_left_mouse_button"): if !selectedUnit.superUnit: @@ -125,11 +129,12 @@ func hoverPath(coord = hoveredCoords):#this gets the hovered tile and tells the func nextRound():#this sends a nextRound signal to units on the board and refreshes their ap. resetPathing() -# rpc_id(1, 'nextRound') + WorldManager.endTurn(regionID) + WorldManager.requestUnits(regionID) func executePath(route, vertices):#this takes the current selected route and tells the unit to execute it/ follow the selected route. - WorldManager.requestMove(route,selectedUnit.id) + WorldManager.requestMove(route,selectedUnit.id, regionID) var convertedRoute = [] for coords in route: convertedRoute.append($TileMap.map_to_world(coords)) @@ -372,13 +377,4 @@ func clickSuperPath(): totalApCost = addUpArray(routeVertices) apDebt = totalApCost - selectedUnit.moveAp if route.size() > 1: - executeSuperPath(route, routeVertices) - -func executeSuperPath(route, vertices):#this takes the current selected route and tells the unit to execute it/ follow the selected route. - WorldManager.requestMove(route,selectedUnit.id) - var convertedRoute = [] - for coords in route: - convertedRoute.append($TileMap.map_to_world(coords)) - selectedNode.moveOnPath(convertedRoute) - animationInProgress = true - clearPathingInfo() + executePath(route, routeVertices) diff --git a/Client/region/SuperUnit.gd b/Client/region/SuperUnit.gd index c2b5d19..f9e0624 100644 --- a/Client/region/SuperUnit.gd +++ b/Client/region/SuperUnit.gd @@ -30,17 +30,14 @@ func snapToPosition(): pass func _input(event):#this selects unit and signals the selected node to the main node - if event is InputEventMouseButton and Input.is_action_just_released("ui_right_mouse_button")and isMoving==false: + if event is InputEventMouseButton and Input.is_action_pressed("ui_right_mouse_button")and isMoving==false: var localEvent = (self.make_input_local(event)) - print(localEvent.position) - print(self.position) if isSelected== true: - emit_signal("unitSelected",null) +# emit_signal("unitSelected",null,self) isSelected = false - if localEvent.position.x > 0 and localEvent.position.y > 0 and localEvent.position.x < self.position.x + 64 and localEvent.position.y < self.position.y + 64: - if isSelected== false: - emit_signal("unitSelected",self) - isSelected = true + elif localEvent.position.x > 0 and localEvent.position.y > 0 and localEvent.position.x < 64 and localEvent.position.y < 64: + emit_signal("unitSelected",self,self) + isSelected = true func moveOnPath(route:Array):#this coordinates the movement/animation isMoving=true diff --git a/Client/region/Unit.gd b/Client/region/Unit.gd index 9448556..6237dad 100644 --- a/Client/region/Unit.gd +++ b/Client/region/Unit.gd @@ -25,11 +25,11 @@ func snapToPosition(): func _input(event):#this selects unit and signals the selected node to the main node if event is InputEventMouseButton and Input.is_action_just_released("ui_right_mouse_button")and isMoving==false: var localEvent = (self.make_input_local(event)) - if isSelected== true: - emit_signal("unitSelected",null) + if isSelected == true: +# emit_signal("unitSelected",null,self) Problem here ist das weil signale asynchron sind es mehrere units gibt die meinen is Selected wäre true und dan je nach layer der units, eine das selectunit(null) signal schickt, nachdem die anderen ihr selectunit(self) signal schickt und so null selektiert wird. Lösungen: Call statt Signal. Deselect funktion funktion in der diesem Script selbst ausführen. isSelected = false - elif event.position.x > 0 and localEvent.position.y > 0 and localEvent.position.x < self.position.x + 32 and localEvent.position.y < self.position.y + 32: - emit_signal("unitSelected",self) + elif localEvent.position.x > 0 and localEvent.position.y > 0 and localEvent.position.x < 64 and localEvent.position.y < 64: + emit_signal("unitSelected",self,self) isSelected = true func moveOnPath(route:Array):#this coordinates the movement/animation diff --git a/Server/autoloads/WorldManager.gd b/Server/autoloads/WorldManager.gd index b97f025..44ec26e 100644 --- a/Server/autoloads/WorldManager.gd +++ b/Server/autoloads/WorldManager.gd @@ -202,23 +202,24 @@ remote func settle(tile, army, ascending): #if ascending, the cheapest ressource var regions = {} +#placeholder zum region testen func _ready(): var newRegion = load("res://region/Region.gd").new() newRegion.buildWorld() regions[123] = newRegion -remote func requestTiles(unit,regionId = 123): +remote func requestTiles(unit,regionId): var clientId = get_tree().get_rpc_sender_id() var tileStuff = regions[regionId].requestTiles(unit) rpc_id(clientId, 'receiveTiles', tileStuff) -remote func requestUnits(regionId = 123): +remote func requestUnits(regionId): var clientId = get_tree().get_rpc_sender_id() var boardUnits = regions[regionId].requestUnits() rpc_id(clientId, 'receiveUnits', boardUnits) -remote func requestMove(route, unitID, regionId = 123): +remote func requestMove(route, unitID, regionId): regions[regionId].moveUnit(route, unitID) -remote func endTurn(regionId = 123): +remote func endTurn(regionId): regions[regionId].nextRound() diff --git a/Server/region/Region.gd b/Server/region/Region.gd index 46fb87d..3e1f926 100644 --- a/Server/region/Region.gd +++ b/Server/region/Region.gd @@ -9,7 +9,7 @@ var tileRect = Vector2(10,11) var boardUnits = [ { "coords":Vector2(0,4), - "faction":"playerFaction", + "faction":"enemyFaction", "superUnit":false, "type":"default", "id":14231, @@ -31,7 +31,7 @@ var boardUnits = [ }, { "coords":Vector2(0,2), - "faction":"enemyFaction", + "faction":"playerFaction", "superUnit":false, "type":"default", "id":14233,