public void LoadFrom(YamlMappingNode mapping) { var serializer = YamlObjectSerializer.NewReader(mapping); serializer.DataField(this, x => x.ID, "id", string.Empty); serializer.DataField(this, x => x.Priority, "priority", 100); serializer.DataField(this, x => x.MinimumRequirements, "minimumRequirements", new float[Atmospherics.TotalNumberOfGases]); serializer.DataField(this, x => x.MinimumTemperatureRequirement, "minimumTemperature", Atmospherics.TCMB); serializer.DataField(this, x => x.MinimumEnergyRequirement, "minimumEnergy", 0f); serializer.DataField(ref _effects, "effects", new List <IGasReactionEffect>()); }
public void LoadFrom(YamlMappingNode mapping) { var serializer = YamlObjectSerializer.NewReader(mapping); serializer.DataField(ref _id, "id", string.Empty); serializer.DataField(ref _name, "name", string.Empty); serializer.DataField(ref _result, "result", string.Empty); serializer.DataField(ref _ingsReagents, "reagents", new Dictionary <string, int>()); serializer.DataField(ref _ingsSolids, "solids", new Dictionary <string, int>()); serializer.DataField(ref _cookTime, "time", 5); }
public void LoadFrom(YamlMappingNode mapping) { var serializer = YamlObjectSerializer.NewReader(mapping); serializer.DataField(ref _id, "id", string.Empty); serializer.DataField(ref _name, "name", string.Empty); serializer.DataField(ref _description, "description", string.Empty); serializer.DataField <double>(ref _animationDuration, "animationDuration", 0); serializer.DataField(ref _spriteName, "spriteName", string.Empty); serializer.DataField(ref _startingInventory, "startingInventory", new Dictionary <string, uint>()); }
public override object NodeToType(Type type, YamlNode node, YamlObjectSerializer serializer) { var args = node.ToString().Split(','); var b = float.Parse(args[0], CultureInfo.InvariantCulture); var l = float.Parse(args[1], CultureInfo.InvariantCulture); var t = float.Parse(args[2], CultureInfo.InvariantCulture); var r = float.Parse(args[3], CultureInfo.InvariantCulture); return(new Box2(l, b, r, t)); }
public void LoadFrom(YamlMappingNode mapping) { var serializer = YamlObjectSerializer.NewReader(mapping); serializer.DataField(ref _id, "id", string.Empty); serializer.DataField(ref _itemId, "itemId", string.Empty); serializer.DataField(ref _price, "price", 5); serializer.DataField(ref _category, "category", UplinkCategory.Utility); serializer.DataField(ref _desc, "description", string.Empty); serializer.DataField(ref _name, "listingName", string.Empty); }
public override void ExposeData(ObjectSerializer serializer) { if (!_didRegisterSerializer) { YamlObjectSerializer.RegisterTypeSerializer(typeof(AppearanceVisualizer), new VisualizerTypeSerializer(_reflectionManager)); _didRegisterSerializer = true; } serializer.DataField(ref Visualizers, "visuals", new List <AppearanceVisualizer>()); }
public void LoadFrom(YamlMappingNode mapping) { var serializer = YamlObjectSerializer.NewReader(mapping); serializer.DataField(ref _name, "name", string.Empty); serializer.DataField(ref _id, "id", string.Empty); serializer.DataField(ref _description, "description", string.Empty); serializer.DataField(ref _icon, "icon", SpriteSpecifier.Invalid); serializer.DataField(ref _requiredPoints, "requiredpoints", 0); serializer.DataField(ref _requiredTechnologies, "requiredtechnologies", new List <string>()); serializer.DataField(ref _unlockedRecipes, "unlockedrecipes", new List <string>()); }
public void LoadFrom(YamlMappingNode mapping) { var serializer = YamlObjectSerializer.NewReader(mapping); _name = serializer.ReadDataField <string>("name"); serializer.DataField(ref _id, "id", string.Empty); serializer.DataField(ref _description, "description", string.Empty); serializer.DataField(ref _icon, "icon", SpriteSpecifier.Invalid); serializer.DataField(ref _result, "result", null); serializer.DataField(ref _hacked, "hacked", false); serializer.DataField(ref _latheType, "lathetype", "default"); }
public void LoadFrom(YamlMappingNode mapping) { var serializer = YamlObjectSerializer.NewReader(mapping); serializer.DataField(this, x => ID, "id", string.Empty); serializer.DataField(this, x => Name, "name", string.Empty); serializer.DataField(this, x => OverlayPath, "overlayPath", string.Empty); serializer.DataField(this, x => SpecificHeat, "specificHeat", 0f); serializer.DataField(this, x => GasMolesVisible, "gasMolesVisible", 0.25f); serializer.DataField(this, x => GasOverlayTexture, "gasOverlayTexture", string.Empty); serializer.DataField(this, x => GasOverlaySprite, "gasOverlaySprite", string.Empty); serializer.DataField(this, x => GasOverlayState, "gasOverlayState", string.Empty); }
public void DeserializeFiveFlagTest() { // Arrange var data = 0; var rootNode = YamlObjectSerializer_Test.YamlTextToNode(SerializedFiveFlag); var serializer = YamlObjectSerializer.NewReader(rootNode); // Act serializer.DataField(ref data, "generic_flags", 0, WithFormat.Flags <GenericFlagTag>()); // Assert Assert.That(data, Is.EqualTo((int)GenericFlags.Five)); }
public void DeserializeLegacyFormatTest() { // Arrange var data = 0; var rootNode = YamlObjectSerializer_Test.YamlTextToNode(SerializedThree); var serializer = YamlObjectSerializer.NewReader(rootNode); // Act serializer.DataField(ref data, "generic_constants", 0, WithFormat.Constants <GenericConstantTag>()); // Assert Assert.That(data, Is.EqualTo((int)GenericConstants.Three)); }
public void DeserializeListAsReadOnlyCollectionTest() { // Arrange IReadOnlyCollection <int> data = null !; var rootNode = YamlTextToNode(SerializedListYaml); var serializer = YamlObjectSerializer.NewReader(rootNode); // Act serializer.DataField(ref data, "datalist", Array.Empty <int>()); // Assert Assert.That(data, Is.EquivalentTo(SerializableList)); }
public void DeserializeZeroWithFlagTest() { // Arrange var data = 0; var rootNode = YamlObjectSerializer_Test.YamlTextToNode(SerializedZeroFlag); var serializer = YamlObjectSerializer.NewReader(rootNode); // Act serializer.DataField(ref data, "generic_flags_with_zero", 0, WithFormat.Flags <GenericFlagWithZeroTag>()); // Assert Assert.That(data, Is.EqualTo(0)); }
public void LoadFrom(YamlMappingNode mapping) { var serializer = YamlObjectSerializer.NewReader(mapping); serializer.DataField(ref _name, "name", string.Empty); serializer.DataField(ref _id, "id", string.Empty); serializer.DataField(ref _description, "description", string.Empty); serializer.DataField(ref _icon, "icon", SpriteSpecifier.Invalid); serializer.DataField(ref _product, "product", null); serializer.DataField(ref _pointCost, "cost", 0); serializer.DataField(ref _category, "category", string.Empty); serializer.DataField(ref _group, "group", string.Empty); }
public virtual void LoadFrom(YamlMappingNode mapping) { var serializer = YamlObjectSerializer.NewReader(mapping); serializer.DataReadFunction("name", string.Empty, s => Name = FormattedMessage.FromMarkup(s)); serializer.DataReadFunction("description", string.Empty, s => Description = FormattedMessage.FromMarkup(s)); serializer.DataField(this, x => x.Requires, "requires", null); serializer.DataField(this, x => x.Icon, "icon", SpriteSpecifier.Invalid); serializer.DataField(this, x => x.IconOn, "iconOn", SpriteSpecifier.Invalid); // client needs to know what type of behavior it is even if the actual implementation is only // on server side. If we wanted to avoid this we'd need to always add a shared or clientside interface // for each action even if there was only server-side logic, which would be cumbersome serializer.DataField(this, x => x.BehaviorType, "behaviorType", BehaviorType.None); if (BehaviorType == BehaviorType.None) { Logger.ErrorS("action", "Missing behaviorType for action with name {0}", Name); } if (BehaviorType != BehaviorType.Toggle && IconOn != SpriteSpecifier.Invalid) { Logger.ErrorS("action", "for action {0}, iconOn was specified but behavior" + " type was {1}. iconOn is only supported for Toggle behavior type.", Name); } serializer.DataField(this, x => x.Repeat, "repeat", false); if (Repeat && BehaviorType != BehaviorType.TargetEntity && BehaviorType != BehaviorType.TargetPoint) { Logger.ErrorS("action", " action named {0} used repeat: true, but this is only supported for" + " TargetEntity and TargetPoint behaviorType and its behaviorType is {1}", Name, BehaviorType); } serializer.DataField(this, x => x.DeselectOnCooldown, "deselectOnCooldown", false); serializer.DataField(this, x => x.DeselectWhenEntityNotClicked, "deselectWhenEntityNotClicked", false); serializer.DataReadFunction("filters", new List <string>(), rawTags => { Filters = rawTags.Select(rawTag => rawTag.Trim()).ToList(); }); serializer.DataReadFunction("keywords", new List <string>(), rawTags => { Keywords = rawTags.Select(rawTag => rawTag.Trim()).ToList(); }); }
public void SerializedEqualDictTest() { var dict = new Dictionary <string, string> { ["A"] = "B", ["C"] = "W", ["D"] = "G", ["E"] = "J" }; var dict2 = new Dictionary <string, string>(dict); Assert.That(YamlObjectSerializer.IsSerializedEqual(dict, dict2), Is.True); }
public void SerializeListAsReadOnlyCollectionTest() { // Arrange IReadOnlyCollection <int> data = SerializableList; var mapping = new YamlMappingNode(); var serializer = YamlObjectSerializer.NewWriter(mapping); // Act serializer.DataField(ref data, "datalist", Array.Empty <int>()); // Assert var result = NodeToYamlText(mapping); Assert.That(result, Is.EqualTo(SerializedListYaml)); }
public void SerializeZeroWithoutFlagTest() { // Arrange var data = 0; var mapping = new YamlMappingNode(); var serializer = YamlObjectSerializer.NewWriter(mapping); // Act serializer.DataField(ref data, "generic_flags", 0, WithFormat.Flags <GenericFlagTag>(), alwaysWrite: true); // Assert var result = YamlObjectSerializer_Test.NodeToYamlText(mapping); Assert.That(result, Is.EqualTo(SerializedZeroNum)); }
public void SerializeTypeTest() { ITestType?type = new TestTypeOne(); var mapping = new YamlMappingNode(); var writer = YamlObjectSerializer.NewWriter(mapping); writer.DataField(ref type, "type", null !); Assert.IsNotEmpty(mapping.Children); Assert.IsInstanceOf <YamlScalarNode>(mapping.Children[0].Key); var scalar = (YamlScalarNode)mapping.Children[0].Key; Assert.That(scalar.Value, Is.EqualTo("type")); }
public void SerializeNonZeroWithZeroFlagDoesntShowZeroTest() { // Arrange var data = (int)FlagsWithZero.Two; var mapping = new YamlMappingNode(); var serializer = YamlObjectSerializer.NewWriter(mapping); // Act serializer.DataField(ref data, "generic_flags_with_zero", 0, WithFormat.Flags <GenericFlagWithZeroTag>()); // Assert var result = YamlObjectSerializer_Test.NodeToYamlText(mapping); Assert.That(result, Is.EqualTo(SerializedTwoWithZeroFlag)); }
public override YamlNode TypeToNode(object obj, YamlObjectSerializer serializer) { switch (obj) { case SpriteSpecifier.Texture tex: return(tex.TexturePath.ToString()); case SpriteSpecifier.Rsi rsi: var mapping = new YamlMappingNode(); mapping.Add("sprite", rsi.RsiPath.ToString()); mapping.Add("state", rsi.RsiState); return(mapping); } throw new NotImplementedException(); }
public void SerializeOneConstantTest() { // Arrange var data = (int)GenericConstants.One; var mapping = new YamlMappingNode(); var serializer = YamlObjectSerializer.NewWriter(mapping); // Act serializer.DataField(ref data, "generic_constants", 0, WithFormat.Constants <GenericConstantTag>()); // Assert var result = YamlObjectSerializer_Test.NodeToYamlText(mapping); Assert.That(result, Is.EqualTo(SerializedOneConstant)); }
public virtual void LoadFrom(YamlMappingNode mapping) { var serializer = YamlObjectSerializer.NewReader(mapping); serializer.DataField(ref _id, "id", string.Empty); serializer.DataField(ref _coefficients, "coefficients", null); serializer.DataField(ref _flatReductions, "flatReductions", null); Resistances = new Dictionary <DamageType, ResistanceSetSettings>(); foreach (var damageType in (DamageType[])Enum.GetValues(typeof(DamageType))) { Resistances.Add(damageType, new ResistanceSetSettings(_coefficients[damageType], _flatReductions[damageType])); } }
public void SerializeFiveFlagTest() { // Arrange var data = (int)GenericFlags.Five; var mapping = new YamlMappingNode(); var serializer = YamlObjectSerializer.NewWriter(mapping); // Act serializer.DataField(ref data, "generic_flags", 0, WithFormat.Flags <GenericFlagTag>()); // Assert var result = YamlObjectSerializer_Test.NodeToYamlText(mapping); Assert.That(result, Is.EqualTo(SerializedOneFourFlag)); }
public void DeserializeExpressionTest() { var dummy = new DummyClass(); var rootNode = YamlTextToNode("foo: 5\nbar: \"baz\""); var serializer = YamlObjectSerializer.NewReader(rootNode); serializer.DataField(dummy, d => d.Foo, "foo", 4); serializer.DataField(dummy, d => d.Bar, "bar", "honk"); serializer.DataField(dummy, d => d.Baz, "baz", Color.Black); Assert.That(dummy.Foo, Is.EqualTo(5)); Assert.That(dummy.Bar, Is.EqualTo("baz")); Assert.That(dummy.Baz, Is.EqualTo(Color.Black)); }
public void LoadFrom(YamlMappingNode mapping) { var srz = YamlObjectSerializer.NewReader(mapping); ID = srz.ReadDataField<string>("id"); Name = Loc.GetString(srz.ReadDataField<string>("name")); StartingGear = srz.ReadDataField<string>("startingGear"); Departments = srz.ReadDataField<List<string>>("departments"); TotalPositions = srz.ReadDataField<int>("positions"); srz.DataField(this, p => p.SpawnPositions, "spawnPositions", TotalPositions); srz.DataField(this, p => p.IsHead, "head", false); srz.DataField(this, p => p.Access, "access", Array.Empty<string>()); srz.DataField(this, p => p.Icon, "icon", string.Empty); srz.DataField(this, p => p.Special, "special", null); }
public void SerializeDictTest() { // Arrange var data = SerializableDict; var mapping = new YamlMappingNode(); var serializer = YamlObjectSerializer.NewWriter(mapping); // Act serializer.DataField(ref data, "datadict", new Dictionary <string, int>(0)); // Assert var result = NodeToYamlText(mapping); Assert.That(result, Is.EqualTo(SerializedDictYaml)); }
public void SerializeListTest() { // Arrange var data = SerializableList; var mapping = new YamlMappingNode(); var serializer = YamlObjectSerializer.NewWriter(mapping); // Act serializer.DataField(ref data, "datalist", new List <int>(0)); // Assert var result = NodeToYamlText(mapping); Assert.That(result, Is.EqualTo(SerializedListYaml)); }
public void LoadFrom(YamlMappingNode mapping) { var serializer = YamlObjectSerializer.NewReader(mapping); serializer.DataField(this, x => ID, "id", string.Empty); serializer.DataField(this, x => Name, "name", string.Empty); serializer.DataField(this, x => OverlayPath, "overlayPath", string.Empty); serializer.DataField(this, x => SpecificHeat, "specificHeat", 0f); serializer.DataField(this, x => HeatCapacityRatio, "heatCapacityRatio", 1.4f); serializer.DataField(this, x => MolarMass, "molarMass", 1f); serializer.DataField(this, x => GasMolesVisible, "gasMolesVisible", 0.25f); serializer.DataField(this, x => GasOverlayTexture, "gasOverlayTexture", string.Empty); serializer.DataField(this, x => GasOverlaySprite, "gasOverlaySprite", string.Empty); serializer.DataField(this, x => GasOverlayState, "gasOverlayState", string.Empty); serializer.DataField(this, x => Color, "color", string.Empty); }
public virtual void LoadFrom(YamlMappingNode mapping) { var serializer = YamlObjectSerializer.NewReader(mapping); serializer.DataField(ref _id, "id", string.Empty); serializer.DataField(ref _name, "name", string.Empty); serializer.DataField(ref _description, "description", string.Empty); serializer.DataField(ref _examineMessage, "examineMessage", string.Empty); serializer.DataField(ref _rsiPath, "rsiPath", string.Empty); serializer.DataField(ref _rsiState, "rsiState", string.Empty); serializer.DataField(ref _durability, "durability", 0); serializer.DataField(ref _destroyThreshold, "destroyThreshold", 0); serializer.DataField(ref _resistance, "resistance", 0); serializer.DataField(ref _size, "size", 2); serializer.DataField(ref _compatibility, "compatibility", BodyPartCompatibility.Universal); }