Implemented IDs for regions, for the pathfinding and unit movement.
This commit is contained in:
parent
0c2a075e5a
commit
7012ffb313
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
@ -69,11 +75,9 @@ func unitSelectedMethod(unit):#this is called when a unit is selected
|
|||
if unit.id != selectedUnit.id:
|
||||
unit.isSelected = false
|
||||
$TileMap/LineManager.drawAdvancedLine([],[],0,0)
|
||||
# getOccupiedTiles(selectedUnit)
|
||||
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)
|
||||
|
|
|
@ -30,16 +30,13 @@ 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)
|
||||
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
|
||||
|
|
|
@ -26,10 +26,10 @@ func _input(event):#this selects unit and signals the selected node to the main
|
|||
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)
|
||||
# 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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue