mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-09 17:47:43 +00:00
YAML read/write refactor
This commit is contained in:
@@ -2,12 +2,13 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_subdirectory(locale)
|
||||
|
||||
atdna(atdna_Space.cpp Space.hpp)
|
||||
atdna(atdna_ResourceOutliner.cpp ResourceOutliner.hpp)
|
||||
|
||||
add_executable(rude WIN32
|
||||
main.cpp
|
||||
Space.hpp Space.cpp atdna_Space.cpp
|
||||
SplashScreen.hpp SplashScreen.cpp
|
||||
ResourceOutliner.hpp ResourceOutliner.cpp
|
||||
ResourceOutliner.hpp ResourceOutliner.cpp atdna_ResourceOutliner.cpp
|
||||
ProjectManager.hpp ProjectManager.cpp
|
||||
ViewManager.hpp ViewManager.cpp)
|
||||
|
||||
@@ -17,8 +18,8 @@ target_link_libraries(rude
|
||||
RuntimeCommonInput
|
||||
RuntimeCommon
|
||||
DNAMP3 DNAMP2 DNAMP1
|
||||
DNACommon Specter SpecterFonts freetype
|
||||
HECLDatabase HECLBlender HECLRuntime HECLCommon AthenaCore NOD
|
||||
DNACommon Specter SpecterFonts freetype ${DATA_SPEC_LIBS}
|
||||
HECLDatabase HECLBackend HECLFrontend HECLBlender HECLRuntime HECLCommon AthenaCore NOD
|
||||
LogVisor AthenaLibYaml Boo ${PNG_LIB} squish xxhash Math
|
||||
${ZLIB_LIBRARIES} ${LZO_LIB}
|
||||
${BOO_SYS_LIBS})
|
||||
|
||||
@@ -1,6 +1,69 @@
|
||||
#include "ProjectManager.hpp"
|
||||
#include "ViewManager.hpp"
|
||||
#include "../DataSpecRegistry.hpp"
|
||||
|
||||
namespace RUDE
|
||||
{
|
||||
static LogVisor::LogModule Log("RUDE::ProjectManager");
|
||||
|
||||
bool ProjectManager::m_registeredSpecs = false;
|
||||
ProjectManager::ProjectManager(ViewManager &vm)
|
||||
: m_vm(vm)
|
||||
{
|
||||
if (!m_registeredSpecs)
|
||||
{
|
||||
HECLRegisterDataSpecs();
|
||||
m_registeredSpecs = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool ProjectManager::newProject(const HECL::SystemString& path)
|
||||
{
|
||||
HECL::ProjectRootPath projPath = HECL::SearchForProject(path);
|
||||
if (projPath)
|
||||
{
|
||||
Log.report(LogVisor::Warning, _S("project already exists at '%s'"), path.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
m_proj.reset(new HECL::Database::Project(path));
|
||||
if (!*m_proj)
|
||||
{
|
||||
m_proj.reset();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProjectManager::openProject(const HECL::SystemString& path)
|
||||
{
|
||||
HECL::ProjectRootPath projPath = HECL::SearchForProject(path);
|
||||
if (!projPath)
|
||||
{
|
||||
Log.report(LogVisor::Warning, _S("project doesn't exist at '%s'"), path.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
m_proj.reset(new HECL::Database::Project(projPath));
|
||||
if (!*m_proj)
|
||||
{
|
||||
m_proj.reset();
|
||||
return false;
|
||||
}
|
||||
|
||||
HECL::ProjectPath rudeSpacesPath(*m_proj, _S(".hecl/rude_spaces.yaml"));
|
||||
if (rudeSpacesPath.getPathType() == HECL::ProjectPath::Type::File)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProjectManager::extractGame(const HECL::SystemString& path)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,11 +5,20 @@
|
||||
|
||||
namespace RUDE
|
||||
{
|
||||
class ViewManager;
|
||||
|
||||
class ProjectManager
|
||||
{
|
||||
HECL::Database::Project* m_proj = nullptr;
|
||||
ViewManager& m_vm;
|
||||
std::unique_ptr<HECL::Database::Project> m_proj;
|
||||
static bool m_registeredSpecs;
|
||||
public:
|
||||
ProjectManager(ViewManager& vm);
|
||||
operator bool() const {return m_proj.operator bool();}
|
||||
|
||||
bool newProject(const HECL::SystemString& path);
|
||||
bool openProject(const HECL::SystemString& path);
|
||||
bool extractGame(const HECL::SystemString& path);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -8,11 +8,21 @@ namespace RUDE
|
||||
|
||||
class ResourceOutliner : public Space
|
||||
{
|
||||
struct State : SpaceState
|
||||
struct State : Space::State
|
||||
{
|
||||
DECL_YAML
|
||||
} m_state;
|
||||
SpaceState* spaceState() {return &m_state;}
|
||||
Space::State& spaceState() {return m_state;}
|
||||
|
||||
public:
|
||||
ResourceOutliner(ViewManager& vm) : Space(vm, Class::ResourceOutliner) {}
|
||||
ResourceOutliner(ViewManager& vm, Athena::io::YAMLDocReader& r)
|
||||
: ResourceOutliner(vm)
|
||||
{
|
||||
m_state.read(r);
|
||||
}
|
||||
|
||||
Specter::View* buildContentView(Specter::ViewResources& res) {return nullptr;}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,19 +1,35 @@
|
||||
#include "Space.hpp"
|
||||
#include "ViewManager.hpp"
|
||||
#include "ResourceOutliner.hpp"
|
||||
|
||||
namespace RUDE
|
||||
{
|
||||
|
||||
Specter::Space* Space::buildSpace(Specter::ViewResources& res)
|
||||
Specter::Space* Space::buildSpaceView(Specter::ViewResources& res)
|
||||
{
|
||||
m_space.reset(new Specter::Space(res, m_vm.rootView(), Specter::Toolbar::Position::Bottom));
|
||||
return m_space.get();
|
||||
}
|
||||
|
||||
Specter::View* SplitSpace::buildContent(Specter::ViewResources& res)
|
||||
Specter::View* SplitSpace::buildContentView(Specter::ViewResources& res)
|
||||
{
|
||||
m_splitView.reset(new Specter::SplitView(res, m_vm.rootView(), Specter::SplitView::Axis::Horizontal));
|
||||
return m_splitView.get();
|
||||
}
|
||||
|
||||
Space* Space::NewSpaceFromYAMLStream(ViewManager& vm, Athena::io::YAMLDocReader& r)
|
||||
{
|
||||
StateHead head;
|
||||
head.read(r);
|
||||
switch (head.cls)
|
||||
{
|
||||
case Class::SplitSpace:
|
||||
return new SplitSpace(vm, r);
|
||||
case Class::ResourceOutliner:
|
||||
return new ResourceOutliner(vm, r);
|
||||
default: break;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,8 +15,6 @@ namespace RUDE
|
||||
{
|
||||
class ViewManager;
|
||||
|
||||
struct SpaceState : Athena::io::DNAYaml<Athena::BigEndian> {Delete _d;};
|
||||
|
||||
class Space
|
||||
{
|
||||
public:
|
||||
@@ -27,42 +25,58 @@ public:
|
||||
TestSpace,
|
||||
ResourceOutliner,
|
||||
};
|
||||
|
||||
struct StateHead : Athena::io::DNAYaml<Athena::BigEndian>
|
||||
{
|
||||
DECL_YAML
|
||||
Value<Class> cls;
|
||||
};
|
||||
struct State : Athena::io::DNAYaml<Athena::BigEndian> {Delete _d;};
|
||||
|
||||
static Space* NewSpaceFromYAMLStream(ViewManager& vm, Athena::io::YAMLDocReader& r);
|
||||
|
||||
protected:
|
||||
friend class ViewManager;
|
||||
ViewManager& m_vm;
|
||||
Class m_class = Class::None;
|
||||
std::unique_ptr<Specter::Space> m_space;
|
||||
Space(ViewManager& vm, Class cls) : m_vm(vm), m_class(cls) {}
|
||||
Space(ViewManager& vm, Class cls, Athena::io::IStreamReader& r) : m_vm(vm), m_class(cls)
|
||||
{if (spaceState()) spaceState()->read(r);}
|
||||
void writeState(Athena::io::IStreamWriter& w) const;
|
||||
|
||||
/* Allows common Space code to access DNA-encoded state */
|
||||
virtual SpaceState* spaceState() {return nullptr;}
|
||||
virtual Space::State& spaceState()=0;
|
||||
|
||||
/* Structural control */
|
||||
virtual bool usesToolbar() const {return false;}
|
||||
virtual void buildToolbar(Specter::ViewResources& res, Specter::Toolbar& tb) {}
|
||||
virtual Specter::View* buildContent(Specter::ViewResources& res)=0;
|
||||
Specter::Space* buildSpace(Specter::ViewResources& res);
|
||||
virtual void buildToolbarView(Specter::ViewResources& res, Specter::Toolbar& tb) {}
|
||||
virtual Specter::View* buildContentView(Specter::ViewResources& res)=0;
|
||||
Specter::Space* buildSpaceView(Specter::ViewResources& res);
|
||||
public:
|
||||
};
|
||||
|
||||
class SplitSpace : public Space
|
||||
{
|
||||
friend class ViewManager;
|
||||
std::unique_ptr<Space> m_a;
|
||||
std::unique_ptr<Space> m_b;
|
||||
std::unique_ptr<Specter::SplitView> m_splitView;
|
||||
struct State : SpaceState
|
||||
struct State : Space::State
|
||||
{
|
||||
DECL_YAML
|
||||
Value<float> m_split;
|
||||
Value<float> split;
|
||||
} m_state;
|
||||
SpaceState* spaceState() {return &m_state;}
|
||||
Space::State& spaceState() {return m_state;}
|
||||
|
||||
public:
|
||||
SplitSpace(ViewManager& vm)
|
||||
: Space(vm, Class::SplitSpace) {}
|
||||
Specter::View* buildContent(Specter::ViewResources& res);
|
||||
SplitSpace(ViewManager& vm) : Space(vm, Class::SplitSpace) {}
|
||||
SplitSpace(ViewManager& vm, Athena::io::YAMLDocReader& r)
|
||||
: SplitSpace(vm)
|
||||
{
|
||||
m_state.read(r);
|
||||
m_a.reset(NewSpaceFromYAMLStream(vm, r));
|
||||
m_b.reset(NewSpaceFromYAMLStream(vm, r));
|
||||
}
|
||||
|
||||
Specter::View* buildContentView(Specter::ViewResources& res);
|
||||
};
|
||||
|
||||
class TestSpace : public Space
|
||||
@@ -81,20 +95,20 @@ public:
|
||||
: Space(vm, Class::TestSpace), m_contentStr(content), m_buttonStr(button), m_binding(binding)
|
||||
{}
|
||||
|
||||
struct State : SpaceState
|
||||
struct State : Space::State
|
||||
{
|
||||
DECL_YAML
|
||||
} m_state;
|
||||
SpaceState* spaceState() {return &m_state;}
|
||||
Space::State& spaceState() {return m_state;}
|
||||
|
||||
bool usesToolbar() const {return true;}
|
||||
void buildToolbar(Specter::ViewResources& res, Specter::Toolbar& tb)
|
||||
void buildToolbarView(Specter::ViewResources& res, Specter::Toolbar& tb)
|
||||
{
|
||||
m_button.reset(new Specter::Button(res, tb, m_binding, m_buttonStr));
|
||||
tb.push_back(m_button.get());
|
||||
}
|
||||
|
||||
Specter::View* buildContent(Specter::ViewResources& res)
|
||||
Specter::View* buildContentView(Specter::ViewResources& res)
|
||||
{
|
||||
m_textView.reset(new Specter::MultiLineTextView(res, *m_space, res.m_heading14));
|
||||
m_textView->setBackground(res.themeData().viewportBackground());
|
||||
|
||||
@@ -43,10 +43,13 @@ class SplashScreen : public Specter::ModalWindow
|
||||
new Specter::FileBrowser(m_splash.rootView().viewRes(),
|
||||
m_splash, m_splash.m_newString,
|
||||
Specter::FileBrowser::Type::SaveDirectory,
|
||||
[](bool ok, const HECL::SystemString& path)
|
||||
[&](bool ok, const HECL::SystemString& path)
|
||||
{
|
||||
if (ok)
|
||||
{
|
||||
Log.report(LogVisor::Info, _S("Making project '%s'"), path.c_str());
|
||||
m_splash.m_vm.projectManager().newProject(path);
|
||||
}
|
||||
}));
|
||||
m_splash.updateSize();
|
||||
m_splash.m_newButt.mouseLeave(coord);
|
||||
@@ -65,10 +68,13 @@ class SplashScreen : public Specter::ModalWindow
|
||||
new Specter::FileBrowser(m_splash.rootView().viewRes(),
|
||||
m_splash, m_splash.m_openString,
|
||||
Specter::FileBrowser::Type::OpenHECLProject,
|
||||
[](bool ok, const HECL::SystemString& path)
|
||||
[&](bool ok, const HECL::SystemString& path)
|
||||
{
|
||||
if (ok)
|
||||
{
|
||||
Log.report(LogVisor::Info, _S("Opening project '%s'"), path.c_str());
|
||||
m_splash.m_vm.projectManager().openProject(path);
|
||||
}
|
||||
}));
|
||||
m_splash.updateSize();
|
||||
m_splash.m_openButt.mouseLeave(coord);
|
||||
@@ -87,10 +93,13 @@ class SplashScreen : public Specter::ModalWindow
|
||||
new Specter::FileBrowser(m_splash.rootView().viewRes(),
|
||||
m_splash, m_splash.m_extractString,
|
||||
Specter::FileBrowser::Type::OpenFile,
|
||||
[](bool ok, const HECL::SystemString& path)
|
||||
[&](bool ok, const HECL::SystemString& path)
|
||||
{
|
||||
if (ok)
|
||||
{
|
||||
Log.report(LogVisor::Info, _S("Extracting game '%s'"), path.c_str());
|
||||
m_splash.m_vm.projectManager().extractGame(path);
|
||||
}
|
||||
}));
|
||||
m_splash.updateSize();
|
||||
m_splash.m_extractButt.mouseLeave(coord);
|
||||
|
||||
@@ -11,11 +11,11 @@ namespace RUDE
|
||||
|
||||
Specter::View* ViewManager::BuildSpaceViews(RUDE::Space* space)
|
||||
{
|
||||
Specter::Space* sspace = space->buildSpace(m_viewResources);
|
||||
Specter::View* sview = space->buildContent(m_viewResources);
|
||||
Specter::Space* sspace = space->buildSpaceView(m_viewResources);
|
||||
Specter::View* sview = space->buildContentView(m_viewResources);
|
||||
sspace->setContentView(sview);
|
||||
if (space->usesToolbar())
|
||||
space->buildToolbar(m_viewResources, sspace->toolbar());
|
||||
space->buildToolbarView(m_viewResources, sspace->toolbar());
|
||||
return sspace;
|
||||
}
|
||||
|
||||
@@ -31,24 +31,28 @@ void ViewManager::SetupSplashView()
|
||||
m_splash.reset(new SplashScreen(*this, m_viewResources));
|
||||
m_rootView->setContentView(m_splash.get());
|
||||
m_rootView->updateSize();
|
||||
m_showSplash = true;
|
||||
}
|
||||
|
||||
void ViewManager::SetupEditorView()
|
||||
{
|
||||
m_rootView->setBackground(Zeus::CColor::skGrey);
|
||||
m_rootView->setContentView(m_split.buildContent(m_viewResources));
|
||||
m_split.m_splitView->setContentView(0, BuildSpaceViews(&m_space1));
|
||||
m_split.m_splitView->setContentView(1, BuildSpaceViews(&m_space2));
|
||||
m_rootSpace.reset(new SplitSpace(*this));
|
||||
m_rootView->setContentView(BuildSpaceViews(m_rootSpace.get()));
|
||||
m_rootView->updateSize();
|
||||
m_showSplash = false;
|
||||
}
|
||||
|
||||
void ViewManager::SetupEditorView(Athena::io::YAMLDocReader& r)
|
||||
{
|
||||
m_rootSpace.reset(Space::NewSpaceFromYAMLStream(*this, r));
|
||||
m_rootView->setContentView(BuildSpaceViews(m_rootSpace.get()));
|
||||
m_rootView->updateSize();
|
||||
m_showSplash = false;
|
||||
}
|
||||
|
||||
ViewManager::ViewManager(HECL::Runtime::FileStoreManager& fileMgr, HECL::CVarManager& cvarMgr)
|
||||
: m_fileStoreManager(fileMgr), m_cvarManager(cvarMgr),
|
||||
m_fontCache(fileMgr), m_translator(RUDE::SystemLocaleOrEnglish()),
|
||||
m_setTo1(*this), m_setTo2(*this),
|
||||
m_split(*this),
|
||||
m_space1(*this, "Hello, World!\n\n", "Hello Button", &m_setTo1),
|
||||
m_space2(*this, "こんにちは世界!\n\n", "こんにちはボタン", &m_setTo2)
|
||||
: m_fileStoreManager(fileMgr), m_cvarManager(cvarMgr), m_projManager(*this),
|
||||
m_fontCache(fileMgr), m_translator(RUDE::SystemLocaleOrEnglish())
|
||||
{}
|
||||
|
||||
ViewManager::~ViewManager() {}
|
||||
@@ -70,15 +74,12 @@ void ViewManager::init(boo::IApplication* app)
|
||||
m_mainWindow->setWaitCursor(true);
|
||||
|
||||
float pixelFactor = 1.0;
|
||||
m_cvPixelFactor = m_cvarManager.newCVar("ed_pixelfactor", "User-selected UI Scale",
|
||||
pixelFactor, HECL::CVar::EFlags::Editor | HECL::CVar::EFlags::Archive);
|
||||
|
||||
boo::IGraphicsDataFactory* gf = m_mainWindow->getMainContextDataFactory();
|
||||
m_viewResources.init(gf, &m_fontCache, Specter::ThemeData(), pixelFactor);
|
||||
m_viewResources.prepFontCacheAsync(m_mainWindow.get());
|
||||
SetupRootView();
|
||||
SetupSplashView();
|
||||
m_showSplash = true;
|
||||
|
||||
m_mainWindow->setWaitCursor(false);
|
||||
}
|
||||
@@ -92,16 +93,12 @@ bool ViewManager::proc()
|
||||
{
|
||||
m_viewResources.resetPixelFactor(m_reqPf);
|
||||
SetupRootView();
|
||||
if (m_showSplash)
|
||||
SetupSplashView();
|
||||
else
|
||||
SetupEditorView();
|
||||
m_updatePf = false;
|
||||
}
|
||||
#if 0
|
||||
if (m_cvPixelFactor->isModified())
|
||||
{
|
||||
float pixelFactor = m_cvPixelFactor->toFloat();
|
||||
m_viewResources.resetPixelFactor(pixelFactor);
|
||||
m_cvPixelFactor->clearModified();
|
||||
}
|
||||
#endif
|
||||
m_rootView->dispatchEvents();
|
||||
if (m_showSplash)
|
||||
m_splash->think();
|
||||
|
||||
@@ -11,6 +11,8 @@ class SplashScreen;
|
||||
|
||||
class ViewManager : public Specter::IViewManager
|
||||
{
|
||||
friend class ProjectManager;
|
||||
|
||||
HECL::Runtime::FileStoreManager& m_fileStoreManager;
|
||||
HECL::CVarManager& m_cvarManager;
|
||||
ProjectManager m_projManager;
|
||||
@@ -18,10 +20,10 @@ class ViewManager : public Specter::IViewManager
|
||||
Specter::ViewResources m_viewResources;
|
||||
Specter::Translator m_translator;
|
||||
std::unique_ptr<boo::IWindow> m_mainWindow;
|
||||
|
||||
std::unique_ptr<Specter::RootView> m_rootView;
|
||||
std::unique_ptr<SplashScreen> m_splash;
|
||||
|
||||
HECL::CVar* m_cvPixelFactor;
|
||||
std::unique_ptr<Space> m_rootSpace;
|
||||
|
||||
std::vector<HECL::SystemString> m_recentProjects;
|
||||
std::vector<HECL::SystemString> m_recentFiles;
|
||||
@@ -33,41 +35,11 @@ class ViewManager : public Specter::IViewManager
|
||||
void SetupRootView();
|
||||
void SetupSplashView();
|
||||
void SetupEditorView();
|
||||
void SetupEditorView(Athena::io::YAMLDocReader& r);
|
||||
|
||||
bool m_showSplash = false;
|
||||
|
||||
public:
|
||||
struct SetTo1 : Specter::IButtonBinding
|
||||
{
|
||||
ViewManager& m_vm;
|
||||
SetTo1(ViewManager& vm) : m_vm(vm) {}
|
||||
|
||||
const char* name() const {return "SetTo1";}
|
||||
const char* help() const {return "Sets scale factor to 1.0";}
|
||||
void activated(const boo::SWindowCoord& coord)
|
||||
{
|
||||
m_vm.requestPixelFactor(1.0);
|
||||
}
|
||||
};
|
||||
SetTo1 m_setTo1;
|
||||
|
||||
struct SetTo2 : Specter::IButtonBinding
|
||||
{
|
||||
ViewManager& m_vm;
|
||||
SetTo2(ViewManager& vm) : m_vm(vm) {}
|
||||
|
||||
const char* name() const {return "SetTo2";}
|
||||
const char* help() const {return "Sets scale factor to 2.0";}
|
||||
void activated(const boo::SWindowCoord& coord)
|
||||
{
|
||||
m_vm.requestPixelFactor(2.0);
|
||||
}
|
||||
};
|
||||
SetTo2 m_setTo2;
|
||||
|
||||
SplitSpace m_split;
|
||||
TestSpace m_space1;
|
||||
TestSpace m_space2;
|
||||
|
||||
ViewManager(HECL::Runtime::FileStoreManager& fileMgr, HECL::CVarManager& cvarMgr);
|
||||
~ViewManager();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user