public async Task LoadPartialStateAsync(int index, IEnumerable <string> IDs, bool overwrite = false) { using (var db = new LiteDatabase(ConnectionString)) { if (overwrite) { await _runner.FlushEntitesAsync(); } var temp = db.GetCollection <SharperSaveModel>("saves").FindById(index); foreach (var id in IDs) { if (!temp.Data.ContainsKey(id)) { throw new InvalidSaveStateException($"The ID {id} does not exist in the save file."); } var entity = new SharperEntity(); foreach (var component in temp.Data[id]) { var system = _systems.Find(x => x.GetType().FullName == component.SystemType); if (system == null) { throw new InvalidSaveStateException($"Cannot find System {component.SystemType}"); } await system.RegisterComponentAsync(component.Import(entity)); } } } }
/// <summary> /// Add a <see cref="SharperEntity"/> to the Sharper Universe. /// </summary> /// <returns>An <see cref="EntityBuilder"/>, for adding multiple <see cref="SharperEntity"/> or <see cref="BaseSharperComponent"/> to the Sharper Universe.</returns> public EntityBuilder AddEntity() { ServerLog.LogInfo("Creating new SharperEntity..."); _currentEntity = new SharperEntity(); _entities.Add(_currentEntity); return(this); }
public override async Task CycleUpdateAsync(int deltaMs) { var commands = await _input.GetEntitiesByCommandInfoTypesAsync(typeof(ExitCommandInfo), typeof(AnswerCommandInfo)); foreach (var command in commands) { switch (command.Value) { case ExitCommandInfo _: _input.GetConnectionByEntity(command.Key).Disconnect(); break; case AnswerCommandInfo a: _guess = a.Guess; _inputEntity = command.Key; _gameState = GameState.Answer; var commandEntityContext = command.Key; var componentICareAbout = Components.Single(c => c.ControllingEntity == commandEntityContext); break; default: break; } } switch (_gameState) { case GameState.Question: //await outputHandler.Invoke($"{left} + {right}"); if (_inputEntity != null) { var left = _random.Next(1, 10); var right = _random.Next(1, 10); _answer = left + right; _input.GetConnectionByEntity(_inputEntity).Send($"{left} + {right}"); _gameState = GameState.Answer; } break; case GameState.Answer: if (_guess == _answer) { _guess = -1; //await outputHandler.Invoke("Correct!\n"); _gameState = GameState.Question; _input.GetConnectionByEntity(_inputEntity).Send($"Correct!"); } break; } }
public MathGameSystem(GameRunner game, SharperInputSystem input) : base(game) { _game = game; _input = input; _random = new Random(); _input.NewInputEntityCreated += async(s, e) => { await RegisterComponentAsync(await Game.CreateEntityAsync(), e.Entity); _inputEntity = e.Entity; }; }
public async Task LoadAsync(int index) { using (var db = new LiteDatabase(ConnectionString)) { await _runner.FlushEntitesAsync(); var temp = db.GetCollection <SharperSaveModel>("saves").FindById(index); foreach (var pair in temp.Data) { var entity = new SharperEntity(); foreach (var component in pair.Value) { var system = _systems.Find(x => x.GetType().FullName == component.SystemType); if (system == null) { throw new InvalidSaveStateException($"Cannot find System {component.SystemType}"); } await system.RegisterComponentAsync(component.Import(entity)); } } } }
public TestComponent(SharperEntity entity, bool startState, SharperEntity ownerEntity) : base(entity) { State = startState; OwnerEntity = ownerEntity; }
public BarComponent(SharperEntity entity) : base(entity) { }
public SharperConnectionComponent(SharperEntity entity, ISharperConnection connection) : base(entity) { Connection = connection; }
public PlayerComponent(SharperEntity entity) : base(entity) { }
public FooExportableComponent Import(SharperEntity entity) { return(new FooExportableComponent(entity)); }
public FooExportableComponent(SharperEntity entity) : base(entity) { Foo = "foo"; }
public TestComponent(SharperEntity entity, bool startState) : base(entity) { State = startState; }
public BarExportableComponent Import(SharperEntity entity) { return new BarExportableComponent(entity); }
public EmptyComponent(SharperEntity entity) : base(entity) { }
public RoundComponent(SharperEntity entity) : base(entity) { State = RoundState.Start; }
protected BaseSharperComponent(SharperEntity entity) { Entity = entity; }
public LocationComponent(SharperEntity entity, Location location, Dictionary <string, int> explorableLocations, bool playerIsHere) : base(entity) { Location = location; PlayerIsHere = playerIsHere; ExplorableLocations = explorableLocations; }
public MathGameComponent(SharperEntity entity, SharperEntity controlingEntity) : base(entity) { ControllingEntity = controlingEntity; }
public FooComponent(SharperEntity entity) : base(entity) { }