public static ItemOffer Deserialize(VariableContainer container) { return(new ItemOffer( DeserializeMany(container.Get <SerializableList>("sell")), DeserializeMany(container.Get <SerializableList>("buy")) )); }
public static Offer Deserialize(VariableContainer container) { return(new Offer( (UserId)container.Get("UserId"), container.Get <Serializable.Decimal>("Price"), container.Get <Serializable.Int>("Count"), DateTimeOffset.FromUnixTimeSeconds(container.Get <Serializable.Long>("Created")), container.Get <Serializable.String>("ItemId") )); }
public BuySellState Deserialize(VariableContainer container) { return(new BuySellState { Selling = container.Get <Serializable.Bool>("Selling"), SelectedItemId = container.Get <Serializable.String>("SelectedItemId"), SelectedItemPrice = container.Get <Serializable.Decimal>("SelectedItemPrice"), SelectedItemCount = (int?)container.Get <Serializable.Int>("SelectedItemCount") }); }
public static ResultStats Deserialize(VariableContainer container) { return(new ResultStats { ArtifactId = container.Get <Serializable.String>(nameof(ArtifactId)), Gold = container.Get <Serializable.Decimal>(nameof(Gold)), KnowledgeGroup = (Knowledge)(int)container.Get <Serializable.Int>(nameof(KnowledgeGroup)), KnowledgeMinimal = container.Get <Serializable.Decimal>(nameof(KnowledgeMinimal)), KnowledgeRequired = container.Get <Serializable.Decimal>(nameof(KnowledgeRequired)), Name = container.Get <Serializable.String>(nameof(Name)), Defence = container.Get <Serializable.Decimal>(nameof(Defence)), DefencedPlaces = (Place)(int)container.Get <Serializable.Int>(nameof(DefencedPlaces)), Damage = container.Get <Serializable.Decimal>(nameof(Damage)), Health = container.Get <Serializable.Decimal>(nameof(Health)) }); }
public void GetNotexistingTest() { var container = new VariableContainer(); Assert.Empty(container.Keys()); Assert.Null(container.Get("key")); }
public static T Deserialize <T>(VariableContainer container) where T : IState <T>, new() { var deserializer = new T(); var stateId = container.Get <Serializable.String>("stateId"); if (stateId != deserializer.StateId) { throw new ArgumentException( $"Cannot deserialize state {deserializer.StateId} instead of saved state {stateId}", nameof(container)); } var innerState = container.Get <VariableContainer>("state"); return(deserializer.Deserialize(innerState)); }
public StatsContext(Random random, VariableContainer roomVariables) { _roomVariables = roomVariables; var container = roomVariables.Get <VariableContainer>("monster_stats"); Stats = container != null ? ResultStats.Deserialize(container) : Generator.GenerateStats(random); }
public static Offers Deserialize(VariableContainer items) { var result = new Offers(); foreach (var key in items.Keys()) { var offer = items.Get <VariableContainer>(key); result[key] = ItemOffer.Deserialize(offer); } return(result); }
public void PlainTest() { var container = new VariableContainer(); Assert.Empty(container.Keys()); container.Set("test_variable", new Serializable.Int(1)); Assert.Single(container.Keys(), "test_variable"); var value = container.Get <Serializable.Int>("test_variable"); Assert.Equal(1, (int)value); }
private VariableContainer DefaultMessengers(VariableContainer variables, ChatId chatId) { var availableChats = variables.Get <VariableContainer>(RootVariable); if (availableChats != null) { return(DefaultMessengersInner(availableChats, chatId)); } var container = new VariableContainer(); variables.Set(RootVariable, container); return(DefaultMessengersInner(container, chatId)); }
public void NestedTest() { var containerA = new VariableContainer(); Assert.Empty(containerA.Keys()); var containerB = new VariableContainer(); Assert.Empty(containerB.Keys()); var containerC = new VariableContainer(); Assert.Empty(containerC.Keys()); containerC.Set("test_c", new Serializable.Bool(true)); containerB.Set("test_b", new Serializable.String("test")); containerB.Set("nested_c", containerC); containerA.Set("test_a", new Serializable.Int(1)); containerA.Set("nested_b", containerB); Assert.Equal(1, (int)containerA.Get <Serializable.Int>("test_a")); var nestedB = containerA.Get <VariableContainer>("nested_b"); Assert.NotNull(nestedB); Assert.Equal("test", nestedB.Get <Serializable.String>("test_b")); var nestedC = containerB.Get <VariableContainer>("nested_c"); Assert.NotNull(nestedC); Assert.Equal(true, (bool)nestedC.Get <Serializable.Bool>("test_c")); }
public AddOfferState Deserialize(VariableContainer container) { return(new AddOfferState { SelectedItemId = container.Get <Serializable.String>("SelectedItemId"), SelectedPriceGroup = container.Get <Serializable.Int>("SelectedPriceGroup"), SelectedItemPrice = container.Get <Serializable.Int>("SelectedItemPrice"), MaxQuantityAvailable = container.Get <Serializable.Int>("MaxQuantityAvailable"), QuantitySelected = container.Get <Serializable.Int>("QuantitySelected"), Selling = container.Get <Serializable.Bool>("Selling") }); }
private VariableContainer DefaultMessengersInner(VariableContainer availableChats, ChatId chatId) { var chat = chatId.Id.ToString(); var availableMessengers = availableChats.Get <VariableContainer>(chat); if (availableMessengers != null) { return(availableMessengers); } availableMessengers = new VariableContainer(); var defaultId = _messengers[0].Id; availableMessengers.Set(defaultId.ToString(), new Serializable.Bool(true)); availableChats.Set(chat, availableMessengers); return(availableMessengers); }