Exemple #1
0
        public static void InitializeLogger()
        {
            try
            {
                Trace.Listeners.Clear();
                var dir = GetGameDirectory();
                if (!System.IO.Directory.Exists(dir))
                {
                    System.IO.Directory.CreateDirectory(dir);
                }
                var path = ProgramData.CreatePath(dir, "log.txt");
                if (!File.Exists(path))
                {
                    File.Create(path).Close();
                }

                FileStream writerOutput = new FileStream(ProgramData.CreatePath(dir, "log.txt"), FileMode.Append, FileAccess.Write);
                _logwriter = new StreamWriter(writerOutput)
                {
                    AutoFlush = true
                };
                Console.SetOut(_logwriter);
                Console.SetError(_logwriter);
                Console.Out.WriteLine("Game started at " + DateTime.Now.ToShortDateString() + " : " + DateTime.Now.ToShortTimeString());
            }
            catch (Exception exception)
            {
                Console.Error.WriteLine("Failed to initialize logger: {0}", exception.ToString());
            }
        }
Exemple #2
0
        public static void InitializeLogger()
        {
            try
            {
                Trace.Listeners.Clear();
                var dir = GetGameDirectory();
                if (!System.IO.Directory.Exists(dir))
                {
                    System.IO.Directory.CreateDirectory(dir);
                }
                var path = ProgramData.CreatePath(dir, "log.txt");
                if (!File.Exists(path))
                {
                    File.Create(path).Close();
                }

                var logFile = new FileInfo(path);
                if (logFile.Length > 5e7)
                {
                    Console.Out.WriteLine("Log file at {0} was too large ({1} bytes). Clearing it.", path, logFile.Length);
                    System.IO.File.WriteAllText(path, string.Empty);
                }
                FileStream writerOutput = new FileStream(path, FileMode.Append, FileAccess.Write);
                _logwriter    = new LogWriter(writerOutput);
                _initialOut   = Console.Out;
                _initialError = Console.Error;
                Console.SetOut(_logwriter);
                Console.SetError(_logwriter);
                Console.Out.WriteLine("Game started at " + DateTime.Now.ToShortDateString() + " : " + DateTime.Now.ToShortTimeString());
            }
            catch (Exception exception)
            {
                Console.Error.WriteLine("Failed to initialize logger: {0}", exception.ToString());
            }
        }
Exemple #3
0
        public static void LoadTemplates()
        {
            string dirname = "." + Path.DirectorySeparatorChar + "Content" + Path.DirectorySeparatorChar + "Text" + Path.DirectorySeparatorChar + "Templates";

            global::System.IO.DirectoryInfo directoryInfo = new DirectoryInfo(dirname);

            if (!directoryInfo.Exists)
            {
                throw new FileNotFoundException("Unable to find text directory : " + dirname);
            }

            foreach (global::System.IO.FileInfo info in directoryInfo.EnumerateFiles())
            {
                var match = Regex.Match(info.Name, @"(.*)\.txt");

                if (match.Success)
                {
                    Templates["$" + match.Groups[1].Value] = GetAtoms(ProgramData.CreatePath("Text", "Templates", match.Groups[1].Value + ".txt"));
                }
            }
        }
