示例#1
0
        public static Mod Create(string title)
        {
            // Determine a unique path
            var shortTitle = title.ToSafeAssetName(false);
            var modsPath   = Path.Combine(App.SavePath, "editor" + Path.DirectorySeparatorChar + "mods");
            var path       = Path.Combine(modsPath, shortTitle);

            int i = 2;

            while (Directory.Exists(path))
            {
                path = Path.Combine(modsPath, shortTitle + i);
                ++i;
            }

            // Create directory
            App.Log("Creating mod {0} ({1})", title, path);
            Mods.InitEditorDirectory();
            Directory.CreateDirectory(path);

            // Create info.txt
            var kvp = new KeyValuePairs();

            kvp.Comment = "Mod information";
            kvp.Set("title", title);
            kvp.Set("version", new Version(1, 0, 0));
            kvp.Set("game_version", App.Info.Version);
            kvp.Set("autoload", false);

            var infoPath = Path.Combine(path, "info.txt");

            using (var infoStream = new StreamWriter(infoPath))
            {
                kvp.Save(infoStream);
            }

            // Create assets directory
            var assetsPath = Path.Combine(path, "assets");

            Directory.CreateDirectory(assetsPath);

            // Load and return our new mod
            Mod mod;

            if (TryAddMod(path, ModSource.Editor, out mod))
            {
                return(mod);
            }
            else
            {
                throw new IOException(string.Format("Failed to load newly created mod {0}", path));
            }
        }
示例#2
0
        public void Save(TextWriter writer)
        {
            var kvp = new KeyValuePairs();

            kvp.Comment = "Campaign data";
            kvp.Set("title", Title);
            kvp.SetStringArray("levels", Levels.ToArray());
            kvp.SetIntegerArray("checkpoints", Checkpoints.ToArray());
            kvp.Set("id", m_id);
            kvp.Set("initial_levels_unlocked", m_initialLevelsUnlocked);
            if (m_hidden)
            {
                kvp.Set("hidden", m_hidden);
            }
            kvp.Save(writer);
        }
示例#3
0
        public void Save(TextWriter writer)
        {
            var kvp = new KeyValuePairs();

            if (ID != 0)
            {
                kvp.Set("id", ID);
            }
            kvp.Set("title", Title);
            if (ContentPath != DefaultContentPath)
            {
                kvp.Set("content_path", ContentPath);
            }
            kvp.Set("button0_prompt", Button0Prompt);
            kvp.Set("button1_prompt", Button1Prompt);
            if (UnlockCampaign != null)
            {
                kvp.Set("unlock_campaign", UnlockCampaign);
            }
            if (UnlockLevelCount != 0)
            {
                kvp.Set("unlock_level_count", UnlockLevelCount);
            }
            kvp.Save(writer);
        }
示例#4
0
        public void Save(TextWriter writer)
        {
            var kvp = new KeyValuePairs();

            kvp.SetColour("background_colour", BackgroundColour);
            kvp.Set("background_image", BackgroundImage);
            kvp.SetColour("ambient_colour", AmbientColour);
            kvp.SetColour("light_colour", LightColour);
            kvp.SetVector("light_direction", LightDirection);
            kvp.SetColour("light2_colour", Light2Colour);
            kvp.SetVector("light2_direction", Light2Direction);

            kvp.Set("model", ModelPath);
            kvp.Set("foreground_model", ModelPath);
            kvp.Set("animation", AnimPath);

            kvp.Set("render_pass", RenderPass);
            kvp.Set("foreground_render_pass", ForegroundRenderPass);
            kvp.Set("cast_shaows", CastShadows);

            kvp.Save(writer);
        }
示例#5
0
        public void Save(TextWriter output)
        {
            // Compress
            m_tileMap.Compress();

            // Save out header
            var kvp = new KeyValuePairs();

            kvp.Comment = "Level data";
            kvp.Set("id", Info.ID);
            kvp.Set("title", Info.Title);
            kvp.Set("music", Info.MusicPath);
            kvp.Set("sky", Info.SkyPath);
            kvp.Set("script", Info.ScriptPath);
            kvp.Set("item", Info.ItemPath);
            kvp.Set("intro", Info.IntroPath);
            kvp.Set("outro", Info.OutroPath);
            kvp.Set("item_count", Info.TotalPlacements);
            kvp.Set("ever_completed", Info.EverCompleted);
            kvp.Set("camera.pitch", Info.CameraPitch);
            kvp.Set("camera.yaw", Info.CameraYaw);
            kvp.Set("camera.distance", Info.CameraDistance);
            kvp.Set("random.seed", Info.RandomSeed);

            // Save out tiles
            kvp.Set("tiles.width", Tiles.Width);
            kvp.Set("tiles.height", Tiles.Height);
            kvp.Set("tiles.depth", Tiles.Depth);
            kvp.Set("tiles.x_origin", Tiles.MinX);
            kvp.Set("tiles.y_origin", Tiles.MinY);
            kvp.Set("tiles.z_origin", Tiles.MinZ);

            var lookup     = new TileLookup();
            int lastID     = -1;
            var tiles      = new StringBuilder();
            var robotCount = 0;

            for (int x = Tiles.MinX; x < Tiles.MaxX; ++x)
            {
                for (int y = Tiles.MinY; y < Tiles.MaxY; ++y)
                {
                    for (int z = Tiles.MinZ; z < Tiles.MaxZ; ++z)
                    {
                        var coords    = new TileCoordinates(x, y, z);
                        var tile      = Tiles.GetTile(coords);
                        var direction = tile.GetDirection(this, coords);
                        if (tile == Dan200.Game.Level.Tiles.Extension)
                        {
                            tile      = Dan200.Game.Level.Tiles.Air;
                            direction = FlatDirection.North;
                        }
                        int id = lookup.GetIDForTile(tile);
                        if (id < 0)
                        {
                            id     = lookup.AddTile(tile);
                            lastID = id;
                        }
                        tiles.Append(Base64.ToString(id, 2));
                        tiles.Append(Base64.ToString((int)direction, 1));

                        var behaviour = tile.GetBehaviour(this, coords);
                        if (behaviour is SpawnTileBehaviour && ((SpawnTileBehaviour)behaviour).Required)
                        {
                            robotCount++;
                        }
                    }
                }
            }
            kvp.Set("tiles.data", tiles.ToString());
            kvp.Set("robot_count", robotCount);

            // Save out lookup
            var lookupString = new StringBuilder();

            for (int i = 0; i <= lastID; ++i)
            {
                var tile = lookup.GetTileFromID(i);
                lookupString.Append(tile.Path);
                if (i < lastID)
                {
                    lookupString.Append(',');
                }
            }
            kvp.Set("tiles.lookup", lookupString.ToString());

            // Save out file
            kvp.Save(output);
        }
