This commit is contained in:
Isuru Samarathunga
2025-10-21 21:03:40 +05:30
parent 86ed9346aa
commit 2d5875d211
11 changed files with 239 additions and 165 deletions

View File

@ -40,19 +40,20 @@ namespace ia::iae
return writer.result;
};
// -----------------------------------------------
}
} // namespace ia::iae
namespace ia::iae
{
SceneManager::SceneManager(IN std::function<RefPtr<Node2D>(IN CONST String &, IN CONST Vector<String>&)> getCustomNode,
IN std::function<Handle(IN ResourceType type, IN CONST String &, IN INT64)> getResource):
m_customNodeGetter(getCustomNode), m_resourceGetter(getResource)
SceneManager::SceneManager(
IN std::function<RefPtr<Node2D>(IN CONST String &, IN CONST Vector<String> &)> getCustomNode,
IN std::function<Handle(IN ResourceType type, IN CONST String &, IN INT64)> getResource)
: m_customNodeGetter(getCustomNode), m_resourceGetter(getResource)
{
}
SceneManager::~SceneManager()
{
for(const auto& t: m_scenes)
for (const auto &t : m_scenes)
delete t->Value;
}
@ -101,6 +102,21 @@ namespace ia::iae
{
auto t = propRoot.child("Extent");
scene->Extent() = Vec2{t.attribute("width").as_float(), t.attribute("height").as_float()};
t = propRoot.child("DesignViewport");
if(t)
scene->DesignViewport() = Vec2{t.attribute("width").as_float(), t.attribute("height").as_float()};
else
scene->DesignViewport() = Vec2{};
scene->EnableOnScreenGamePad() = false;
t = propRoot.child("GamePad");
if(t)
{
const auto t2 = t.attribute("enableOnScreen");
if(t2 && t2.as_bool())
scene->EnableOnScreenGamePad() = true;
}
}
// Process Nodes
@ -110,7 +126,7 @@ namespace ia::iae
{
for (const auto &t : nodeRoot)
{
Node2D* n{};
Node2D *n{};
if (!strcmp(t.name(), "TextureNode"))
{
const auto node = MakeRefPtr<TextureNode>(Engine::GetUniqueResourceName());
@ -124,15 +140,11 @@ namespace ia::iae
scene->AddNode(node);
n = node.get();
}
if(!n) continue;
if(t.attribute("X") && t.attribute("Y"))
{
n->SetLocalPosition({
t.attribute("X").as_float(),
t.attribute("Y").as_float()
});
}
if (!n)
continue;
if (t.attribute("X") && t.attribute("Y"))
n->SetLocalPosition({t.attribute("X").as_float(), t.attribute("Y").as_float()});
}
}
@ -141,15 +153,21 @@ namespace ia::iae
if (!uiRoot)
THROW_INVALID_DATA("Scene file is missing 'UI' tag");
{
scene->UIMarkupStyles() = getInnerXML(uiRoot.child("CSS")).c_str();
auto html = String(getInnerXML(uiRoot.child("HTML")).c_str());
html =
Utils::RegexReplaceGroups(html, "<img(.*?)src=\"(.*?)\"", [&](IN INT32 index, IN CONST String &match) {
if(index == 1)
return BuildString("$H$", resources[match]);
return match;
});
scene->UIMarkup() = html;
if (uiRoot.child("CSS") && uiRoot.child("HTML"))
{
scene->UIMarkupStyles() = getInnerXML(uiRoot.child("CSS")).c_str();
auto html = String(getInnerXML(uiRoot.child("HTML")).c_str());
html = Utils::RegexReplaceGroups(html, "<img(.*?)src=\"(.*?)\"",
[&](IN INT32 index, IN CONST String &match) {
if (index == 1)
return BuildString("$H$", resources[match]);
return match;
});
scene->UIMarkup() = html;
}
else {
}
}
m_scenes[name] = scene;