Implemented IDs for regions, for the pathfinding and unit movement.

This commit is contained in:
Joa2 2023-11-30 09:00:27 +01:00
parent 0c2a075e5a
commit 7012ffb313
7 changed files with 40 additions and 48 deletions

View File

@ -19,8 +19,6 @@ func _ready():
get_tree().connect('network_peer_disconnected', self, '_on_player_disconnected') get_tree().connect('network_peer_disconnected', self, '_on_player_disconnected')
get_tree().connect('network_peer_connected', self, '_on_player_connected') get_tree().connect('network_peer_connected', self, '_on_player_connected')
connect_to_server("name","","") 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): func connect_to_server(playerName,pw,serverpassword):
self.serverpassword = serverpassword self.serverpassword = serverpassword

View File

@ -232,8 +232,8 @@ func _load_worldmap():
func requestTiles(unit = null): func requestTiles(unit, RegionId):
rpc_id(1, 'requestTiles', unit) rpc_id(1, 'requestTiles', unit, RegionId)
signal receiveTiles signal receiveTiles
@ -243,17 +243,17 @@ remote func receiveTiles(bundledTileStuff):
var newSuperTiles = bundledTileStuff[2] var newSuperTiles = bundledTileStuff[2]
emit_signal("receiveTiles", newTileRect, newTiles, newSuperTiles) emit_signal("receiveTiles", newTileRect, newTiles, newSuperTiles)
func requestUnits(): func requestUnits(RegionId):
rpc_id(1, 'requestUnits') rpc_id(1, 'requestUnits', RegionId)
signal receiveUnits signal receiveUnits
remote func receiveUnits(newBoardUnits): remote func receiveUnits(newBoardUnits):
emit_signal("receiveUnits", newBoardUnits) emit_signal("receiveUnits", newBoardUnits)
func requestMove(route, unitID): func requestMove(route, unitID, RegionID):
rpc_id(1, 'requestMove', route, unitID) rpc_id(1, 'requestMove', route, unitID, RegionID)
func endTurn(): func endTurn(RegionId):
rpc_id(1, 'endTurn') rpc_id(1, 'endTurn', RegionId)

View File

