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 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 void LoadFrom(YamlMappingNode mapping) { var serializer = YamlObjectSerializer.NewReader(mapping); serializer.DataField(this, x => ID, "id", string.Empty); serializer.DataField(this, x => Priority, "priority", 100); serializer.DataField(this, x => MinimumRequirements, "minimumRequirements", new float[Atmospherics.TotalNumberOfGases]); serializer.DataField(this, x => MinimumTemperatureRequirement, "minimumTemperature", Atmospherics.TCMB); serializer.DataField(this, 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 _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 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 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 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 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 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(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 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 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 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 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 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)); }
ObjectSerializer IEntityFinishContext.GetComponentSerializer(string componentName, YamlMappingNode protoData) { if (CurrentReadingEntityComponents == null) { throw new InvalidOperationException(); } if (CurrentReadingEntityComponents.TryGetValue(componentName, out var mapping)) { return(YamlObjectSerializer.NewReader(new List <YamlMappingNode> { mapping, protoData }, this)); } return(YamlObjectSerializer.NewReader(protoData, this)); }
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); }
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 Task <List <ChangelogEntry> > LoadChangelog() { return(Task.Run(() => { var yamlData = _resource.ContentFileReadYaml(new ResourcePath("/Changelog/Changelog.yml")); if (yamlData.Documents.Count == 0) { return new List <ChangelogEntry>(); } var serializer = YamlObjectSerializer.NewReader((YamlMappingNode)yamlData.Documents[0].RootNode); return serializer.ReadDataField <List <ChangelogEntry> >("Entries"); })); }
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 _reactants, "reactants", new Dictionary <string, ReactantPrototype>()); serializer.DataField(ref _products, "products", new Dictionary <string, ReagentUnit>()); if (_moduleManager.IsServerModule) { //TODO: Don't have a check for if this is the server //Some implementations of IReactionEffect can't currently be moved to shared, so this is here to prevent the client from breaking when reading server-only IReactionEffects. serializer.DataField(ref _effects, "effects", new List <IReactionEffect>()); } }
public void DeserializeDictTest() { Dictionary <string, int> data = null; var rootNode = YamlTextToNode(SerializedDictYaml); var serializer = YamlObjectSerializer.NewReader(rootNode); // Act serializer.DataField(ref data, "datadict", new Dictionary <string, int>(0)); // Assert Assert.That(data, Is.Not.Null); Assert.That(data.Count, Is.EqualTo(SerializableDict.Count)); foreach (var kvEntry in SerializableDict) { Assert.That(data[kvEntry.Key], Is.EqualTo(kvEntry.Value)); } }
public override void LoadData(YamlMappingNode node) { base.LoadData(node); var serializer = YamlObjectSerializer.NewReader(node); var rsiString = SharedSpriteComponent.TextureRoot / serializer.ReadDataField("rsi", "Constructible/Atmos/pipe.rsi"); var resourceCache = IoCManager.Resolve <IResourceCache>(); if (resourceCache.TryGetResource(rsiString, out RSIResource? rsi)) { _pipeRSI = rsi.RSI; } else { Logger.Error($"{nameof(PipeVisualizer)} could not load to load RSI {rsiString}."); } }
public override void LoadData(YamlMappingNode node) { base.LoadData(node); var serializer = YamlObjectSerializer.NewReader(node); if (!serializer.TryReadDataField <string>("baseState", out var baseState)) { throw new PrototypeLoadException("No baseState property specified for ParticleAcceleratorPartVisualizer"); } _states.Add(ParticleAcceleratorVisualState.Powered, baseState + "p"); _states.Add(ParticleAcceleratorVisualState.Level0, baseState + "p0"); _states.Add(ParticleAcceleratorVisualState.Level1, baseState + "p1"); _states.Add(ParticleAcceleratorVisualState.Level2, baseState + "p2"); _states.Add(ParticleAcceleratorVisualState.Level3, baseState + "p3"); }
public void LoadFrom(YamlMappingNode mapping) { var serializer = YamlObjectSerializer.NewReader(mapping); ExposeData(serializer); if (!mapping.TryGetNode("steps", out YamlSequenceNode stepsMapping)) { return; } foreach (var yamlNode in stepsMapping) { var stepMapping = (YamlMappingNode)yamlNode; _steps.Add(LoadStep(stepMapping)); } }
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 _centerSlot, "centerSlot", string.Empty); serializer.DataField(ref _slots, "slots", new Dictionary <string, BodyPartType>()); serializer.DataField(ref _connections, "connections", new Dictionary <string, List <string> >()); serializer.DataField(ref _layers, "layers", new Dictionary <string, string>()); serializer.DataField(ref _mechanismLayers, "mechanismLayers", new Dictionary <string, string>()); //Our prototypes don't force the user to define a BodyPart connection twice. E.g. Head: Torso v.s. Torso: Head. //The user only has to do one. We want it to be that way in the code, though, so this cleans that up. var cleanedConnections = new Dictionary <string, List <string> >(); foreach (var targetSlotName in _slots.Keys) { var tempConnections = new List <string>(); foreach (var(slotName, slotConnections) in _connections) { if (slotName == targetSlotName) { foreach (var connection in slotConnections) { if (!tempConnections.Contains(connection)) { tempConnections.Add(connection); } } } else if (slotConnections.Contains(targetSlotName)) { tempConnections.Add(slotName); } } if (tempConnections.Count > 0) { cleanedConnections.Add(targetSlotName, tempConnections); } } _connections = cleanedConnections; }
public void DeserializeListTest() { // Arrange List <int> data = null; var rootNode = YamlTextToNode(SerializedListYaml); var serializer = YamlObjectSerializer.NewReader(rootNode); // Act serializer.DataField(ref data, "datalist", new List <int>(0)); // Assert Assert.That(data, Is.Not.Null); Assert.That(data.Count, Is.EqualTo(SerializableList.Count)); for (var i = 0; i < SerializableList.Count; i++) { Assert.That(data[i], Is.EqualTo(SerializableList[i])); } }
public void LoadFrom(YamlMappingNode mapping) { var ser = YamlObjectSerializer.NewReader(mapping); Name = ser.ReadDataField <string>("name"); ser.DataField(this, x => x.ID, "id", string.Empty); ser.DataField(this, x => x.Graph, "graph", string.Empty); ser.DataField(this, x => x.TargetNode, "targetNode", string.Empty); ser.DataField(this, x => x.StartNode, "startNode", string.Empty); ser.DataField(this, x => x.Description, "description", string.Empty); ser.DataField(this, x => x.Icon, "icon", SpriteSpecifier.Invalid); ser.DataField(this, x => x.Type, "objectType", ConstructionType.Structure); ser.DataField(this, x => x.PlacementMode, "placementMode", "PlaceFree"); ser.DataField(this, x => x.CanBuildInImpassable, "canBuildInImpassable", false); ser.DataField(this, x => x.Category, "category", string.Empty); ser.DataField(ref _conditions, "conditions", new List <IConstructionCondition>()); }
public void LoadFrom(YamlMappingNode mapping) { var serializer = YamlObjectSerializer.NewReader(mapping); serializer.DataField(ref _id, "id", string.Empty); var equipment = serializer.ReadDataField <Dictionary <string, string> >("equipment"); _equipment = equipment.ToDictionary(slotStr => { var(key, _) = slotStr; if (!Enum.TryParse(key, true, out Slots slot)) { throw new Exception($"{key} is an invalid equipment slot."); } return(slot); }, type => type.Value); }
public void LoadFrom(YamlMappingNode mapping) { var ser = YamlObjectSerializer.NewReader(mapping); _name = ser.ReadDataField <string>("name"); ser.DataField(ref _id, "id", string.Empty); ser.DataField(ref _description, "description", string.Empty); ser.DataField(ref _icon, "icon", SpriteSpecifier.Invalid); ser.DataField(ref _type, "objectType", ConstructionType.Structure); ser.DataField(ref _result, "result", null); ser.DataField(ref _placementMode, "placementMode", "PlaceFree"); ser.DataField(ref _canBuildInImpassable, "canBuildInImpassable", false); _keywords = ser.ReadDataField <List <string> >("keywords", new List <string>()); { var cat = ser.ReadDataField <string>("category"); var split = cat.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); _categorySegments = split.ToList(); } { SpriteSpecifier nextIcon = null; ConstructionStep nextBackward = null; foreach (var stepMap in mapping.GetNode <YamlSequenceNode>("steps").Cast <YamlMappingNode>()) { var step = ReadStepPrototype(stepMap); _stages.Add(new ConstructionStage(step, nextIcon, nextBackward)); if (stepMap.TryGetNode("icon", out var node)) { nextIcon = SpriteSpecifier.FromYaml(node); } if (stepMap.TryGetNode("reverse", out YamlMappingNode revMap)) { nextBackward = ReadStepPrototype(revMap); } } _stages.Add(new ConstructionStage(null, nextIcon, nextBackward)); } }