void IEcsInitSystem.Initialize() { webSocket = new WebSocket(getServerAddress()); webSocket.OnMessage += (sender, e) => { _stateVersion++; var node = JSON.Parse(e.Data); var values = node.Values; if (values.MoveNext()) { var heroesData = values.Current["heroesData"]; var field = MapUtils.to2Dimension(values.Current["board"]); var fieldSize = field.Length; var tanks = new Dictionary <string, MapItem>(); MapItem tank; foreach (var tankNode in heroesData.Values) { tank = new MapItem(); var tankValue = tankNode.Values; tankValue.MoveNext(); tank.column = tankValue.Current["coordinate"]["x"]; tank.row = fieldSize - tankValue.Current["coordinate"]["y"] - 1; tank.symbol = field[tank.row][tank.column]; var tankKey = tankNode.Keys; tankKey.MoveNext(); tanks.Add(tankKey.Current, tank); } if (_gameState.Data.fieldSize != fieldSize) { _gameState.Data.fieldSize = fieldSize; } GameStateEventManager.getInstance().onUpdate(new BattlefieldState { field = field, tanks = tanks, size = fieldSize }, _stateVersion); } }; webSocket.OnError += (sender, e) => { Debug.Log("Socket connection error: " + e.Message); }; this._monoBehaviour.StartCoroutine(getFieldMapping()); }
void IEcsInitSystem.Initialize() { updatesHandlers.Add( new MapItemProcessor <BattleWall>( new ItemManagerDelegate <BattleWall>(_world, _battleWallsFilter, MapItems.PREFAB_BATTLE_WALL), new UpdatesHandler(), MapItems.PREFAB_TO_KEYS[MapItems.PREFAB_BATTLE_WALL] ) ); updatesHandlers.Add( new MapItemProcessor <Wall>( new WallManagerDelegate(_world, _wallsFilter, MapItems.PREFAB_WALL), new UpdatesHandler(), MapItems.PREFAB_TO_KEYS[MapItems.PREFAB_WALL] ) ); updatesHandlers.Add( new MapItemProcessor <Bullet>( new BulletManagerDelegate(_world, _bulletsFilter, MapItems.PREFAB_BULLET), new BulletsUpdatesHandler(), MapItems.PREFAB_TO_KEYS[MapItems.PREFAB_BULLET] ) ); updatesHandlers.Add( new MapItemProcessor <Medkit>( new PickUpManagerDelegate <Medkit>(_world, _medkitFilter, MapItems.PREFAB_MEDKIT), new UpdatesHandler(), MapItems.PREFAB_TO_KEYS[MapItems.PREFAB_MEDKIT] ) ); updatesHandlers.Add( new MapItemProcessor <AmmoBox>( new PickUpManagerDelegate <AmmoBox>(_world, _ammoBoxFilter, MapItems.PREFAB_AMMO_BOX), new UpdatesHandler(), MapItems.PREFAB_TO_KEYS[MapItems.PREFAB_AMMO_BOX] ) ); updatesHandlers.Add( new MapItemProcessor <Hedgehog>( new ObstacleManagerDelegate <Hedgehog>(_world, _hedgehogFilter, MapItems.PREFAB_HEDGEHOG), new UpdatesHandler(), MapItems.PREFAB_TO_KEYS[MapItems.PREFAB_HEDGEHOG] ) ); updatesHandlers.Add( new MapItemProcessor <Sand>( new ObstacleManagerDelegate <Sand>(_world, _sandFilter, MapItems.PREFAB_SAND), new UpdatesHandler(), MapItems.PREFAB_TO_KEYS[MapItems.PREFAB_SAND] ) ); updatesHandlers.Add( new MapItemProcessor <Bog>( new ObstacleManagerDelegate <Bog>(_world, _bogFilter, MapItems.PREFAB_BOG), new UpdatesHandler(), MapItems.PREFAB_TO_KEYS[MapItems.PREFAB_BOG] ) ); updatesHandlers.Add( new MapItemProcessor <Moat>( new MoatManagerDelegate(_world, _moatFilter, MapItems.PREFAB_MOAT), new UpdatesHandler(), MapItems.PREFAB_TO_KEYS[MapItems.PREFAB_MOAT] ) ); updatesHandlers.Add( new MapItemProcessor <WormHole>( new ObstacleManagerDelegate <WormHole>(_world, _wormHoleFilter, MapItems.PREFAB_WORM_HOLE), new UpdatesHandler(), MapItems.PREFAB_TO_KEYS[MapItems.PREFAB_WORM_HOLE] ) ); _tanksProcessor = new TankItemProcessor( new TanksManagerDelegate(_world, _tanksFilter, MapItems.PREFAB_TANK), new TanksUpdateHandler(), MapItems.PREFAB_TO_KEYS[MapItems.PREFAB_TANK] ); GameStateEventManager.getInstance().subscribe(this); }
void IEcsInitSystem.Destroy() { GameStateEventManager.getInstance().unSubscibe(this); }