コード例 #1
0
        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));
            }
        }
コード例 #2
0
 public override object NodeToType(Type type, YamlNode node, YamlObjectSerializer serializer)
 {
     return(SpriteSpecifier.FromYaml(node));
 }