From ead7f3415f97d1f120ec33be23e1acf343a6adb3 Mon Sep 17 00:00:00 2001 From: Hat Kid <6624576+Hat-Kid@users.noreply.github.com> Date: Sun, 14 Aug 2022 23:21:53 +0200 Subject: [PATCH] custom levels: add support for more res types in actor lumps (#1754) * add support for more res types in actor lumps * floatm -> meters --- custom_levels/test-zone/test-zone.jsonc | 11 +++++++++++ goalc/build_level/Entity.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/custom_levels/test-zone/test-zone.jsonc b/custom_levels/test-zone/test-zone.jsonc index 6955436242..3c3aeb8203 100644 --- a/custom_levels/test-zone/test-zone.jsonc +++ b/custom_levels/test-zone/test-zone.jsonc @@ -20,6 +20,17 @@ // this makes collision 2x slower and bigger, so only use if really needed "double_sided_collide": false, + // available res-lump tag data types: + // int32, float, meters, vector, vector4m (meters) + // + // examples: + // + // adds a float tag 'spring-height' with value of 200 meters (1 meter = 4096.0 units): + // "spring-height": ["meters", 200.0] + // + // adds a vector tag 'movie-pos': + // "movie-pos": ["vector", [4096000.0, -176128.0, 1353973.76, 1.0]] + "actors" : [ { "trans": [-21.6238, 20.0496, 17.1191], // translation diff --git a/goalc/build_level/Entity.cpp b/goalc/build_level/Entity.cpp index 05941765c0..afd10ad445 100644 --- a/goalc/build_level/Entity.cpp +++ b/goalc/build_level/Entity.cpp @@ -113,6 +113,30 @@ std::unique_ptr res_from_json_array(const std::string& name, data.push_back(json_array[i].get()); } return std::make_unique(name, data, -1000000000.0000); + } else if (array_type == "vector") { + std::vector data; + for (size_t i = 1; i < json_array.size(); i++) { + data.push_back(vector_from_json(json_array[i])); + } + return std::make_unique(name, data, -1000000000.0000); + } else if (array_type == "vector4m") { + std::vector data; + for (size_t i = 1; i < json_array.size(); i++) { + data.push_back(vectorm4_from_json(json_array[i])); + } + return std::make_unique(name, data, -1000000000.0000); + } else if (array_type == "float") { + std::vector data; + for (size_t i = 1; i < json_array.size(); i++) { + data.push_back(json_array[i].get()); + } + return std::make_unique(name, data, -1000000000.0000); + } else if (array_type == "meters") { + std::vector data; + for (size_t i = 1; i < json_array.size(); i++) { + data.push_back(json_array[i].get() * METER_LENGTH); + } + return std::make_unique(name, data, -1000000000.0000); } else { ASSERT_MSG(false, fmt::format("unsupported array type: {}\n", array_type)); }