Exemple #1
0
        public Story(string author, string title)
        {
            this.Path = Directory.CreateDirectory(Program.WorldsPath + "\\" + author + " - " + title).FullName;
            using (File.Create(this.Path + @"\World.ini")) { }
            this.WorldIni = new IniFile(this.Path + @"\World.ini");

            Story_Crafter.Properties.Resources.default_icon.Save(this.Path + @"\Icon.png");
            Story_Crafter.Properties.Resources.default_info.Save(this.Path + @"\Info.png");

            this.Author      = author;
            this.Title       = title;
            this.Description = "";
            this.Size        = "";
            this.CategoryA   = "";
            this.CategoryB   = "";
            this.DifficultyA = "";
            this.DifficultyB = "";
            this.DifficultyC = "";

            this.Clothes = Program.Clothes;
            this.Skin    = Program.Skin;

            this.DefaultSave         = new SaveInfo();
            this.DefaultSave.MapX    = 1000;
            this.DefaultSave.MapY    = 1000;
            this.DefaultSave.ScreenX = 0;
            this.DefaultSave.ScreenY = 0;
            this.DefaultSave.Powers  = new bool[12] {
                false, false, false, false, false, false, false, false, false, false, false, false
            };

            Screen start = new Screen(1000, 1000);

            this.Screens = new List <Screen>(1);
            this.Screens.Add(start);
            this.ActiveScreen = start;

            this.Patterns = new List <Pattern>();

            this.Save();
        }
Exemple #2
0
        public Story(string path)
        {
            this.Path = path;

            // Extract World.ini info.
            this.WorldIni    = new IniFile(this.Path + @"\World.ini");
            this.Author      = WorldIni.Read("World", "Author");
            this.Title       = WorldIni.Read("World", "Name");
            this.Description = WorldIni.Read("World", "Description");
            this.Size        = WorldIni.Read("World", "Size");
            this.CategoryA   = WorldIni.Read("World", "Category A");
            this.CategoryB   = WorldIni.Read("World", "Category B");
            this.DifficultyA = WorldIni.Read("World", "Difficulty A");
            this.DifficultyB = WorldIni.Read("World", "Difficulty B");
            this.DifficultyC = WorldIni.Read("World", "Difficulty C");

            try {
                int clothes = int.Parse(this.WorldIni.Read("World", "Clothes"));
                this.Clothes = Color.FromArgb(clothes & 0xFF, (clothes & 0xFF00) / 256, clothes / 65536); // Bit operations... best just move along.
            }
            catch (Exception) {
                this.Clothes = Program.Clothes;
            }
            try {
                int skin = int.Parse(this.WorldIni.Read("World", "Skin"));
                this.Skin = Color.FromArgb(skin & 0xFF, (skin & 0xFF00) / 256, skin / 65536);
            }
            catch (Exception) {
                this.Skin = Program.Skin;
            }

            // Extract DefaultSavegame.ini info.
            IniFile saveIni = new IniFile(this.Path + @"\DefaultSavegame.ini");

            this.DefaultSave         = new SaveInfo();
            this.DefaultSave.MapX    = Program.ParseInt(saveIni.Read("Positions", "X Map"), 1000);
            this.DefaultSave.MapY    = Program.ParseInt(saveIni.Read("Positions", "Y Map"), 1000);
            this.DefaultSave.ScreenX = Program.ParseInt(saveIni.Read("Positions", "X Pos"), 0);
            this.DefaultSave.ScreenY = Program.ParseInt(saveIni.Read("Positions", "Y Pos"), 0);
            this.DefaultSave.Powers  = new bool[12];
            for (int i = 0; i < 12; i++)
            {
                this.DefaultSave.Powers[i] = saveIni.Read("Powers", "Power" + i) == "1";
            }

            // Extract data from Map.bin.
            FileStream fileIn = File.OpenRead(this.Path + @"\Map.bin");

            Story_Crafter.MemoryStream data = new Story_Crafter.MemoryStream();
            GZipStream zipStream            = new GZipStream(fileIn, CompressionMode.Decompress);

            zipStream.CopyTo(data);
            zipStream.Close();
            fileIn.Close();
            data.Seek(0, SeekOrigin.Begin);

            // Load all the screens. 1000 screens currently take about 25 mb of memory not including thumbnails.
            this.Screens = new List <Screen>();
            try {
                Screen s = this.LoadScreen(data);
                while (s != null)
                {
                    this.Screens.Add(s);
                    s = this.LoadScreen(data);
                }
            }
            catch (Exception) {
                throw;
            }
            finally {
                GC.Collect();
                data.Close();
            }

            if (Screens.Count == 0)  // If there are no screens, create a blank one to start on.
            {
                Screen start = new Screen(1000, 1000);
                this.Screens.Add(start);
                this.ActiveScreen = start;
            }
            else
            {
                this.ActiveScreen = GetScreen(this.DefaultSave.MapX, this.DefaultSave.MapY); // Try the screen given as Juni's starting position.
                if (this.ActiveScreen == null)
                {
                    this.ActiveScreen = this.GetScreen(1000, 1000);                          // If that screen doesn't exist, try x1000y1000.
                    if (this.ActiveScreen == null)
                    {
                        this.ActiveScreen = this.Screens[0];                                 // If that doesn't exist either, use whatever the first screen in Map.bin is.
                    }
                }
            }

            // Load patterns
            this.Patterns = new List <Pattern>();
            try {
                using (FileStream patternsFile = new FileStream(this.Path + @"\.story_crafter_patterns", FileMode.Open, FileAccess.Read)) {
                    BinaryFormatter formatter = new BinaryFormatter();
                    Patterns = (List <Pattern>)formatter.Deserialize(patternsFile);
                }
            }
            catch {
                // TODO error message
            }
        }