Exemple #1
0
        /// <summary>
        /// Generates a GopherField from a RawField class.
        /// </summary>
        /// <returns></returns>
        private GopherField GenerateField()
        {
            Gopher.ProgressCallback("Generating field node tree...");
            var rootMeshes = FindRoots();
            var rootNodes  = new List <GopherFieldNode>();

            //Turn meshes into nodes
            foreach (var mesh in rootMeshes)
            {
                rootNodes.Add(new GopherFieldNode
                {
                    Mesh  = mesh,
                    Level = 0
                });
            }

            //Prepare GopherField object for population
            GopherField ret = new GopherField
            {
                RootNodes = rootNodes
            };

            //Population objects
            List <GopherFieldNode> ThisLevel = ret.RootNodes;
            List <GopherFieldNode> NextLevel = new List <GopherFieldNode>();
            bool DoContinue = true;

            //Populating nodes
            do
            {
                DoContinue = PopulateNodes(ThisLevel, out NextLevel);
                ThisLevel  = new List <GopherFieldNode>();
                ThisLevel  = NextLevel;
                NextLevel  = new List <GopherFieldNode>();
            }while (DoContinue);

            //Add colliders, generate top level collider list, and remove redundencies
            foreach (var node in ret.ListAllNodes())
            {
                if (node.Mesh.AttributeID == uint.MaxValue)
                {
                    node.Collider = ret.Colliders[0];
                }
                else
                {
                    var col = field.GetCollider(node.Mesh.AttributeID);
                    col.Nephews.Add(node);
                    node.Collider = col;
                    ret.Colliders.Add(col);
                }
            }
            Gopher.ProgressCallback("Generating field node tree...DONE");
            return(ret);
        }
 /// <summary>
 /// Loads given file into memory
 /// </summary>
 /// <param name="path">The file to be opened</param>
 internal GopherReader_Base(string path)
 {
     if (Path.GetExtension(path).ToLower() != ".field" || Path.GetExtension(path).ToLower() != ".robot")
     {
         throw new ArgumentException("ERROR: path given was not a field or robot file", "path");
     }
     Gopher.ProgressCallback("Loading " + Path.GetFileName(path) + "into memory");
     using (var reader = new BinaryReader(new FileStream(path, FileMode.Open)))
     {
         rawFile = reader.ReadBytes((int)reader.BaseStream.Length);
     }
 }
Exemple #3
0
    /*
     * Method to spawn a gopher
     * Instantiates spawn particle effect, Instantiates a new Gopher, gives it a random lifetime from defined values in LevelOneData SO
     */
    private void SpawnGopher()
    {
        if (_hasGopher)
        {
            return;
        }
        int index = ChooseGopher();                                                       // Select a random gopher to spawn based on passed values in inspector

        Instantiate(spawnParticleEffect, spawnPoint);                                     // Instantiate a spawn particle effect
        _currentGopher          = Instantiate(gopherPrefabs[index], spawnPoint);          // Instantiate a Gopher gameObject at the same location as this spawner
        _currentGopher.Lifetime = Random.Range(MinGopherLifetime, MaxGopherLifetime);
        _hasGopher = true;                                                                // After Instantiating a gopher, the spawner now has an active gopher
    }
