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); }
private void NewFile() { _currentAsset = CreateFile(); _currentContent = _currentAsset.Content; _currentFileName = null; _unsavedChanges = false; }
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); }
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; }
private void LoadAnimationController(XMLAsset <AnimationController> f) { if (f?.Content == null) { return; } _animController = f.Content; _spriteSheetTexture = _animController.AnimTex.TextureAsset; _animation = _animController.AnimTex; _saveName = f.Name; }
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(); });
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); }
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"))); }
protected override bool OnFileLoaded(XMLAsset <TextAsset> file) { return(true); }
protected abstract bool OnFileLoaded(XMLAsset <T> file);
protected virtual XMLAsset <T> CreateFile() { var newT = Activator.CreateInstance <T>(); return(XMLAsset <T> .CreateFromContent(newT)); }