| 144 | } |
| 145 | |
| 146 | void Object::init(World* world, EntityId entityId, EntityMode mode) { |
| 147 | Entity::init(world, entityId, mode); |
| 148 | // Only try and find a new orientation if we do not already have one, |
| 149 | // otherwise we may have a valid orientation that depends on non-tile data |
| 150 | // that is not loaded yet. |
| 151 | if (m_orientationIndex == NPos) { |
| 152 | updateOrientation(); |
| 153 | } else if (auto orientation = currentOrientation()) { |
| 154 | // update direction in case orientation config direction has changed |
| 155 | if (orientation->directionAffinity) |
| 156 | m_direction.set(*orientation->directionAffinity); |
| 157 | m_materialSpaces.set(orientation->materialSpaces); |
| 158 | } |
| 159 | |
| 160 | m_orientationDrawablesCache.reset(); |
| 161 | |
| 162 | // This is stupid and we should only have to deal with the new directives parameter, but blah blah backwards compatibility. |
| 163 | auto colorName = configValue("color", "default").toString().takeUtf8(); |
| 164 | auto colorEnd = colorName.find('?'); |
| 165 | if (colorEnd != NPos) { |
| 166 | size_t suffixBegin = colorName.rfind('?'); |
| 167 | String colorDirectives; |
| 168 | std::string colorSuffix = suffixBegin == NPos ? "" : colorName.substr(suffixBegin); |
| 169 | if (colorSuffix.empty() && colorSuffix.rfind("?replace", 0) != 0) |
| 170 | colorDirectives = colorName.substr(colorEnd); |
| 171 | else |
| 172 | colorDirectives = colorName.substr(colorEnd, suffixBegin - colorEnd); |
| 173 | |
| 174 | m_colorSuffix = std::move(colorSuffix); |
| 175 | m_colorDirectives = std::move(colorDirectives); |
| 176 | } |
| 177 | else |
| 178 | m_colorDirectives = m_colorSuffix = ""; |
| 179 | |
| 180 | m_directives = ""; |
| 181 | if (auto directives = configValue("")) { |
| 182 | if (directives.isType(Json::Type::String)) |
| 183 | m_directives.parse(directives.toString()); |
| 184 | } |
| 185 | |
| 186 | if (isMaster()) { |
| 187 | setImageKey("color", colorName); |
| 188 | |
| 189 | if (m_config->lightColors.contains(colorName)) |
| 190 | m_lightSourceColor.set(m_config->lightColors.get(colorName)); |
| 191 | else |
| 192 | m_lightSourceColor.set(Color::Clear); |
| 193 | |
| 194 | m_soundEffectEnabled.set(true); |
| 195 | |
| 196 | m_liquidCheckTimer = GameTimer(m_config->liquidCheckInterval); |
| 197 | m_liquidCheckTimer.setDone(); |
| 198 | |
| 199 | setKeepAlive(configValue("keepAlive", false).toBool()); |
| 200 | |
| 201 | auto jScripts = configValue("scripts", JsonArray()); |
| 202 | if (jScripts.isType(Json::Type::Array)) |
| 203 | m_scriptComponent.setScripts(jsonToStringList(jScripts).transformed(bind(AssetPath::relativeTo, m_config->path, _1))); |
nothing calls this directly
no test coverage detected