Ejemplo n.º 1
0
        public static Sprite NewSprite(Pathfinder path, TextureLibrary textureLibrary)
        {
            _Sprite _sprite = JsonHelper <_Sprite> .Load(path.Path);

            _sprite.Finalize(textureLibrary, path);
            Sprite sprite = _sprite.Solidify();

            return(sprite);
        }
Ejemplo n.º 2
0
        public static void Initialize(string gameName, string companyName, Game game, GraphicsDeviceManager graphicsManager)
        {
            GameName        = gameName;
            CompanyName     = companyName;
            Game            = game;
            GraphicsManager = graphicsManager;
            GlobalContent   = game.Content;
            SpriteBatch     = new SpriteBatch(game.GraphicsDevice);

            ContentDirectory = "Content";
#if DEBUG
            ContentDirectory = Path.Combine("..", "..", "..", "..", "Content");
#endif
            //GlobalContent.RootDirectory = Path.Combine(System.IO.Directory.GetCurrentDirectory(), ContentDirectory);
            //System.Diagnostics.Debug.WriteLine(Path.GetFullPath(ContentDirectory));
            // TODO: How does this perform on linux? (And any other target OS.)
            //SaveDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "My Games", gameName);
            if (companyName == null || companyName == "")
            {
                SaveDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), gameName);
            }
            else
            {
                SaveDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), companyName, gameName);
            }
            // TODO: Set up a way for apps to specify whether to use a global or user-specific save location.
            //SaveDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), gameName);
            // Probably don't need to support Roaming data.
            // Ugh, should I wash input and output so that backslashes in custom content don't break linux?
            // Path.DirectorySeparatorChar
            Directory.CreateDirectory(SaveDirectory);

            /*
             * string configPath = Path.Combine(SaveDirectory, "config.xml");
             * if (!File.Exists(configPath))
             *  File.Create(configPath).Dispose();
             */

            Util.Error.StartLog();

            string extensionPath = GetSaveDirectory("Extensions");
            Directory.CreateDirectory(extensionPath);
            ExtensionDirectories = new List <string>();

/*
 #if DEBUG
 *          // In debug builds, also check the content folder in the root directory of the project.
 *          // For the sake of lightweight history, this volatile folder is excluded from the repository.
 *          ExtensionDirectories.Add(Path.Combine("..", "..", "..", "..", "..", "Content"));
 #endif
 */
            // TODO: As a debug, all extensions are automatically loaded. I'm not certain what the final behaviour
            //   should be.
            foreach (string folder in Directory.GetDirectories(extensionPath))
            {
                //ExtensionDirectories.Add(Path.GetFileName(folder));
                ExtensionDirectories.Add(folder);
            }
            // TODO: Make sure extension folder names only include _0-9A-Za-z

/*
 #if DEBUG
 *          System.Diagnostics.Debug.WriteLine("Pathfinder test:");
 *          System.Diagnostics.Debug.WriteLine(Pathfinder.Find("ball", "sprites", Pathfinder.FileType.image).Path);
 *          System.Diagnostics.Debug.WriteLine(Pathfinder.Find("ball", "spriteconfigs", Pathfinder.FileType.xml).Path);
 *          Pathfinder pf = Pathfinder.Find("kraken:/round/ball2", "sprites", Pathfinder.FileType.image);
 *          System.Diagnostics.Debug.WriteLine(pf.Path);
 *          System.Diagnostics.Debug.WriteLine(Pathfinder.Find("../rootball", "spriteconfigs", Pathfinder.FileType.xml, pf).Path);
 *          System.Diagnostics.Debug.WriteLine(Pathfinder.Find("superball", "spriteconfigs", Pathfinder.FileType.xml, pf).Path);
 #endif
 */
            GlobalRandom = new Random();

            Libraries.TextureLibrary.Initialize();
            Libraries.SpriteLibrary.Initialize();
            Libraries.FontLibrary.Initialize();
            Libraries.SongLibrary.Initialize();
            Libraries.SoundEffectLibrary.Initialize();

            GlobalTextures = new Libraries.TextureLibrary();
            Libraries.TextureLibrary.AddLibrary(GlobalTextures);

            GlobalSprites = new Libraries.SpriteLibrary(GlobalTextures);
            Libraries.SpriteLibrary.AddLibrary(GlobalSprites);

            GlobalFonts = new Libraries.FontLibrary();
            Libraries.FontLibrary.AddLibrary(GlobalFonts);

            GlobalSongs = new Libraries.SongLibrary();
            Libraries.SongLibrary.AddLibrary(GlobalSongs);

            GlobalSoundEffects = new Libraries.SoundEffectLibrary();
            Libraries.SoundEffectLibrary.AddLibrary(GlobalSoundEffects);

            InputManager = new Input.InputManager(GetSaveDirectory("inputconfig.json"));

            TextHandler = new Input.TextHandler();
        }
