mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-28 15:01:53 +08:00
fix(多人游戏): 修复玩家实体与UI状态同步问题
修复多人游戏中玩家实体与UI状态不同步的问题,现在当玩家名称匹配时会自动设置UIState.player 移除单机游戏中重复设置UIState.player的代码 为WorldManager添加对象解析功能以支持多人游戏中的对象传输
This commit is contained in:
@@ -63,7 +63,6 @@ func startMultiplayerGame():
|
||||
func startSingleplayerGame():
|
||||
MultiplayerState.isMultiplayer = false
|
||||
EntityBase.generatePlayer(playerNameInput.text)
|
||||
UIState.player = EntityBase.findPlayer(playerNameInput.text)
|
||||
WorldManager.rootNode.spawnWave()
|
||||
UIState.closeCurrentPanel()
|
||||
|
||||
|
||||
@@ -117,6 +117,8 @@ func _ready():
|
||||
statebar = selfStatebar
|
||||
statebar.entity = self
|
||||
if isPlayer():
|
||||
if displayName == MultiplayerState.playerName:
|
||||
UIState.player = self
|
||||
for i in weaponStore.get_children():
|
||||
i.hide()
|
||||
weapons.append(i)
|
||||
|
||||
@@ -1,13 +1,21 @@
|
||||
class_name ArrayTool
|
||||
|
||||
static func removeAll(array: Array, value) -> Array:
|
||||
var result = []
|
||||
for item in array:
|
||||
if item != value:
|
||||
result.append(item)
|
||||
return result
|
||||
var result = []
|
||||
for item in array:
|
||||
if item != value:
|
||||
result.append(item)
|
||||
return result
|
||||
static func swap(array: Array, a: int, b: int):
|
||||
var temp = array[a]
|
||||
array[a] = array[b]
|
||||
array[b] = temp
|
||||
return array
|
||||
var temp = array[a]
|
||||
array[a] = array[b]
|
||||
array[b] = temp
|
||||
return array
|
||||
static func parseEncodedObject(arr: Array) -> Array:
|
||||
var result = []
|
||||
for item in arr:
|
||||
if item is EncodedObjectAsID:
|
||||
result.append(instance_from_id(item.get_instance_id()))
|
||||
else:
|
||||
result.append(item)
|
||||
return result
|
||||
|
||||
@@ -12,6 +12,7 @@ func _ready():
|
||||
rootNode = self
|
||||
spawner = $%spawner
|
||||
ComponentManager.init()
|
||||
spawner.spawn_function = justReturn
|
||||
func _physics_process(delta):
|
||||
runningTime += delta * 1000
|
||||
if EntityBase.mobCount() == 0 and runningTime > 1000:
|
||||
@@ -29,9 +30,12 @@ func spawnWave():
|
||||
func spawn(node: Node):
|
||||
if MultiplayerState.isMultiplayer:
|
||||
if multiplayer.is_server():
|
||||
spawner.spawn(node)
|
||||
spawner.spawn([node])
|
||||
else:
|
||||
add_child(node)
|
||||
func justReturn(data):
|
||||
print(ArrayTool.parseEncodedObject(data))
|
||||
return ArrayTool.parseEncodedObject(data)[0]
|
||||
|
||||
static func getTime():
|
||||
return runningTime
|
||||
|
||||
Reference in New Issue
Block a user