Exemple #4
0
        public void Initialize(GraphicsDevice graphics, ContentManager content)
        {
            if (!m_initialized)
            {
                Texture2D spriteSheet = TextureManager.GetTexture(ContentPaths.Entities.Furniture.bedtex);
                OldBoxPrimitive.BoxTextureCoords boxCoords = new OldBoxPrimitive.BoxTextureCoords(spriteSheet.Width, spriteSheet.Height,
                                                                                                  new OldBoxPrimitive.FaceData(new Rectangle(0, 24, 24, 16), true),
                                                                                                  new OldBoxPrimitive.FaceData(new Rectangle(72, 24, 24, 16), true),
                                                                                                  new OldBoxPrimitive.FaceData(new Rectangle(24, 0, 48, 24), false),
                                                                                                  new OldBoxPrimitive.FaceData(new Rectangle(0, 0, 1, 1), true),
                                                                                                  new OldBoxPrimitive.FaceData(new Rectangle(24, 24, 48, 16), true),
                                                                                                  new OldBoxPrimitive.FaceData(new Rectangle(24, 40, 48, 16), true));
                BoxPrimitives["bed"] = new OldBoxPrimitive(graphics, 0.8f, 0.5f, 1.8f, boxCoords);

                Texture2D bookSheet = TextureManager.GetTexture(ContentPaths.Entities.Furniture.bookshelf);
                OldBoxPrimitive.BoxTextureCoords bookshelfTexture = new OldBoxPrimitive.BoxTextureCoords(bookSheet.Width, bookSheet.Height,
                                                                                                         new OldBoxPrimitive.FaceData(new Rectangle(0, 20, 20, 32), true),
                                                                                                         new OldBoxPrimitive.FaceData(new Rectangle(28, 20, 20, 32), true),
                                                                                                         new OldBoxPrimitive.FaceData(new Rectangle(20, 0, 8, 20), false),
                                                                                                         new OldBoxPrimitive.FaceData(new Rectangle(0, 0, 1, 1), true),
                                                                                                         new OldBoxPrimitive.FaceData(new Rectangle(20, 20, 8, 32), true),
                                                                                                         new OldBoxPrimitive.FaceData(new Rectangle(20, 52, 8, 32), true));
                BoxPrimitives["bookshelf"] = new OldBoxPrimitive(graphics, 20.0f / 32.0f, 32.0f / 32.0f, 8.0f / 32.0f, bookshelfTexture);

                m_initialized = false;


                Texture2D sheetTiles = TextureManager.GetTexture(ContentPaths.Terrain.terrain_tiles);
                OldBoxPrimitive.BoxTextureCoords crateCoords = new OldBoxPrimitive.BoxTextureCoords(sheetTiles.Width, sheetTiles.Height, 32, 32,
                                                                                                    new Point(7, 0),
                                                                                                    new Point(7, 0),
                                                                                                    new Point(8, 0),
                                                                                                    new Point(7, 0),
                                                                                                    new Point(7, 0),
                                                                                                    new Point(7, 0));
                BoxPrimitives["crate"] = new OldBoxPrimitive(graphics, 0.9f, 0.9f, 0.9f, crateCoords);
                m_initialized          = false;

                Texture2D     treeSheet      = TextureManager.GetTexture(ContentPaths.Entities.Plants.pine);
                Texture2D     snowpineSheet  = TextureManager.GetTexture(ContentPaths.Entities.Plants.snowpine);
                Texture2D     palmSheet      = TextureManager.GetTexture(ContentPaths.Entities.Plants.palm);
                List <Matrix> treeTransforms = new List <Matrix>();
                List <Color>  treeTints      = new List <Color>();
                treeTransforms.Add(Matrix.Identity);
                treeTransforms.Add(Matrix.CreateRotationY(1.57f));
                treeTints.Add(Color.White);
                treeTints.Add(Color.White);

                BatchBillboardPrimitives["pine"]     = new BatchBillboardPrimitive(graphics, treeSheet, treeSheet.Width, treeSheet.Height, new Point(0, 0), treeSheet.Width / 32.0f, treeSheet.Height / 32.0f, false, treeTransforms, treeTints);
                BatchBillboardPrimitives["snowpine"] = new BatchBillboardPrimitive(graphics, snowpineSheet, snowpineSheet.Width, snowpineSheet.Height, new Point(0, 0), snowpineSheet.Width / 32.0f, snowpineSheet.Height / 32.0f, false, treeTransforms, treeTints);
                BatchBillboardPrimitives["palm"]     = new BatchBillboardPrimitive(graphics, palmSheet, palmSheet.Width, palmSheet.Height, new Point(0, 0), palmSheet.Width / 32.0f, palmSheet.Height / 32.0f, false, treeTransforms, treeTints);



                List <string> motes = new List <string>
                {
                    "berrybush",
                    "frostgrass",
                    "flower",
                    "grass",
                    "deadbush",
                    "mushroom",
                    "vine",
                    "gnarled"
                };

                foreach (string mote in motes)
                {
                    CreateIntersecting(mote, ProgramData.CreatePath("Entities", "Plants", mote), graphics, content);
                }
            }
        }