mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 03:14:47 +00:00
111 lines
3.2 KiB
C#
111 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using DotRecast.Core.Collections;
|
|
using Entitas;
|
|
using Game.JNGFrame.Logic.Entity;
|
|
using Game.JNGFrame.Logic.Entity.Contexts;
|
|
using JNGame.Math;
|
|
using JNGame.Sync.State.Tile.Entity;
|
|
using JNGame.Sync.System;
|
|
using JNGame.Sync.System.Data;
|
|
using Newtonsoft.Json;
|
|
using UnityEngine;
|
|
|
|
namespace Game.JNGState.Logic.Data
|
|
{
|
|
|
|
[Serializable]
|
|
public class EDNodeValue
|
|
{
|
|
public DValuePosition Position = null;
|
|
}
|
|
|
|
public class EDNodeData : ISTileData
|
|
{
|
|
|
|
public readonly EDNodeValue Value = new ();
|
|
|
|
private readonly EDNode _data;
|
|
public override bool IsHost => _data is not null && _data.IsHost;
|
|
|
|
public EDNodeData()
|
|
{
|
|
}
|
|
|
|
public EDNodeData(EDNode node){
|
|
Id = node.Id;
|
|
Value.Position = new DValuePosition()
|
|
{
|
|
x = node.Position.x.rawValue,
|
|
y = node.Position.y.rawValue,
|
|
z = node.Position.z.rawValue,
|
|
};
|
|
_data = node;
|
|
}
|
|
|
|
public override bool IsEquals(ISData data)
|
|
{
|
|
var node = data as EDNodeData;
|
|
if (node is null) return false;
|
|
return Value.Position.Equals(node.Value.Position);
|
|
}
|
|
|
|
public override byte[] GetByte()
|
|
{
|
|
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(Value));
|
|
}
|
|
|
|
public override byte[] GetByteDifference(ISData diffValue = null)
|
|
{
|
|
var diff = diffValue as EDNodeData;
|
|
if (diff is null || IsEquals(diffValue)) return Array.Empty<byte>();
|
|
|
|
var value = new EDNodeValue();
|
|
|
|
if (diff.Value.Position is not null) value.Position = diff.Value.Position;
|
|
|
|
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(value));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 生效字节
|
|
/// </summary>
|
|
/// <param name="bytes"></param>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public override void UByte(byte[] bytes)
|
|
{
|
|
if (bytes.Length == 0) return;
|
|
var value = JsonConvert.DeserializeObject<EDNodeValue>(Encoding.UTF8.GetString(bytes));
|
|
if (value.Position is not null) Value.Position = value.Position;
|
|
}
|
|
}
|
|
public class EDNodeDataSystem : DStateDataSystem<EDNodeData,EDNode>
|
|
{
|
|
|
|
public EDNodeDataSystem(SStateDataEnum type) : base(type)
|
|
{
|
|
}
|
|
|
|
public override JNTileContext<EDNode> NodeContext => Contexts.GetContext<EDNodeContext>();
|
|
|
|
public override int NetID => (int)NetDataEnum.EDNodeData;
|
|
|
|
public override Dictionary<long, EDNodeData> GetLatest()
|
|
{
|
|
var nodes = new Dictionary<long, EDNodeData>();
|
|
NodeContext.GetEntities().ForEach(child =>
|
|
{
|
|
if (nodes.ContainsKey(child.Id))
|
|
{
|
|
Debug.Log($"[EDNodeDataSystem] 出错 发现重复Key");
|
|
return;
|
|
}
|
|
nodes.Add(child.Id,new EDNodeData(child));
|
|
});
|
|
return nodes;
|
|
}
|
|
|
|
}
|
|
|
|
} |