예제 #1
0
        public CompoundMap MapFromYAML(string mapYaml)
        {
            CompoundMapBridge bridge = BridgeFromYAML(mapYaml);
            CompoundMap       map    = MapFromBridge(bridge);

            return(map);
        }
예제 #2
0
        public string YAMLFromBridge(CompoundMapBridge bridge)
        {
            var serializer = GetSerializer();

            var yaml = serializer.Serialize(bridge);

            return(yaml);
        }
예제 #3
0
        public CompoundMapBridge BridgeFromMap(ICompoundMap map)
        {
            var bridge = new CompoundMapBridge
            {
                Name   = map.Name,
                Width  = map.Width,
                Height = map.Height,
            };

            // we want to create a list of the distinct terrains
            // used in this map
            List <string> distinctTerrainNames = new List <string>();

            foreach (var space in map.SpaceMap)
            {
                var name = space.Item.Terrain.Name;
                if (!distinctTerrainNames.Contains(name))
                {
                    distinctTerrainNames.Add(name);
                }
            }
            // ...then build the bridge legend from those
            foreach (var name in distinctTerrainNames)
            {
                var kv = Atlas.Legend.Where(t => t.Value.Name == name).Single();
                var ch = ((char)kv.Value.Cell.Glyph).ToString();
                bridge.Legend[ch] = name;
            }

            //data.Legend["."] = "dot dirt dere";
            //data.Legend["~"] = "tilde dirt";

            for (int y = 0; y < map.SpaceMap.Height; y++)
            {
                var sb = new StringBuilder(map.SpaceMap.Width);
                for (int x = 0; x < map.SpaceMap.Width; x++)
                {
                    var sp = map.SpaceMap.GetItem((x, y));
                    sb.Append((char)sp.Terrain.Cell.Glyph);
                }

                bridge.Terrain.Add(sb.ToString());
            }

            foreach (var beingST in map.BeingMap)
            {
                bridge.MultiBeings[beingST.Item.ID] = new Coord_IBeing {
                    Coord = beingST.Position, Being = beingST.Item
                };
            }

            foreach (var itemST in map.ItemMap)
            {
                bridge.MultiItems[itemST.Item.ID] = new Coord_IItem {
                    Coord = itemST.Position, Item = itemST.Item
                };
            }

            foreach (var rotST in map.RotMap)
            {
                bridge.AreaRots.Add(rotST.Position, rotST.Item);
            }

            bridge.Triggers.AddRange(map.Triggers);

            return(bridge);
        }
예제 #4
0
        public CompoundMap MapFromBridge(CompoundMapBridge bridge)
        {
            var width  = bridge.Terrain.Max(t => t.Length);
            var height = bridge.Terrain.Count;

            if (bridge.Width != width)
            {
                log.Error($"Map {bridge.Name} declares width {bridge.Width} but has terrain {width} wide.");
            }
            if (bridge.Height != height)
            {
                log.Error($"Map {bridge.Name} declares height {bridge.Height} but has terrain {height} high.");
            }

            var map = new CompoundMap
            {
                Name     = bridge.Name,
                Width    = width,
                Height   = height,
                SpaceMap = new SpaceMap(width, height),
                BeingMap = new BeingMap(),
                ItemMap  = new ItemMap(),
                RotMap   = new RotMap(),
            };

            var tilledSoil = Atlas.Legend[TerrainEnum.SoilTilled];

            for (int y = 0; y < height; y++)
            {
                string row = bridge.Terrain[y];
                for (int x = 0; x < width; x++)
                {
                    var symbol = (x < row.Length)
                        ? row.Substring(x, 1)
                        : "???";
                    var name = bridge.Legend[symbol];

                    var   type  = TerrainFrom(name);
                    Space space = new Space
                    {
                        Terrain  = type,
                        IsTilled = (type == tilledSoil),
                    };
                    map.SpaceMap.Add(space, (x, y));
                }
            }

            foreach (var coord in bridge.AreaRots.Keys)
            {
                map.RotMap.Add(bridge.AreaRots[coord], coord);
            }

            foreach (var pair in bridge.AreaRots)
            {
                map.RotMap.Add(pair.Value, pair.Key);
            }

            map.Triggers.AddRange(bridge.Triggers);

            return(map);
        }