public async Task EntityComponentScript_should_work() { var entity = _world.CreateEntity(); entity.Set(new TestComponent { Dice1 = Dice.Parse("2d+5") }); var c = entity.Get <TestComponent>(); //sanity Assert.Equal(0, c.RollResult); var changeScript = new EntityComponentScript(@"component.RollResult = component.Dice1.Roll();", Assembly.GetExecutingAssembly()); await changeScript.RunAsyncOn <TestComponent>(entity); Assert.NotEqual(0, c.RollResult); }
static async Task Main(string[] args) { Console.ReadLine(); var jsonSerializerOptions = new JsonSerializerOptions(); jsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); var json = JsonSerializer.Serialize(KeyMappings.ToArray(), jsonSerializerOptions); var col = JsonSerializer.Deserialize <IEnumerable <KeyValuePair <ConsoleKey, ActionList> > >(json, jsonSerializerOptions); //while (true) //{ // var dice = Dice.Parse(Console.ReadLine()); // var value = dice.Roll(); // Console.WriteLine(value); //} var templateCollection = new EntityTemplateCollection("."); var entityFactory = new EntityFactory(new World(), templateCollection); var success = entityFactory.TryCreateEntity("actor2", out var actorEntity); Console.WriteLine(success); var foobarComponent = actorEntity.Get <FoobarComponent>(); Console.WriteLine(foobarComponent.Dice1.Roll()); Console.WriteLine(foobarComponent.Dice2.Roll()); actorEntity.Set(new FoobarComponent { Dice1 = Dice.Parse("2d+5") }); var c = actorEntity.Get <FoobarComponent>(); var changeScript = new EntityComponentScript(@"component.RollResult = component.Dice1.Roll();"); await changeScript.RunAsyncOn <FoobarComponent>(actorEntity); Console.WriteLine(); Console.WriteLine(c.RollResult); await changeScript.RunAsyncOn <FoobarComponent>(actorEntity); Console.WriteLine(c.RollResult); }