public ChunkStorage Save() { var storage = new ChunkStorage(); var tileToId = TILES.GetTileToID(); storage.X = X; storage.Y = Y; storage.Level = Level.Id; storage.Registry = TILES.GetIDToName(); // Saving tile for (var x = 0; x < SIZE; x++) { for (var y = 0; y < SIZE; y++) { storage.Tiles[y * SIZE + x] = tileToId[Tiles[x, y]]; storage.Data[y * SIZE + x] = Data[x, y]; } } // Saving entities lock (Entities) { foreach (var entity in Entities.Where(e => !e.MemberOf(ENTITIES.GROUPE_SAVE_EXCUDED))) { storage.Entities.Add(entity.Save()); } } return(storage); }
public ChunkStorage Save() { ChunkStorage store = new ChunkStorage(); Dictionary <Tile, int> tileToId = TILES.GetTileToID(); store.X = X; store.Y = Y; store.Level = Level.Id; store.Registry = TILES.GetIDToName(); // Saving tile for (int x = 0; x < CHUNK_SIZE; x++) { for (int y = 0; y < CHUNK_SIZE; y++) { store.Tiles[y * CHUNK_SIZE + x] = tileToId[Tiles[x, y]]; store.Data[y * CHUNK_SIZE + x] = Data[x, y]; } } // Saving entities foreach (var e in Entities) { if (!e.IsMemberOf(ENTITIES.GROUPE_SAVE_EXCUDED)) { store.Entities.Add(e.Save()); } } return(store); }
public void HandleTILE(Socket socket, byte[] data) { new BufferReader(data) .Ignore(sizeof(int)) .ReadInteger(out var levelId) .ReadInteger(out var x) .ReadInteger(out var y) .ReadStringUTF8(out var tileName); World.GetLevel(levelId).SetTile(x, y, TILES.GetTile(tileName)); }
public static Chunk Load(ChunkStorage store) { Chunk chunk = new Chunk(store.X, store.Y); // Loading tile for (int x = 0; x < CHUNK_SIZE; x++) { for (int y = 0; y < CHUNK_SIZE; y++) { chunk.Tiles[x, y] = TILES.GetTile(store.Registry[store.Tiles[y * CHUNK_SIZE + x].ToString()]); chunk.Data[x, y] = store.Data[y * CHUNK_SIZE + x]; } } // Loading entities foreach (EntityStorage entityData in store.Entities) { Entity entity = entityData.ConstructEntity(); chunk.AddEntity(entity); } return(chunk); }
public TDTile(TILES t) { type = t; }