Exemple #4
0
        private GopherRobot GenerateRobot()
        {
            AssignDrivers();
            Gopher.ProgressCallback("Generating robot node tree...");
            var rootMeshes = FindRoots();
            var rootNodes  = new List <GopherRobotNode>();

            //Turn meshes into nodes
            foreach (var mesh in rootMeshes)
            {
                rootNodes.Add(new GopherRobotNode
                {
                    Mesh  = mesh,
                    Level = 0
                });
            }

            //Prepare GopherRobot object for population
            var ret = new GopherRobot
            {
                RootNodes = rootNodes
            };

            //Population objects
            List <GopherRobotNode> ThisLevel = ret.RootNodes;
            List <GopherRobotNode> NextLevel = new List <GopherRobotNode>();
            bool DoContinue = true;

            //Populating nodes
            do
            {
                DoContinue = PopulateNodes(ThisLevel, out NextLevel);
                ThisLevel  = new List <GopherRobotNode>();
                ThisLevel  = NextLevel;
                NextLevel  = new List <GopherRobotNode>();
            }while (DoContinue);
            Gopher.ProgressCallback("Generating robot node tree...DONE");
            return(ret);
        }
        public void NavigateGopherScheme(string fullQuery, System.Windows.Navigation.NavigatingCancelEventArgs e, SiteIdentity siteIdentity)
        {
            var sessionPath = Session.Instance.SessionPath;
            var appDir      = AppDomain.CurrentDomain.BaseDirectory;

            //check if it is a query selector without a parameter
            if (!e.Uri.OriginalString.Contains("%09") && e.Uri.PathAndQuery.StartsWith("/7/"))
            {
                NavigateGopherWithInput(e);

                mMainWindow.ToggleContainerControlsForBrowser(true);

                //no further navigation right now
                e.Cancel = true;

                return;
            }

            var settings = new UserSettings();

            var hash = HashService.GetMd5Hash(fullQuery);

            //uses .txt as extension so content loaded as text/plain not interpreted by the browser
            //if user requests a view-source.
            var gopherFile = sessionPath + "\\" + hash + ".txt";
            var gmiFile    = sessionPath + "\\" + hash + ".gmi";
            var htmlFile   = sessionPath + "\\" + hash + ".htm";

            //delete txt file as GemGet seems to sometimes overwrite not create afresh
            File.Delete(gopherFile);

            //delete any existing html file to encourage webbrowser to reload it
            File.Delete(gmiFile);

            //get the content from Gopher using SmolNetSharp
            IResponse response;

            try
            {
                response = Gopher.Fetch(new Uri(fullQuery), settings.MaxDownloadSizeMb * 1024, settings.MaxDownloadTimeSeconds);

                File.WriteAllBytes(gopherFile, response.bytes.ToArray());
            }
            catch (Exception err)
            {
                mMainWindow.ToastNotify(err.Message, ToastMessageStyles.Error);
                mMainWindow.ToggleContainerControlsForBrowser(true);    //reenable browser
                e.Cancel = true;
                return;
            }

            var mime = response.mime;
            Tuple <int, string, string> result;

            if (File.Exists(gopherFile))
            {
                string parseFile;

                if (mime == "application/gopher-menu")
                {
                    //convert gophermap to text/gemini

                    //ToastNotify("Converting gophermap to " + gmiFile);
                    result    = ConverterService.GophertoGmi(gopherFile, gmiFile, fullQuery, GopherParseTypes.Map);
                    parseFile = gmiFile;
                }
                else if (mime == "text/plain")
                {
                    result    = ConverterService.GophertoGmi(gopherFile, gmiFile, fullQuery, GopherParseTypes.Text);
                    parseFile = gmiFile;
                }
                else
                {
                    //a download

                    //copy to a file having its source extension
                    var pathFragment = (new UriBuilder(fullQuery)).Path;
                    var ext          = Path.GetExtension(pathFragment);

                    var binFile = gopherFile + (ext ?? "");

                    File.Copy(gopherFile, binFile, true); //rename overwriting

                    if (mime == "image/png" || mime == "image/gif" || mime == "image/jpeg")
                    {
                        //show the image
                        mMainWindow.ShowImage(fullQuery, binFile, e);
                    }
                    else
                    {
                        //show a save as dialog
                        SaveFileDialog saveFileDialog = new SaveFileDialog();

                        saveFileDialog.FileName = Path.GetFileName(pathFragment);

                        if (saveFileDialog.ShowDialog() == true)
                        {
                            try
                            {
                                //save the file
                                var savePath = saveFileDialog.FileName;

                                File.Copy(binFile, savePath, true); //rename overwriting

                                mMainWindow.ToastNotify("File saved to " + savePath, ToastMessageStyles.Success);
                            }
                            catch (SystemException err)
                            {
                                mMainWindow.ToastNotify("Could not save the file due to: " + err.Message, ToastMessageStyles.Error);
                            }
                        }

                        mMainWindow.ToggleContainerControlsForBrowser(true);
                        e.Cancel = true;
                    }

                    return;
                }

                if (!File.Exists(gmiFile) || result.Item1 != 0)
                {
                    mMainWindow.ToastNotify("Did not create expected GMI file for " + fullQuery + " in " + gmiFile, ToastMessageStyles.Error);
                    mMainWindow.ToggleContainerControlsForBrowser(true);
                    e.Cancel = true;
                }
                else
                {
                    var userThemesFolder = ResourceFinder.LocalOrDevFolder(appDir, @"GmiConverters\themes", @"..\..\..\GmiConverters\themes");

                    var userThemeBase = Path.Combine(userThemesFolder, settings.Theme);

                    mMainWindow.ShowUrl(fullQuery, parseFile, htmlFile, userThemeBase, siteIdentity, e);
                }
            }
        }