Exemplo n.º 1
0
        protected override bool OnFileLoaded(XMLAsset <AnimatedSprite> file)
        {
            ResetEditors();
            _selectedAnimation = file.Content.Animations.First().Key;

            var assetFileLoaded = Engine.AssetLoader.Get <TextureAsset>(file.Content.AssetFile, false);

            _currentAssetTexture = assetFileLoaded?.Texture;
            _controller          = new SpriteAnimationController(file.Content);
            _controller.SetAnimation(_selectedAnimation);

            GLThread.ExecuteGLThreadAsync(() =>
            {
                if (_textureFb == null)
                {
                    _textureFb = new FrameBuffer(_currentAssetTexture.Size).WithColor();
                }
                else
                {
                    _textureFb.Resize(_currentAssetTexture.Size);
                }
            });

            // Patch legacy files
            foreach (KeyValuePair <string, SpriteAnimationData> anim in file.Content.Animations)
            {
                // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                if (anim.Value.FrameIndices == null)
                {
                    anim.Value.FrameIndices = Array.Empty <int>();
                }
            }

            return(true);
        }
Exemplo n.º 2
0
 private void NewFile()
 {
     _currentAsset    = CreateFile();
     _currentContent  = _currentAsset.Content;
     _currentFileName = null;
     _unsavedChanges  = false;
 }
Exemplo n.º 3
0
 private void LoadAnimationController(XMLAsset<AnimationController> f)
 {
     if (f?.Content == null) return;
     AnimController = f.Content;
     _spriteSheetTexture = AnimController.AnimTex.TextureAsset;
     Animation = AnimController.AnimTex;
     _saveName = f.Name;
     AnimController.SetAnimation(AnimController.Animations.First().Key);
 }
Exemplo n.º 4
0
        private void LoadAnimatedTexture(XMLAsset<AnimatedTexture> f)
        {
            if (f?.Content == null) return;

            AnimatedTexture anim = f.Content;
            _spriteSheetTexture = anim.TextureAsset;
            Animation = anim;
            AnimController = null;
            _saveName = f.Name;
        }
Exemplo n.º 5
0
 private void LoadAnimationController(XMLAsset <AnimationController> f)
 {
     if (f?.Content == null)
     {
         return;
     }
     _animController     = f.Content;
     _spriteSheetTexture = _animController.AnimTex.TextureAsset;
     _animation          = _animController.AnimTex;
     _saveName           = f.Name;
 }
Exemplo n.º 6
0
        protected override void RenderImGui()
        {
            base.RenderImGui();

            if (_currentAsset == null)
            {
                ImGui.Text("No file loaded. Click 'New' to start!");
                return;
            }

            XMLAsset <UIBaseWindow> asset  = _currentAsset;
            UIBaseWindow            window = asset.Content;

            // Initial selection.
            if (_selectedWindow == null)
            {
                SelectWindow(window);
                _ui.ClearChildren();
                _ui.AddChild(window);
            }

            if (ImGui.Button("Update Preview"))
            {
                _ui.ClearChildren();
                _ui.AddChild(window);
            }

            ImGui.SameLine();
            if (ImGui.Button("Delete Selected") && !_readonlyWindow)
            {
                var yesNoModal = new YesNoModalWindow("Delete Window", $"Are you sure you want to delete {_selectedWindow}?", result =>
                {
                    if (!result)
                    {
                        return;
                    }
                    UIBaseWindow parent = _selectedWindow.Parent;
                    parent !.RemoveChild(_selectedWindow);
                    SelectWindow(parent);
                    UnsavedChanges();
                    ImGui.CloseCurrentPopup();
                });
Exemplo n.º 7
0
        private void OpenFile()
        {
            var explorer = new FileExplorer <XMLAsset <T> >(asset =>
            {
                if (asset.Content == null)
                {
                    Engine.Log.Warning($"{asset.Name} asset couldn't be loaded. Maybe it is not of type {typeof(T)}.", "Tools");
                    return;
                }

                if (OnFileLoaded(asset))
                {
                    _currentAsset    = asset;
                    _currentContent  = asset.Content;
                    _currentFileName = asset.Name;
                    _unsavedChanges  = false;
                }
            });

            _toolsRoot.AddLegacyWindow(explorer);
        }
Exemplo n.º 8
0
        public void AssetStorage()
        {
            var save = Engine.AssetLoader.Get <XMLAsset <TestStorage> >("saveFile.save");

            Assert.True(save == null);

            var saveFilePath = "Player/saveFile.save";
            XMLAsset <TestStorage> saveFile = XMLAsset <TestStorage> .LoadSaveOrCreate(saveFilePath);

            Assert.True(File.Exists(Path.Join(".", "Player", "savefile.save")));
            Assert.True(Engine.AssetLoader.Exists(saveFilePath));

            saveFile.Content.Text = "Wassaa";
            saveFile.Save();

            // It will now exist!
            save = Engine.AssetLoader.Get <XMLAsset <TestStorage> >("Player/saveFile.save");
            Assert.Equal(save.Content.Text, saveFile.Content.Text);
            Engine.AssetLoader.Destroy(saveFilePath);

            saveFile.Save();
            Assert.True(File.Exists(Path.Join("./Player", "savefile.save.backup")));
        }
Exemplo n.º 9
0
 protected override bool OnFileLoaded(XMLAsset <TextAsset> file)
 {
     return(true);
 }
Exemplo n.º 10
0
 protected abstract bool OnFileLoaded(XMLAsset <T> file);
Exemplo n.º 11
0
        protected virtual XMLAsset <T> CreateFile()
        {
            var newT = Activator.CreateInstance <T>();

            return(XMLAsset <T> .CreateFromContent(newT));
        }