Example #1
0
        private void BuildPuzzleThread(PuzzleConfig config, Action <Puzzle> finishBuild, Action <Puzzle> finishLoad)
        {
            Puzzle puzzle = new Puzzle();

            try
            {
                if (config != null)
                {
                    puzzle.Config = config;
                }
                puzzle.Build(this);
            }
            catch (System.Exception)
            {
                puzzle = null;
                ExecuteOnThisThread(() => InformationMessage("Build Failure", "So sorry, there was a puzzle build failure."));
            }

            try
            {
                if (finishLoad != null)
                {
                    finishLoad(puzzle);
                }
            }
            catch (System.Exception)
            {
                puzzle = null;
                ExecuteOnThisThread(() => InformationMessage("Load Failure", "So sorry, there was a loading failure."));
            }
            finally
            {
                finishBuild(puzzle);
            }
        }
Example #2
0
        /// <summary>
        /// I had to change persistence for ET and VT puzzles.
        /// This will load the saved file version into the passed in puzzle config,
        /// so we can build the puzzle in a backward compatible way if needed.
        /// </summary>
        public static void SetVersionOnConfig(PuzzleConfig puzzleConfig, XElement root)
        {
            XAttribute xVersion = root.Attribute("Version");

            if (xVersion == null)
            {
                puzzleConfig.Version = VersionPreview;
            }
            puzzleConfig.Version = xVersion.Value;
        }
Example #3
0
        private void menuPuzzle_Click(object sender, EventArgs e)
        {
            if (!this.AllowUI)
            {
                return;
            }

            ToolStripMenuItem item   = (ToolStripMenuItem)sender;
            PuzzleConfig      config = (PuzzleConfig)item.Tag;

            BuildPuzzle(config);
        }
Example #4
0
        private void BuildPuzzle(PuzzleConfig config, Action <Puzzle> finishLoad)
        {
            Log.Message("Building Puzzle...");
            m_cancel = new CancellationTokenSource();
            m_renderer.WaitRadius = 0;
            m_renderer.ResetView();

            m_built = false;
            m_buildTimer.Enabled = true;
            WaitCursor();
            m_task = Task.Factory.StartNew(() => BuildPuzzleThread(config, this.FinishBuild, finishLoad), m_cancel.Token);
        }
Example #5
0
 /// <summary>
 /// NOTE: filePath is relative to the base puzzle directory.
 /// </summary>
 public static void Save(PuzzleConfig config, string filePath)
 {
     try
     {
         string fullPath = Path.GetFullPath(Path.Combine(StandardPaths.ConfigDir, filePath));
         Directory.CreateDirectory(Path.GetDirectoryName(fullPath));
         DataContractHelper.SaveToXml(config, fullPath);
     }
     catch (System.Exception e)
     {
         string message = string.Format("Failed to save puzzle config.\n{0}", e.Message);
         Log.Error(message);
     }
 }
Example #6
0
        /// <summary>
        /// All the puzzles we represent.
        /// </summary>
        public void GetPuzzles(out PuzzleConfig tiling, out PuzzleConfig[] face, out PuzzleConfig[] edge,
                               out PuzzleConfig[] vertex, out PuzzleConfig[] mixed, out PuzzleConfig[] earthquake)
        {
            tiling                = NonSpecific();
            tiling.MenuName       = "Tiling";
            tiling.DisplayName    = this.ClassDisplayName + " " + tiling.MenuName;
            tiling.SlicingCircles = null;

            List <PuzzleConfig> puzzles = new List <PuzzleConfig>();

            foreach (PuzzleSpecific puzzleSpecific in this.PuzzleSpecificList)
            {
                PuzzleConfig config = NonSpecific();

                // Specific stuff.
                config.SlicingCircles = puzzleSpecific.SlicingCircles;
                config.Earthquake     = puzzleSpecific.Earthquake;

                // NOTE: I decided to not propagate old IDs for edge or vertex turning puzzles.
                //		 We won't be able to load preview version macros for these anyway,
                //		 due to the build/persistence changes from 2.0 -> 2.1
                if (string.IsNullOrEmpty(puzzleSpecific.ID) || config.EdgeOrVertexTwisting)
                {
                    config.ID = this.ClassID + " " + puzzleSpecific.AutoUniqueId();
                }
                else
                {
                    config.ID = puzzleSpecific.ID;
                }

                if (string.IsNullOrEmpty(puzzleSpecific.DisplayName))
                {
                    config.MenuName = puzzleSpecific.AutoDisplayName();
                }
                else
                {
                    config.MenuName = puzzleSpecific.DisplayName + " (" + puzzleSpecific.AutoDisplayName() + ")";
                }
                config.DisplayName = this.ClassDisplayName + " " + config.MenuName;

                puzzles.Add(config);
            }

            face       = puzzles.Where(p => p.SlicingCircles.FaceTwisting && !p.SlicingCircles.EdgeTwisting && !p.SlicingCircles.VertexTwisting).ToArray();
            edge       = puzzles.Where(p => !p.SlicingCircles.FaceTwisting && p.SlicingCircles.EdgeTwisting && !p.SlicingCircles.VertexTwisting).ToArray();
            vertex     = puzzles.Where(p => !p.SlicingCircles.FaceTwisting && !p.SlicingCircles.EdgeTwisting && p.SlicingCircles.VertexTwisting).ToArray();
            earthquake = puzzles.Where(p => p.Earthquake).ToArray();
            mixed      = puzzles.Except(face).Except(edge).Except(vertex).Except(earthquake).ToArray();
        }
Example #7
0
        public void LoadFromFile(System.Action <PuzzleConfig, System.Action <Puzzle> > buildPuzzle)
        {
            string fileName = GetLoadFileNameInternal();

            if (!File.Exists(fileName))
            {
                return;
            }

            XDocument    xDocument = XDocument.Load(fileName);
            XElement     xConfig   = xDocument.Root.Element("PuzzleConfig");
            PuzzleConfig config    = (PuzzleConfig)DataContractHelper.LoadFromString(typeof(PuzzleConfig), xConfig.ToString());

            SetVersionOnConfig(config, xDocument.Root);
            System.Action <Puzzle> finishLoad = p => LoadStateAndHistoryAndMacros(xDocument, p);
            buildPuzzle(config, finishLoad);
        }
Example #8
0
        private PuzzleConfig NonSpecific()
        {
            PuzzleConfig config = new PuzzleConfig();

            // Non-specific stuff.
            config.P                 = this.P;
            config.Q                 = this.Q;
            config.TileShrink        = this.TileShrink;
            config.Identifications   = this.Identifications;
            config.ExpectedNumColors = this.ExpectedNumColors;
            config.NumTiles          = this.NumTiles;
            config.SurfaceConfig     = this.SurfaceConfig;
            config.IRPConfig         = this.IRPConfig;
            config.Skew4DConfig      = this.Skew4DConfig;

            return(config);
        }
Example #9
0
        private void m_puzzleTree_DoubleClick(object sender, EventArgs e)
        {
            if (!this.AllowUI)
            {
                return;
            }

            TreeNode selected = m_puzzleTree.SelectedNode;

            if (selected == null || selected.Tag == null)
            {
                return;
            }

            PuzzleConfig config = (PuzzleConfig)selected.Tag;

            BuildPuzzle(config);
        }
Example #10
0
 private XElement SaveConfig(PuzzleConfig config)
 {
     return(XElement.Parse(DataContractHelper.SaveToString(config)));
 }
Example #11
0
 private void BuildPuzzle(PuzzleConfig config)
 {
     BuildPuzzle(config, null);
 }