示例#6
0
        private void Load(IFileStore store)
        {
            using (var stream = store.OpenFile(m_path))
            {
                var    reader = new StreamReader(stream, Encoding.UTF8);
                string line;
                string type    = null;
                var    options = new KeyValuePairs();
                while ((line = reader.ReadLine()) != null)
                {
                    // Parse each line
                    string[] parts = line.Split(' ');
                    if (parts.Length < 1)
                    {
                        continue;
                    }

                    // Extract type and options
                    type = parts[0];
                    options.Clear();
                    for (int i = 1; i < parts.Length; ++i)
                    {
                        string part        = parts[i];
                        int    equalsIndex = part.IndexOf('=');
                        if (equalsIndex >= 0)
                        {
                            string key   = part.Substring(0, equalsIndex);
                            string value = part.Substring(equalsIndex + 1);
                            int    intValue;
                            if (value.StartsWith("\""))
                            {
                                if (value.EndsWith("\"") && value.Length >= 2)
                                {
                                    value = value.Substring(1, value.Length - 2);
                                }
                                else
                                {
                                    value = value.Substring(1) + " ";
                                    i++;
                                    while (!parts[i].EndsWith("\""))
                                    {
                                        value += parts[i] + " ";
                                        i++;
                                    }
                                    value += parts[i].Substring(0, parts[i].Length - 1);
                                }
                                options.Set(key, value);
                            }
                            else if (int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out intValue))
                            {
                                options.Set(key, intValue);
                            }
                        }
                    }

                    // Interpret
                    switch (type)
                    {
                    case "common":
                    {
                        m_lineHeight = options.GetInteger("lineHeight");
                        m_base       = options.GetInteger("base");
                        m_scaleW     = options.GetInteger("scaleW");
                        m_scaleH     = options.GetInteger("scaleH");
                        m_pages      = new Page[options.GetInteger("pages")];
                        break;
                    }

                    case "page":
                    {
                        int id = options.GetInteger("id");
                        if (id >= PageCount)
                        {
                            Array.Resize(ref m_pages, id + 1);
                        }
                        m_pages[id]      = new Page();
                        m_pages[id].Path = AssetPath.Combine(AssetPath.GetDirectoryName(m_path), options.GetString("file"));
                        break;
                    }

                    case "chars":
                    {
                        m_chars = new Dictionary <int, Char>(options.GetInteger("count"));
                        break;
                    }

                    case "char":
                    {
                        var id = options.GetInteger("id");
                        m_chars[id]          = new Char();
                        m_chars[id].X        = options.GetInteger("x");
                        m_chars[id].Y        = options.GetInteger("y");
                        m_chars[id].Width    = options.GetInteger("width");
                        m_chars[id].Height   = options.GetInteger("height");
                        m_chars[id].XOffset  = options.GetInteger("xoffset");
                        m_chars[id].YOffset  = options.GetInteger("yoffset");
                        m_chars[id].XAdvance = options.GetInteger("xadvance");
                        m_chars[id].Page     = options.GetInteger("page");
                        if (m_chars[id].Page < 0 || m_chars[id].Page >= PageCount)
                        {
                            m_chars[id].Page = 0;
                            //throw new IOException( "Page count out of range" );
                        }
                        break;
                    }

                    case "kernings":
                    {
                        m_kernings = new Dictionary <KerningPair, Kerning>(options.GetInteger("count"));
                        break;
                    }

                    case "kerning":
                    {
                        var first  = options.GetInteger("first");
                        var second = options.GetInteger("second");
                        var pair   = new KerningPair(first, second);
                        m_kernings[pair]        = new Kerning();
                        m_kernings[pair].Amount = options.GetInteger("amount");
                        break;
                    }
                    }
                }
            }
        }