@ -15,6 +15,7 @@ var enemyOccupiedTiles=[]
var route var route
var routeVertices var routeVertices
var hoveredCoords var hoveredCoords
var regionID = 123
func _ready():#this mostly just builds a bunch of stuff func _ready():#this mostly just builds a bunch of stuff
WorldManager.connect("receiveTiles", self, "receiveTiles") WorldManager.connect("receiveTiles", self, "receiveTiles")
@ -27,7 +28,7 @@ func buildWorld():
requestUnits() requestUnits()
func requestTiles(unit = null): func requestTiles(unit = null):
WorldManager.requestTiles(unit) WorldManager.requestTiles(unit, regionID)
func receiveTiles(newTileRect, newTiles, newSuperTiles): func receiveTiles(newTileRect, newTiles, newSuperTiles):
tileRect = newTileRect tileRect = newTileRect
@ -36,9 +37,9 @@ func receiveTiles(newTileRect, newTiles, newSuperTiles):
$TileMap.buildTileMap(tiles) $TileMap.buildTileMap(tiles)
func requestUnits(): func requestUnits():
WorldManager.requestUnits() WorldManager.requestUnits(regionID)
func receiveUnits(newBoardUnits): func receiveUnits(newBoardUnits):#overwork this
boardUnits = newBoardUnits boardUnits = newBoardUnits
for child in $TileMap/Units.get_children(): for child in $TileMap/Units.get_children():
child.queue_free() child.queue_free()
@ -54,12 +55,17 @@ func receiveUnits(newBoardUnits):
newUnit.on_ready() newUnit.on_ready()
boardUnitsIndex +=1 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: if unit == null:
clearPathingInfo() clearPathingInfo()
$moveapcost.text = "" $moveapcost.text = ""
$unitapcounter.text = "" $unitapcounter.text = ""
selectedFaction = null selectedFaction = null
selectedUnit = null
for unit in boardUnits:
unit.isSelected = false
$TileMap/LineManager.drawAdvancedLine([],[],0,0)
else: else:
selectedNode = unit selectedNode = unit
selectedUnit = boardUnits[unit.boardUnitsIndex] selectedUnit = boardUnits[unit.boardUnitsIndex]
@ -68,12 +74,10 @@ func unitSelectedMethod(unit):#this is called when a unit is selected
for unit in boardUnits: for unit in boardUnits:
if unit.id != selectedUnit.id: if unit.id != selectedUnit.id:
unit.isSelected = false unit.isSelected = false
$TileMap/LineManager.drawAdvancedLine([],[],0,0) $TileMap/LineManager.drawAdvancedLine([],[],0,0)
# getOccupiedTiles(selectedUnit) print(selectedUnit)
func _input(event):#this responds to any input. Has various functions depending on input 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 selectedUnit != null:
if event is InputEventMouseButton and Input.is_action_just_released("ui_left_mouse_button"): if event is InputEventMouseButton and Input.is_action_just_released("ui_left_mouse_button"):
if !selectedUnit.superUnit: 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. func nextRound():#this sends a nextRound signal to units on the board and refreshes their ap.
resetPathing() 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. 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 = [] var convertedRoute = []
for coords in route: for coords in route:
convertedRoute.append($TileMap.map_to_world(coords)) convertedRoute.append($TileMap.map_to_world(coords))
@ -372,13 +377,4 @@ func clickSuperPath():
totalApCost = addUpArray(routeVertices) totalApCost = addUpArray(routeVertices)
apDebt = totalApCost - selectedUnit.moveAp apDebt = totalApCost - selectedUnit.moveAp
if route.size() > 1: if route.size() > 1:
executeSuperPath(route, routeVertices) executePath(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()

View File

@ -30,17 +30,14 @@ func snapToPosition():
pass pass
func _input(event):#this selects unit and signals the selected node to the main node 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)) var localEvent = (self.make_input_local(event))
print(localEvent.position)
print(self.position)
if isSelected== true: if isSelected== true:
emit_signal("unitSelected",null) # emit_signal("unitSelected",null,self)
isSelected = false 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: elif localEvent.position.x > 0 and localEvent.position.y > 0 and localEvent.position.x < 64 and localEvent.position.y < 64:
if isSelected== false: emit_signal("unitSelected",self,self)
emit_signal("unitSelected",self) isSelected = true
isSelected = true
func moveOnPath(route:Array):#this coordinates the movement/animation func moveOnPath(route:Array):#this coordinates the movement/animation
isMoving=true isMoving=true

View File

@ -25,11 +25,11 @@ func snapToPosition():
func _input(event):#this selects unit and signals the selected node to the main node 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_just_released("ui_right_mouse_button")and isMoving==false:
var localEvent = (self.make_input_local(event)) var localEvent = (self.make_input_local(event))
if isSelected== true: if isSelected == true:
emit_signal("unitSelected",null) # 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 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: elif localEvent.position.x > 0 and localEvent.position.y > 0 and localEvent.position.x < 64 and localEvent.position.y < 64:
emit_signal("unitSelected",self) emit_signal("unitSelected",self,self)
isSelected = true isSelected = true
func moveOnPath(route:Array):#this coordinates the movement/animation func moveOnPath(route:Array):#this coordinates the movement/animation

View File

@ -202,23 +202,24 @@ remote func settle(tile, army, ascending): #if ascending, the cheapest ressource
var regions = {} var regions = {}
#placeholder zum region testen
func _ready(): func _ready():
var newRegion = load("res://region/Region.gd").new() var newRegion = load("res://region/Region.gd").new()
newRegion.buildWorld() newRegion.buildWorld()
regions[123] = newRegion regions[123] = newRegion
remote func requestTiles(unit,regionId = 123): remote func requestTiles(unit,regionId):
var clientId = get_tree().get_rpc_sender_id() var clientId = get_tree().get_rpc_sender_id()
var tileStuff = regions[regionId].requestTiles(unit) var tileStuff = regions[regionId].requestTiles(unit)
rpc_id(clientId, 'receiveTiles', tileStuff) rpc_id(clientId, 'receiveTiles', tileStuff)
remote func requestUnits(regionId = 123): remote func requestUnits(regionId):
var clientId = get_tree().get_rpc_sender_id() var clientId = get_tree().get_rpc_sender_id()
var boardUnits = regions[regionId].requestUnits() var boardUnits = regions[regionId].requestUnits()
rpc_id(clientId, 'receiveUnits', boardUnits) rpc_id(clientId, 'receiveUnits', boardUnits)
remote func requestMove(route, unitID, regionId = 123): remote func requestMove(route, unitID, regionId):
regions[regionId].moveUnit(route, unitID) regions[regionId].moveUnit(route, unitID)
remote func endTurn(regionId = 123): remote func endTurn(regionId):
regions[regionId].nextRound() regions[regionId].nextRound()

View File

@ -9,7 +9,7 @@ var tileRect = Vector2(10,11)
var boardUnits = [ var boardUnits = [
{ {
"coords":Vector2(0,4), "coords":Vector2(0,4),
"faction":"playerFaction", "faction":"enemyFaction",
"superUnit":false, "superUnit":false,
"type":"default", "type":"default",
"id":14231, "id":14231,
@ -31,7 +31,7 @@ var boardUnits = [
}, },
{ {
"coords":Vector2(0,2), "coords":Vector2(0,2),
"faction":"enemyFaction", "faction":"playerFaction",
"superUnit":false, "superUnit":false,
"type":"default", "type":"default",
"id":14233, "id":14233,