Ejemplo n.º 3
0
        public void Finalize(TextureLibrary textureLibrary, Pathfinder defaultPath)
        {
            Pathfinder.SetCurrentPath(defaultPath);

            if (DefaultFrame == null)
            {
                DefaultFrame = new _FrameRange();
            }
            if (DefaultFrame.Spritesheet != null)
            {
                DefaultFrame.Texture = textureLibrary.Register(DefaultFrame.Spritesheet);
            }
            if (DefaultFrame.X == null)
            {
                DefaultFrame.X = 0;
            }
            if (DefaultFrame.Y == null)
            {
                DefaultFrame.Y = 0;
            }
            if (DefaultFrame.Texture != null)
            {
                if (DefaultFrame.Width == null)
                {
                    DefaultFrame.Width = DefaultFrame.Texture.Width;
                }
                if (DefaultFrame.Height == null)
                {
                    DefaultFrame.Height = DefaultFrame.Texture.Height;
                }
            }
            else
            {
                DefaultFrame.Width  = 0;
                DefaultFrame.Height = 0;
            }
            if (DefaultFrame.AnchorX == null)
            {
                DefaultFrame.AnchorX = 0f;
            }
            if (DefaultFrame.AnchorY == null)
            {
                DefaultFrame.AnchorY = 0f;
            }
            if (DefaultFrame.Count == null)
            {
                DefaultFrame.Count = 1;
            }
            if (DefaultFrame.Frametime == null)
            {
                DefaultFrame.Frametime = 1f;
            }

            if (Animations == null)
            {
                Animations = new List <_Animation>(new _Animation[] { new _Animation() });
            }
            foreach (_Animation animation in Animations)
            {
                if (animation.Name == null)
                {
                    animation.Name = "default";
                }
                if (animation.Speed == null)
                {
                    animation.Speed = 1f;
                }
                if (animation.FrameRanges == null)
                {
                    animation.FrameRanges = new List <_FrameRange>();
                    animation.FrameRanges.Add(DefaultFrame);
                }
                else
                {
                    foreach (_FrameRange frame in animation.FrameRanges)
                    {
                        if (frame.Spritesheet == null)
                        {
                            frame.Spritesheet = DefaultFrame.Spritesheet;
                            frame.Texture     = DefaultFrame.Texture;
                        }
                        else
                        {
                            frame.Texture = textureLibrary.Register(frame.Spritesheet);
                        }
                        if (frame.X == null)
                        {
                            frame.X = DefaultFrame.X;
                        }
                        if (frame.Y == null)
                        {
                            frame.Y = DefaultFrame.Y;
                        }
                        if (frame.Width == null)
                        {
                            frame.Width = DefaultFrame.Width;
                        }
                        if (frame.Height == null)
                        {
                            frame.Height = DefaultFrame.Height;
                        }
                        if (frame.AnchorX == null)
                        {
                            frame.AnchorX = DefaultFrame.AnchorX;
                        }
                        if (frame.AnchorY == null)
                        {
                            frame.AnchorY = DefaultFrame.AnchorY;
                        }
                        if (frame.Count == null)
                        {
                            frame.Count = DefaultFrame.Count;
                        }
                        if (frame.Frametime == null)
                        {
                            frame.Frametime = 1f;                          // Do not inherit this from DefaultFrame.
                        }
                    }
                }

                if (DefaultAnimation == null)
                {
                    DefaultAnimation = animation.Name;
                }
            }

            Pathfinder.ClearCurrentPath(); // TODO: This develops loose ends too easily.
        }
Ejemplo n.º 4
0
 public SpriteLibrary(TextureLibrary textureLibrary)
 {
     this.textureLibrary = textureLibrary;
 }