| 66 | } |
| 67 | |
| 68 | ProjectileConfigPtr ProjectileDatabase::readConfig(String const& path) { |
| 69 | auto assets = Root::singleton().assets(); |
| 70 | |
| 71 | Json config = assets->json(path); |
| 72 | |
| 73 | auto projectileConfig = make_shared<ProjectileConfig>(); |
| 74 | projectileConfig->config = config; |
| 75 | projectileConfig->typeName = config.getString("projectileName"); |
| 76 | projectileConfig->directory = AssetPath::directory(path); |
| 77 | |
| 78 | projectileConfig->description = config.getString("description", ""); |
| 79 | |
| 80 | projectileConfig->boundBox = config.opt("boundBox").apply(jsonToRectF).value({-5, -5, 5, 5}); |
| 81 | |
| 82 | auto physicsType = config.getString("physics", "default"); |
| 83 | JsonObject movementSettings = config.getObject("movementSettings", JsonObject()); |
| 84 | projectileConfig->movementSettings = |
| 85 | jsonMerge(assets->json(strf("/projectiles/physics.config:{}", physicsType)), movementSettings); |
| 86 | |
| 87 | projectileConfig->initialSpeed = config.getFloat("speed", 50); |
| 88 | projectileConfig->acceleration = config.getFloat("acceleration", 0); |
| 89 | projectileConfig->power = config.getFloat("power", 1); |
| 90 | if (config.contains("damagePoly")) { |
| 91 | projectileConfig->damagePoly = jsonToPolyF(config.get("damagePoly")); |
| 92 | projectileConfig->damagePoly.scale(1.0f / TilePixels); |
| 93 | } |
| 94 | projectileConfig->piercing = config.getBool("piercing", false); |
| 95 | projectileConfig->falldown = config.getBool("falldown", false); |
| 96 | projectileConfig->bounces = config.getInt("bounces", 0); |
| 97 | |
| 98 | projectileConfig->actionOnCollide = config.getArray("actionOnCollide", {}); |
| 99 | projectileConfig->actionOnReap = config.getArray("actionOnReap", {}); |
| 100 | projectileConfig->actionOnHit = config.getArray("actionOnHit", {}); |
| 101 | projectileConfig->actionOnTimeout = config.getArray("actionOnTimeout", {}); |
| 102 | |
| 103 | for (auto const& c : config.getArray("periodicActions", {})) |
| 104 | projectileConfig->periodicActions.append(make_tuple(c.getFloat("time"), c.getBool("repeat", true), c)); |
| 105 | |
| 106 | projectileConfig->image = AssetPath::relativeTo(path, config.getString("image")); |
| 107 | projectileConfig->frameNumber = config.getUInt("frameNumber", 1); |
| 108 | projectileConfig->animationCycle = config.getFloat("animationCycle", 1.0); |
| 109 | projectileConfig->animationLoops = config.getBool("animationLoops", true); |
| 110 | projectileConfig->windupFrames = config.getUInt("windupFrames", 0); |
| 111 | projectileConfig->intangibleWindup = config.getBool("intangibleWindup", false); |
| 112 | projectileConfig->winddownFrames = config.getUInt("winddownFrames", 0); |
| 113 | projectileConfig->intangibleWinddown = config.getBool("intangibleWinddown", false); |
| 114 | projectileConfig->flippable = config.getBool("flippable", false); |
| 115 | projectileConfig->orientationLocked = config.getBool("orientationLocked", false); |
| 116 | |
| 117 | projectileConfig->fullbright = config.getBool("fullbright", false); |
| 118 | projectileConfig->renderLayer = parseRenderLayer(config.getString("renderLayer", "Projectile")); |
| 119 | |
| 120 | projectileConfig->lightColor = jsonToColor(config.get("lightColor", JsonArray{0, 0, 0})); |
| 121 | projectileConfig->lightPosition = jsonToVec2F(config.get("lightPosition", JsonArray{0, 0})); |
| 122 | if (auto lightType = config.optString("lightType")) |
| 123 | projectileConfig->lightType = LightTypeNames.getLeft(*lightType); |
| 124 | else |
| 125 | projectileConfig->lightType = (LightType)config.getBool("pointLight", false); |
nothing calls this directly
no test coverage detected