|
|
@@ -7,6 +7,7 @@
|
|
|
#include "UserSettingParser.h"
|
|
|
#include "WallpaperEngine/Data/Model/Object.h"
|
|
|
#include "WallpaperEngine/Data/Model/Project.h"
|
|
|
+#include "WallpaperEngine/Data/Model/ScriptedDynamicValue.h"
|
|
|
#include "WallpaperEngine/Logging/Log.h"
|
|
|
|
|
|
#include <glm/gtc/constants.hpp>
|
|
|
@@ -85,6 +86,28 @@ void widenColorToVec4 (DynamicValue& v) {
|
|
|
v.update (glm::vec4 (glm::vec3 (icolor), 255.0f) / 255.0f);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+static void bindScriptContext (
|
|
|
+ const UserSettingUniquePtr& setting,
|
|
|
+ int objectId,
|
|
|
+ const std::string& objectName,
|
|
|
+ const std::string& propertyName
|
|
|
+) {
|
|
|
+ if (!setting || !setting->value) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ auto* scripted = dynamic_cast<ScriptedDynamicValue*> (setting->value.get ());
|
|
|
+ if (!scripted) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ scripted->setBindingContext (ScriptBindingContext {
|
|
|
+ .objectId = objectId,
|
|
|
+ .objectName = objectName,
|
|
|
+ .propertyName = propertyName,
|
|
|
+ });
|
|
|
+}
|
|
|
} // namespace
|
|
|
|
|
|
ObjectUniquePtr ObjectParser::parse (const JSON& it, const Project& project) {
|
|
|
@@ -103,13 +126,13 @@ ObjectUniquePtr ObjectParser::parse (const JSON& it, const Project& project) {
|
|
|
basedata = ObjectData {
|
|
|
.id = it.require<int> ("id", "Object must have an id"),
|
|
|
.name = it.require<std::string> ("name", "Object must have a name"),
|
|
|
- .dependencies = parseDependencies (it),
|
|
|
- .parent = it.optional<int> ("parent"),
|
|
|
- .origin = it.user ("origin", project.properties, glm::vec3 (0.0f)),
|
|
|
- .groupScale = it.user ("scale", project.properties, glm::vec3 (1.0f)),
|
|
|
- .groupAngles = it.user ("angles", project.properties, glm::vec3 (0.0f)),
|
|
|
- .groupVisible = it.user ("visible", project.properties, true),
|
|
|
- };
|
|
|
+ .dependencies = parseDependencies (it),
|
|
|
+ .parent = it.optional<int> ("parent"),
|
|
|
+ .origin = it.user ("origin", project.properties, glm::vec3 (0.0f)),
|
|
|
+ .groupScale = it.user ("scale", project.properties, glm::vec3 (1.0f)),
|
|
|
+ .groupAngles = it.user ("angles", project.properties, glm::vec3 (0.0f)),
|
|
|
+ .groupVisible = it.user ("visible", project.properties, true),
|
|
|
+ };
|
|
|
} catch (const std::exception& e) {
|
|
|
sLog.error ("Error parsing object base data: ", e.what ());
|
|
|
const auto idIt = it.find ("id");
|
|
|
@@ -123,15 +146,22 @@ ObjectUniquePtr ObjectParser::parse (const JSON& it, const Project& project) {
|
|
|
name = std::to_string (nameIt->get<int> ());
|
|
|
}
|
|
|
}
|
|
|
- basedata = ObjectData {
|
|
|
- .id = id,
|
|
|
- .name = name,
|
|
|
- .dependencies = {},
|
|
|
- .groupScale = it.user ("scale", project.properties, glm::vec3 (1.0f)),
|
|
|
- .groupAngles = it.user ("angles", project.properties, glm::vec3 (0.0f)),
|
|
|
- .groupVisible = it.user ("visible", project.properties, true),
|
|
|
- };
|
|
|
- }
|
|
|
+ basedata = ObjectData {
|
|
|
+ .id = id,
|
|
|
+ .name = name,
|
|
|
+ .dependencies = parseDependencies (it),
|
|
|
+ .parent = it.optional<int> ("parent"),
|
|
|
+ .origin = it.user ("origin", project.properties, glm::vec3 (0.0f)),
|
|
|
+ .groupScale = it.user ("scale", project.properties, glm::vec3 (1.0f)),
|
|
|
+ .groupAngles = it.user ("angles", project.properties, glm::vec3 (0.0f)),
|
|
|
+ .groupVisible = it.user ("visible", project.properties, true),
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ bindScriptContext (basedata.origin, basedata.id, basedata.name, "origin");
|
|
|
+ bindScriptContext (basedata.groupScale, basedata.id, basedata.name, "scale");
|
|
|
+ bindScriptContext (basedata.groupAngles, basedata.id, basedata.name, "angles");
|
|
|
+ bindScriptContext (basedata.groupVisible, basedata.id, basedata.name, "visible");
|
|
|
|
|
|
if (imageIt != it.end () && imageIt->is_string ()) {
|
|
|
return parseImage (it, project, std::move (basedata), *imageIt);
|
|
|
@@ -146,10 +176,12 @@ ObjectUniquePtr ObjectParser::parse (const JSON& it, const Project& project) {
|
|
|
} else if (shapeIt != it.end ()) {
|
|
|
sLog.error ("VolumeLight objects are not supported yet");
|
|
|
} else {
|
|
|
- // dump the object for now, might want to change later
|
|
|
- // TODO: RE-EVALUATE IF THIS MAKES SENSE, THERE'S OBJECTS THAT CONTAIN OTHER OBJECTS AND THUS AREN'T REALLY
|
|
|
- // ANYTHING SPECIAL
|
|
|
- sLog.error ("Unknown object type found: ", it.dump ());
|
|
|
+ if (!it.optional ("solid", false)) {
|
|
|
+ // dump the object for now, might want to change later
|
|
|
+ // TODO: RE-EVALUATE IF THIS MAKES SENSE, THERE'S OBJECTS THAT CONTAIN OTHER OBJECTS AND THUS AREN'T REALLY
|
|
|
+ // ANYTHING SPECIAL
|
|
|
+ sLog.error ("Unknown object type found: ", it.dump ());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return std::make_unique<Object> (std::move (basedata));
|
|
|
@@ -231,6 +263,10 @@ TextUniquePtr ObjectParser::parseText (const JSON& it, const Project& project, O
|
|
|
);
|
|
|
|
|
|
widenColorToVec4 (*result->color->value);
|
|
|
+ bindScriptContext (result->visible, result->id, result->name, "visible");
|
|
|
+ bindScriptContext (result->color, result->id, result->name, "color");
|
|
|
+ bindScriptContext (result->alpha, result->id, result->name, "alpha");
|
|
|
+ bindScriptContext (result->scale, result->id, result->name, "scale");
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
@@ -268,6 +304,36 @@ ObjectParser::parseImage (const JSON& it, const Project& project, ObjectData bas
|
|
|
result->color->value->update (glm::vec4 (result->color->value->getIVec3 (), 255));
|
|
|
}
|
|
|
|
|
|
+ bindScriptContext (result->scale, result->id, result->name, "scale");
|
|
|
+ bindScriptContext (result->angles, result->id, result->name, "angles");
|
|
|
+ bindScriptContext (result->visible, result->id, result->name, "visible");
|
|
|
+ bindScriptContext (result->alpha, result->id, result->name, "alpha");
|
|
|
+ bindScriptContext (result->color, result->id, result->name, "color");
|
|
|
+ bindScriptContext (result->parallaxDepth, result->id, result->name, "parallaxDepth");
|
|
|
+
|
|
|
+ const auto instance = it.optional ("instance");
|
|
|
+ if (instance.has_value () && instance->is_object () && !result->model->material->passes.empty ()) {
|
|
|
+ auto& firstPass = **result->model->material->passes.begin ();
|
|
|
+ const auto instanceTextures = instance->optional ("textures");
|
|
|
+ if (instanceTextures.has_value ()) {
|
|
|
+ const auto parsed = parseTextureMap (*instanceTextures);
|
|
|
+ firstPass.textures.insert (parsed.begin (), parsed.end ());
|
|
|
+ }
|
|
|
+ const auto instanceUserTextures = instance->optional ("usertextures");
|
|
|
+ if (instanceUserTextures.has_value ()) {
|
|
|
+ const auto parsed = parseTextureMap (*instanceUserTextures);
|
|
|
+ firstPass.usertextures.insert (parsed.begin (), parsed.end ());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (const auto& effect : result->effects) {
|
|
|
+ for (const auto& pass : effect->passOverrides) {
|
|
|
+ for (const auto& [name, constant] : pass->constants) {
|
|
|
+ bindScriptContext (constant, result->id, result->name, name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -339,6 +405,11 @@ TextureMap ObjectParser::parseTextureMap (const JSON& it) {
|
|
|
|
|
|
if (cur.is_null ()) {
|
|
|
continue;
|
|
|
+ } else if (cur.is_object ()) {
|
|
|
+ const auto nameIt = cur.find ("name");
|
|
|
+ if (nameIt != cur.end () && nameIt->is_string ()) {
|
|
|
+ result.emplace (textureIndex, nameIt->get<std::string> ());
|
|
|
+ }
|
|
|
} else {
|
|
|
std::string texName = cur;
|
|
|
if (!texName.empty ()) {
|
|
|
@@ -646,7 +717,7 @@ ParticleUniquePtr ObjectParser::parseParticle (const JSON& it, const Project& pr
|
|
|
flags = flagsIt->get<uint32_t> ();
|
|
|
}
|
|
|
|
|
|
- return std::make_unique<Particle> (
|
|
|
+ auto result = std::make_unique<Particle> (
|
|
|
std::move (base),
|
|
|
ParticleData {
|
|
|
.scale = it.user ("scale", properties, glm::vec3 (1.0f)),
|
|
|
@@ -669,6 +740,11 @@ ParticleUniquePtr ObjectParser::parseParticle (const JSON& it, const Project& pr
|
|
|
.instanceOverride = std::move (instanceOverride),
|
|
|
}
|
|
|
);
|
|
|
+ bindScriptContext (result->scale, result->id, result->name, "scale");
|
|
|
+ bindScriptContext (result->angles, result->id, result->name, "angles");
|
|
|
+ bindScriptContext (result->visible, result->id, result->name, "visible");
|
|
|
+ bindScriptContext (result->parallaxDepth, result->id, result->name, "parallaxDepth");
|
|
|
+ return result;
|
|
|
} catch (nlohmann::json::exception& e) {
|
|
|
sLog.error ("Error parsing particle '", base.name, "': ", e.what ());
|
|
|
sLog.error ("Particle JSON: ", it.dump ());
|