| 53 | } |
| 54 | |
| 55 | void build(Object& obj, Entry &entry, Build::SceneCtx &ctx) |
| 56 | { |
| 57 | Data &data = *static_cast<Data*>(entry.data.get()); |
| 58 | |
| 59 | auto idRes = ctx.codeIdxMapUUID.find(data.scriptUUID); |
| 60 | uint16_t id = 0xDEAD; |
| 61 | if (idRes == ctx.codeIdxMapUUID.end()) { |
| 62 | Utils::Logger::log("Component Code: Script UUID not found: " + std::to_string(entry.uuid), Utils::Logger::LEVEL_ERROR); |
| 63 | } else { |
| 64 | id = idRes->second; |
| 65 | } |
| 66 | |
| 67 | ctx.fileObj.write<uint16_t>(id); |
| 68 | ctx.fileObj.write<uint16_t>(0); |
| 69 | |
| 70 | auto script = ctx.project->getAssets().getEntryByUUID(data.scriptUUID); |
| 71 | if (!script)return; |
| 72 | |
| 73 | for (auto &field : script->params.fields) { |
| 74 | auto &prop = data.args[field.name]; |
| 75 | auto val = prop.resolve(obj.propOverrides); |
| 76 | if (val.empty())val = field.defaultValue; |
| 77 | if (val.empty())val = "0"; |
| 78 | |
| 79 | if(field.type == Utils::DataType::ASSET_SPRITE) |
| 80 | { |
| 81 | uint64_t uuid = Utils::parseU64(val); |
| 82 | ctx.fileObj.write<uint32_t>(ctx.assetUUIDToIdx[uuid]); |
| 83 | } else if(field.type == Utils::DataType::OBJECT_REF) { |
| 84 | uint32_t uuid = static_cast<uint32_t>(Utils::parseU64(val)); |
| 85 | auto refObj = ctx.scene ? ctx.scene->getObjectByUUID(uuid) : nullptr; |
| 86 | uint16_t objId = refObj ? refObj->runtimeId : 0; |
| 87 | ctx.fileObj.write<uint32_t>(objId); |
| 88 | } else if(field.type == Utils::DataType::PREFAB){ |
| 89 | uint64_t uuid = Utils::parseU64(val); |
| 90 | ctx.fileObj.write<uint32_t>(ctx.assetUUIDToIdx[uuid]); |
| 91 | } else { |
| 92 | ctx.fileObj.writeAs(val, field.type); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | void draw(Object &obj, Entry &entry) |
| 98 | { |
no test coverage detected