/// <summary> /// Should pass the correct voxel (with correct x and y coord) /// </summary> public void ToVoxel(GameVoxel voxel, GameplayObjectsSerializer gameplayObjectsSerializer) { Debug.Assert(voxel.Coord.X == X); Debug.Assert(voxel.Coord.Y == Y); voxel.World.ChangeType(voxel, gameplayObjectsSerializer.GetVoxelType(this.TypeName)); //voxel.ResetData(); // TODO: potential overhead //voxel.Data.Type = gameplayObjectsSerializer.GetVoxelType(this.TypeName); voxel.Data.MagicLevel = MagicLevel; voxel.Data.DataValue = DataValue; voxel.Data.Inventory.Clear(); if (InventoryItems != null) { foreach (var item in InventoryItems) { voxel.Data.Inventory.AddNewItems(gameplayObjectsSerializer.GetItemType(item), 1); } } voxel.Data.Height = Height; voxel.Data.WorkerCount = WorkerCount; }
public void Set(PlayerState state, GameplayObjectsSerializer objectSerializer) { Name = state.Name; ActiveToolName = objectSerializer.Serialize(state.ActiveTool); HeightToolSize = (state.HeightToolSize); HeightToolState = (state.HeightToolState); }
public void ApplyVoxels(Internal.Model.World world, GameplayObjectsSerializer objectSerializer) { foreach (var voxel in Voxels) { var target = world.GetVoxel(new Point2(voxel.X, voxel.Y)); voxel.ToVoxel(target, objectSerializer); } }
public void Set(GameState state, GameplayObjectsSerializer objectSerializer) { Players = state.Players.Select(ps => { var ret = new SerializedPlayerState(); ret.Set(ps, objectSerializer); return(ret); }).ToArray(); }
public void Apply(PlayerState state, GameplayObjectsSerializer objectSerializer) { if (state.Name != Name) { throw new InvalidOperationException("Deserializing on wrong or changed name player!"); } state.ActiveTool = objectSerializer.GetPlayerTool(ActiveToolName); state.HeightToolSize = HeightToolSize; state.HeightToolState = HeightToolState; }
public void Apply(GameState state, GameplayObjectsSerializer objectSerializer) { foreach (var sp in Players) { var player = state.Players.FirstOrDefault(k => k.Name == sp.Name); if (player == null) { player = new PlayerState(); player.Name = sp.Name; state.AddPlayer(player); } sp.Apply(player, objectSerializer); } }
public void ToWorld(Internal.Model.World world, GameplayObjectsSerializer gameplayObjectsSerializer) { foreach (var el in Voxels) { var v = world.GetVoxel(new Point2(el.X, el.Y)); if (v == null) { //Console.WriteLine("Deserializing voxel but world to small: " + el.X + ", " + el.Y); continue; } try { el.ToVoxel(v, gameplayObjectsSerializer); } catch (Exception ex) { DI.Get <IErrorLogger>().Log(ex, "Can't load voxel in serializedworld"); } } }
public void SetVoxels(IEnumerable <GameVoxel> voxels, GameplayObjectsSerializer objectSerializer) { Voxels = voxels.Select(SerializedVoxel.FromVoxel).ToArray(); }