Added code support, not great but hey it works
This commit is contained in:
@ -5,4 +5,18 @@
|
|||||||
<QuadMeshHost />
|
<QuadMeshHost />
|
||||||
<SimpleBillboardedMaterial texture="texture_eth" />
|
<SimpleBillboardedMaterial texture="texture_eth" />
|
||||||
<TiledSprite tile="0" ref="tiledSprite" sizeType="TILED_SPRITE_SIZE_TYPE_WIDTH_RATIO" />
|
<TiledSprite tile="0" ref="tiledSprite" sizeType="TILED_SPRITE_SIZE_TYPE_WIDTH_RATIO" />
|
||||||
|
|
||||||
|
<code type="properties">
|
||||||
|
TilesetGrid grid;
|
||||||
|
</code>
|
||||||
|
|
||||||
|
<code type="init">
|
||||||
|
this->grid = TilesetGrid(
|
||||||
|
1, 13,
|
||||||
|
741, 10270,
|
||||||
|
0, 0,
|
||||||
|
0, 0
|
||||||
|
);
|
||||||
|
tiledSprite->tileset = &grid;
|
||||||
|
</code>
|
||||||
</prefab>
|
</prefab>
|
@ -4,13 +4,13 @@
|
|||||||
</item>
|
</item>
|
||||||
|
|
||||||
<item ref="eth" prefab="prefabs/EthPrefab" />
|
<item ref="eth" prefab="prefabs/EthPrefab" />
|
||||||
<item ref="craig" prefab="prefabs/SimpleSpinningCubePrefab" />
|
<!-- <item ref="craig" prefab="prefabs/SimpleSpinningCubePrefab" />
|
||||||
<item ref="bg" prefab="prefabs/SimpleSpinningCubePrefab" />
|
<item ref="bg" prefab="prefabs/SimpleSpinningCubePrefab" />
|
||||||
<item ref="square" prefab="prefabs/SimpleSpinningCubePrefab" />
|
<item ref="square" prefab="prefabs/SimpleSpinningCubePrefab" /> -->
|
||||||
|
|
||||||
<item lookAt="0, 0, 5, 0, 0, 0" >
|
<item lookAt="5, 5, 5, 0, 0, 0" >
|
||||||
<Camera fov="0.436332" ref="cameraNew" />
|
<Camera fov="0.436332" />
|
||||||
<CameraTexture />
|
<CameraTexture ref="camTexture" />
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
@ -24,7 +24,16 @@
|
|||||||
alignUnitRight="UI_COMPONENT_ALIGN_UNIT_PERCENT"
|
alignUnitRight="UI_COMPONENT_ALIGN_UNIT_PERCENT"
|
||||||
alignY="UI_COMPONENT_ALIGN_STRETCH"
|
alignY="UI_COMPONENT_ALIGN_STRETCH"
|
||||||
ref="image"
|
ref="image"
|
||||||
|
texture="camTexture->renderTarget.getTexture()"
|
||||||
/>
|
/>
|
||||||
</item>
|
</item>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
|
<code type="init">
|
||||||
|
useEvent([&]{
|
||||||
|
assertNotNull(camTexture);
|
||||||
|
assertNotNull(image);
|
||||||
|
camTexture->renderTarget.setSize(image->getWidth(), image->getHeight());
|
||||||
|
}, image->eventAlignmentUpdated);
|
||||||
|
</code>
|
||||||
</scene>
|
</scene>
|
@ -1,6 +1,6 @@
|
|||||||
<vnscene name="VNSceneTest" extend="scenes/SceneBase">
|
<vnscene name="VNSceneTest" extend="scenes/SceneBase">
|
||||||
<events>
|
<events>
|
||||||
<position item="eth" x="0" y="0" z="5" />
|
<position item="eth" x="0" y="0" z="0" />
|
||||||
|
|
||||||
<text character="eth">
|
<text character="eth">
|
||||||
<string lang="en">Hi, I'm Ethereality.</string>
|
<string lang="en">Hi, I'm Ethereality.</string>
|
||||||
|
@ -10,6 +10,7 @@ set(
|
|||||||
${DAWN_TOOL_SOURCES}
|
${DAWN_TOOL_SOURCES}
|
||||||
${D}/SceneItemGenerator.cpp
|
${D}/SceneItemGenerator.cpp
|
||||||
${D}/SceneAssetGenerator.cpp
|
${D}/SceneAssetGenerator.cpp
|
||||||
|
${D}/SceneCodeGenerator.cpp
|
||||||
${D}/SceneGenerator.cpp
|
${D}/SceneGenerator.cpp
|
||||||
${D}/SceneItemComponentGenerator.cpp
|
${D}/SceneItemComponentGenerator.cpp
|
||||||
|
|
||||||
|
28
src/dawntools/util/generator/SceneCodeGenerator.cpp
Normal file
28
src/dawntools/util/generator/SceneCodeGenerator.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright (c) 2023 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#include "SceneCodeGenerator.hpp"
|
||||||
|
|
||||||
|
using namespace Dawn;
|
||||||
|
|
||||||
|
void SceneCodeGenerator::generate(
|
||||||
|
std::vector<std::string> *publicProperties,
|
||||||
|
std::vector<std::string> *initBody,
|
||||||
|
struct SceneCode *code,
|
||||||
|
std::string tabs
|
||||||
|
) {
|
||||||
|
switch(code->codeType) {
|
||||||
|
case SCENE_CODE_TYPE_PROPERTIES:
|
||||||
|
line(publicProperties, code->code, "");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SCENE_CODE_TYPE_INIT:
|
||||||
|
line(initBody, code->code, "");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
20
src/dawntools/util/generator/SceneCodeGenerator.hpp
Normal file
20
src/dawntools/util/generator/SceneCodeGenerator.hpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Copyright (c) 2023 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "util/parser/SceneCodeParser.hpp"
|
||||||
|
#include "util/CodeGen.hpp"
|
||||||
|
|
||||||
|
namespace Dawn {
|
||||||
|
class SceneCodeGenerator : public CodeGen {
|
||||||
|
public:
|
||||||
|
static void generate(
|
||||||
|
std::vector<std::string> *publicProperties,
|
||||||
|
std::vector<std::string> *initBody,
|
||||||
|
struct SceneCode *code,
|
||||||
|
std::string tabs
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
@ -76,4 +76,16 @@ void SceneGenerator::generate(
|
|||||||
|
|
||||||
// Seal methods
|
// Seal methods
|
||||||
line(&methodAssets.body, "return assets;", "");
|
line(&methodAssets.body, "return assets;", "");
|
||||||
|
|
||||||
|
// Code
|
||||||
|
auto itCode = scene->code.begin();
|
||||||
|
while(itCode != scene->code.end()) {
|
||||||
|
SceneCodeGenerator::generate(
|
||||||
|
&classInfo.publicProperties,
|
||||||
|
&methodInit.body,
|
||||||
|
&(*itCode),
|
||||||
|
""
|
||||||
|
);
|
||||||
|
++itCode;
|
||||||
|
}
|
||||||
}
|
}
|
@ -122,4 +122,16 @@ void SceneItemGenerator::generate(
|
|||||||
if(!parentRef.empty()) {
|
if(!parentRef.empty()) {
|
||||||
line(initBody, name + "->transform.setParent(&"+parentRef+"->transform);", "");
|
line(initBody, name + "->transform.setParent(&"+parentRef+"->transform);", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Code
|
||||||
|
auto itCode = item->code.begin();
|
||||||
|
while(itCode != item->code.end()) {
|
||||||
|
SceneCodeGenerator::generate(
|
||||||
|
publicProperties,
|
||||||
|
initBody,
|
||||||
|
&(*itCode),
|
||||||
|
""
|
||||||
|
);
|
||||||
|
++itCode;
|
||||||
|
}
|
||||||
}
|
}
|
@ -7,6 +7,7 @@
|
|||||||
#include "SceneItemComponentGenerator.hpp"
|
#include "SceneItemComponentGenerator.hpp"
|
||||||
#include "SceneAssetGenerator.hpp"
|
#include "SceneAssetGenerator.hpp"
|
||||||
#include "util/parser/SceneItemParser.hpp"
|
#include "util/parser/SceneItemParser.hpp"
|
||||||
|
#include "util/generator/SceneCodeGenerator.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class SceneItemGenerator : public CodeGen {
|
class SceneItemGenerator : public CodeGen {
|
||||||
|
@ -11,6 +11,7 @@ set(
|
|||||||
${D}/SceneParser.cpp
|
${D}/SceneParser.cpp
|
||||||
${D}/SceneItemParser.cpp
|
${D}/SceneItemParser.cpp
|
||||||
${D}/SceneAssetParser.cpp
|
${D}/SceneAssetParser.cpp
|
||||||
|
${D}/SceneCodeParser.cpp
|
||||||
${D}/SceneItemComponentParser.cpp
|
${D}/SceneItemComponentParser.cpp
|
||||||
${D}/SceneItemComponentRegistry.cpp
|
${D}/SceneItemComponentRegistry.cpp
|
||||||
|
|
||||||
|
39
src/dawntools/util/parser/SceneCodeParser.cpp
Normal file
39
src/dawntools/util/parser/SceneCodeParser.cpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// Copyright (c) 2023 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#include "SceneCodeParser.hpp"
|
||||||
|
|
||||||
|
using namespace Dawn;
|
||||||
|
|
||||||
|
std::vector<std::string> SceneCodeParser::getRequiredAttributes() {
|
||||||
|
return { "type" };
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, std::string> SceneCodeParser::getOptionalAttributes() {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t SceneCodeParser::onParse(
|
||||||
|
Xml *node,
|
||||||
|
std::map<std::string, std::string> values,
|
||||||
|
struct SceneCode *out,
|
||||||
|
std::string *error
|
||||||
|
) {
|
||||||
|
// Get the type
|
||||||
|
std::string type = values["type"];
|
||||||
|
if(type == "properties") {
|
||||||
|
out->codeType = SCENE_CODE_TYPE_PROPERTIES;
|
||||||
|
} else if(type == "init") {
|
||||||
|
out->codeType = SCENE_CODE_TYPE_INIT;
|
||||||
|
} else {
|
||||||
|
*error = "Invalid type '" + type + "' for SceneCode.";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the code
|
||||||
|
out->code = node->value;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
32
src/dawntools/util/parser/SceneCodeParser.hpp
Normal file
32
src/dawntools/util/parser/SceneCodeParser.hpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// Copyright (c) 2023 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "util/XmlParser.hpp"
|
||||||
|
|
||||||
|
namespace Dawn {
|
||||||
|
enum SceneCodeType {
|
||||||
|
SCENE_CODE_TYPE_PROPERTIES,
|
||||||
|
SCENE_CODE_TYPE_INIT
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SceneCode {
|
||||||
|
enum SceneCodeType codeType;
|
||||||
|
std::string code;
|
||||||
|
};
|
||||||
|
|
||||||
|
class SceneCodeParser : public XmlParser<struct SceneCode> {
|
||||||
|
public:
|
||||||
|
virtual std::vector<std::string> getRequiredAttributes();
|
||||||
|
virtual std::map<std::string, std::string> getOptionalAttributes();
|
||||||
|
|
||||||
|
virtual int32_t onParse(
|
||||||
|
Xml *node,
|
||||||
|
std::map<std::string, std::string> values,
|
||||||
|
struct SceneCode *out,
|
||||||
|
std::string *error
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
@ -71,6 +71,12 @@ int32_t SceneItemParser::onParse(
|
|||||||
auto ret = (SceneAssetParser()).parse(c, &asset, error);
|
auto ret = (SceneAssetParser()).parse(c, &asset, error);
|
||||||
if(ret != 0) return ret;
|
if(ret != 0) return ret;
|
||||||
out->assets.push_back(asset);
|
out->assets.push_back(asset);
|
||||||
|
|
||||||
|
} else if(c->node == "code") {
|
||||||
|
struct SceneCode code;
|
||||||
|
auto ret = (SceneCodeParser()).parse(c, &code, error);
|
||||||
|
if(ret != 0) return ret;
|
||||||
|
out->code.push_back(code);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
struct SceneItemComponent component;
|
struct SceneItemComponent component;
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "util/parser/SceneItemComponentParser.hpp"
|
#include "util/parser/SceneItemComponentParser.hpp"
|
||||||
#include "util/parser/SceneAssetParser.hpp"
|
#include "util/parser/SceneAssetParser.hpp"
|
||||||
|
#include "util/parser/SceneCodeParser.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
struct SceneItem {
|
struct SceneItem {
|
||||||
@ -19,6 +20,7 @@ namespace Dawn {
|
|||||||
std::vector<struct SceneItemComponent> components;
|
std::vector<struct SceneItemComponent> components;
|
||||||
std::vector<struct SceneItem> children;
|
std::vector<struct SceneItem> children;
|
||||||
std::vector<struct SceneAsset> assets;
|
std::vector<struct SceneAsset> assets;
|
||||||
|
std::vector<struct SceneCode> code;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SceneItemParser : public XmlParser<struct SceneItem> {
|
class SceneItemParser : public XmlParser<struct SceneItem> {
|
||||||
|
@ -40,6 +40,12 @@ int32_t SceneParser::onParse(
|
|||||||
ret = (SceneItemParser()).parse(child, &item, error);
|
ret = (SceneItemParser()).parse(child, &item, error);
|
||||||
if(ret != 0) return 1;
|
if(ret != 0) return 1;
|
||||||
out->items.push_back(item);
|
out->items.push_back(item);
|
||||||
|
|
||||||
|
} else if(child->node == "code") {
|
||||||
|
struct SceneCode code;
|
||||||
|
ret = (SceneCodeParser()).parse(child, &code, error);
|
||||||
|
if(ret != 0) return ret;
|
||||||
|
out->code.push_back(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
++itChildren;
|
++itChildren;
|
||||||
|
@ -5,12 +5,14 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "util/parser/SceneItemParser.hpp"
|
#include "util/parser/SceneItemParser.hpp"
|
||||||
|
#include "util/parser/SceneCodeParser.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
struct Scene {
|
struct Scene {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string extend;
|
std::string extend;
|
||||||
std::vector<struct SceneItem> items;
|
std::vector<struct SceneItem> items;
|
||||||
|
std::vector<struct SceneCode> code;
|
||||||
struct SceneItemComponentRegistry *registry;
|
struct SceneItemComponentRegistry *registry;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user