refactor enums: CursorShape, InterpolationType, ParticleSpawnShape
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
#define VC_ENABLE_REFLECTION
|
||||||
#include "../ContentLoader.hpp"
|
#include "../ContentLoader.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -210,13 +211,9 @@ void ContentLoader::loadGenerator(
|
|||||||
map.at("heights-bpd").get(def.heightsBPD);
|
map.at("heights-bpd").get(def.heightsBPD);
|
||||||
std::string interpName;
|
std::string interpName;
|
||||||
map.at("heights-interpolation").get(interpName);
|
map.at("heights-interpolation").get(interpName);
|
||||||
if (auto interp = InterpolationType_from(interpName)) {
|
InterpolationTypeMeta.getItem(interpName, def.heightsInterpolation);
|
||||||
def.heightsInterpolation = *interp;
|
|
||||||
}
|
|
||||||
map.at("biomes-interpolation").get(interpName);
|
map.at("biomes-interpolation").get(interpName);
|
||||||
if (auto interp = InterpolationType_from(interpName)) {
|
InterpolationTypeMeta.getItem(interpName, def.biomesInterpolation);
|
||||||
def.biomesInterpolation = *interp;
|
|
||||||
}
|
|
||||||
|
|
||||||
map.at("sea-level").get(def.seaLevel);
|
map.at("sea-level").get(def.seaLevel);
|
||||||
map.at("wide-structs-chunks-radius").get(def.wideStructsChunksRadius);
|
map.at("wide-structs-chunks-radius").get(def.wideStructsChunksRadius);
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
#include "commons.hpp"
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
std::optional<CursorShape> CursorShape_from(std::string_view name) {
|
|
||||||
static std::map<std::string_view, CursorShape> shapes = {
|
|
||||||
{"arrow", CursorShape::ARROW},
|
|
||||||
{"text", CursorShape::TEXT},
|
|
||||||
{"crosshair", CursorShape::CROSSHAIR},
|
|
||||||
{"pointer", CursorShape::POINTER},
|
|
||||||
{"ew-resize", CursorShape::EW_RESIZE},
|
|
||||||
{"ns-resize", CursorShape::NS_RESIZE},
|
|
||||||
{"nwse-resize", CursorShape::NWSE_RESIZE},
|
|
||||||
{"nesw-resize", CursorShape::NESW_RESIZE},
|
|
||||||
{"all-resize", CursorShape::ALL_RESIZE},
|
|
||||||
{"not-allowed", CursorShape::NOT_ALLOWED}
|
|
||||||
};
|
|
||||||
const auto& found = shapes.find(name);
|
|
||||||
if (found == shapes.end()) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
return found->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string to_string(CursorShape shape) {
|
|
||||||
static std::string names[] = {
|
|
||||||
"arrow",
|
|
||||||
"text",
|
|
||||||
"crosshair",
|
|
||||||
"pointer",
|
|
||||||
"ew-resize",
|
|
||||||
"ns-resize",
|
|
||||||
"nwse-resize",
|
|
||||||
"nesw-resize",
|
|
||||||
"all-resize",
|
|
||||||
"not-allowed"
|
|
||||||
};
|
|
||||||
return names[static_cast<int>(shape)];
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
#include "util/EnumMetadata.hpp"
|
||||||
|
|
||||||
enum class DrawPrimitive {
|
enum class DrawPrimitive {
|
||||||
point = 0,
|
point = 0,
|
||||||
line,
|
line,
|
||||||
@@ -48,8 +50,18 @@ enum class CursorShape {
|
|||||||
LAST=NOT_ALLOWED
|
LAST=NOT_ALLOWED
|
||||||
};
|
};
|
||||||
|
|
||||||
std::optional<CursorShape> CursorShape_from(std::string_view name);
|
VC_ENUM_METADATA(CursorShape)
|
||||||
std::string to_string(CursorShape shape);
|
{"arrow", CursorShape::ARROW},
|
||||||
|
{"text", CursorShape::TEXT},
|
||||||
|
{"crosshair", CursorShape::CROSSHAIR},
|
||||||
|
{"pointer", CursorShape::POINTER},
|
||||||
|
{"ew-resize", CursorShape::EW_RESIZE},
|
||||||
|
{"ns-resize", CursorShape::NS_RESIZE},
|
||||||
|
{"nwse-resize", CursorShape::NWSE_RESIZE},
|
||||||
|
{"nesw-resize", CursorShape::NESW_RESIZE},
|
||||||
|
{"all-resize", CursorShape::ALL_RESIZE},
|
||||||
|
{"not-allowed", CursorShape::NOT_ALLOWED},
|
||||||
|
VC_ENUM_END
|
||||||
|
|
||||||
class Flushable {
|
class Flushable {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#define VC_ENABLE_REFLECTION
|
||||||
#include "gui_xml.hpp"
|
#include "gui_xml.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
@@ -168,8 +169,9 @@ static void read_uinode(
|
|||||||
node.setTooltipDelay(element.attr("tooltip-delay").asFloat());
|
node.setTooltipDelay(element.attr("tooltip-delay").asFloat());
|
||||||
}
|
}
|
||||||
if (element.has("cursor")) {
|
if (element.has("cursor")) {
|
||||||
if (auto cursor = CursorShape_from(element.attr("cursor").getText())) {
|
CursorShape cursor;
|
||||||
node.setCursor(*cursor);
|
if (CursorShapeMeta.getItem(element.attr("cursor").getText(), cursor)) {
|
||||||
|
node.setCursor(cursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#define VC_ENABLE_REFLECTION
|
||||||
#include "libgui.hpp"
|
#include "libgui.hpp"
|
||||||
#include "assets/Assets.hpp"
|
#include "assets/Assets.hpp"
|
||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
@@ -422,7 +423,7 @@ static int p_get_line_pos(UINode*, lua::State* L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int p_get_cursor(UINode* node, lua::State* L) {
|
static int p_get_cursor(UINode* node, lua::State* L) {
|
||||||
return lua::pushstring(L, to_string(node->getCursor()));
|
return lua::pushlstring(L, CursorShapeMeta.getName(node->getCursor()));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int p_get_scroll(UINode* node, lua::State* L) {
|
static int p_get_scroll(UINode* node, lua::State* L) {
|
||||||
@@ -660,9 +661,9 @@ static void p_set_focused(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void p_set_cursor(UINode* node, lua::State* L, int idx) {
|
static void p_set_cursor(UINode* node, lua::State* L, int idx) {
|
||||||
if (auto cursor = CursorShape_from(lua::require_string(L, idx))) {
|
auto cursor = CursorShape::ARROW; // reset to default
|
||||||
node->setCursor(*cursor);
|
CursorShapeMeta.getItem(lua::require_string(L, idx), cursor);
|
||||||
}
|
node->setCursor(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int p_set_scroll(UINode* node, lua::State* L, int idx) {
|
static int p_set_scroll(UINode* node, lua::State* L, int idx) {
|
||||||
|
|||||||
@@ -5,17 +5,6 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
std::optional<InterpolationType> InterpolationType_from(std::string_view str) {
|
|
||||||
if (str == "nearest") {
|
|
||||||
return InterpolationType::NEAREST;
|
|
||||||
} else if (str == "linear") {
|
|
||||||
return InterpolationType::LINEAR;
|
|
||||||
} else if (str == "cubic") {
|
|
||||||
return InterpolationType::CUBIC;
|
|
||||||
}
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline float sample_at(
|
static inline float sample_at(
|
||||||
const float* buffer,
|
const float* buffer,
|
||||||
uint width,
|
uint width,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "typedefs.hpp"
|
#include "typedefs.hpp"
|
||||||
#include "maths/Heightmap.hpp"
|
#include "maths/Heightmap.hpp"
|
||||||
|
#include "util/EnumMetadata.hpp"
|
||||||
|
|
||||||
enum class InterpolationType {
|
enum class InterpolationType {
|
||||||
NEAREST,
|
NEAREST,
|
||||||
@@ -13,7 +14,11 @@ enum class InterpolationType {
|
|||||||
CUBIC,
|
CUBIC,
|
||||||
};
|
};
|
||||||
|
|
||||||
std::optional<InterpolationType> InterpolationType_from(std::string_view str);
|
VC_ENUM_METADATA(InterpolationType)
|
||||||
|
{"nearest", InterpolationType::NEAREST},
|
||||||
|
{"linear", InterpolationType::LINEAR},
|
||||||
|
{"cubic", InterpolationType::CUBIC},
|
||||||
|
VC_ENUM_END
|
||||||
|
|
||||||
class Heightmap {
|
class Heightmap {
|
||||||
uint width, height;
|
uint width, height;
|
||||||
|
|||||||
@@ -1,26 +1,8 @@
|
|||||||
|
#define VC_ENABLE_REFLECTION
|
||||||
|
|
||||||
#include "ParticlesPreset.hpp"
|
#include "ParticlesPreset.hpp"
|
||||||
|
|
||||||
#include "data/dv_util.hpp"
|
#include "data/dv_util.hpp"
|
||||||
|
|
||||||
std::string to_string(ParticleSpawnShape shape) {
|
|
||||||
static std::string names[] = {
|
|
||||||
"ball",
|
|
||||||
"sphere",
|
|
||||||
"box"
|
|
||||||
};
|
|
||||||
return names[static_cast<int>(shape)];
|
|
||||||
}
|
|
||||||
|
|
||||||
ParticleSpawnShape ParticleSpawnShape_from(std::string_view s) {
|
|
||||||
if (s == "ball") {
|
|
||||||
return ParticleSpawnShape::BALL;
|
|
||||||
} else if (s == "sphere") {
|
|
||||||
return ParticleSpawnShape::SPHERE;
|
|
||||||
} else {
|
|
||||||
return ParticleSpawnShape::BOX;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dv::value ParticlesPreset::serialize() const {
|
dv::value ParticlesPreset::serialize() const {
|
||||||
auto root = dv::object();
|
auto root = dv::object();
|
||||||
if (frames.empty()) {
|
if (frames.empty()) {
|
||||||
@@ -47,7 +29,7 @@ dv::value ParticlesPreset::serialize() const {
|
|||||||
root["min_angular_vel"] = minAngularVelocity;
|
root["min_angular_vel"] = minAngularVelocity;
|
||||||
root["max_angular_vel"] = maxAngularVelocity;
|
root["max_angular_vel"] = maxAngularVelocity;
|
||||||
root["spawn_spread"] = dv::to_value(size);
|
root["spawn_spread"] = dv::to_value(size);
|
||||||
root["spawn_shape"] = to_string(spawnShape);
|
root["spawn_shape"] = ParticleSpawnShapeMeta.getName(spawnShape);
|
||||||
root["random_sub_uv"] = randomSubUV;
|
root["random_sub_uv"] = randomSubUV;
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
@@ -82,7 +64,7 @@ void ParticlesPreset::deserialize(const dv::value& src) {
|
|||||||
dv::get_vec(src["explosion"], explosion);
|
dv::get_vec(src["explosion"], explosion);
|
||||||
}
|
}
|
||||||
if (src.has("spawn_shape")) {
|
if (src.has("spawn_shape")) {
|
||||||
spawnShape = ParticleSpawnShape_from(src["spawn_shape"].asString());
|
ParticleSpawnShapeMeta.getItem(src["spawn_shape"].asString(), spawnShape);
|
||||||
}
|
}
|
||||||
if (src.has("frames")) {
|
if (src.has("frames")) {
|
||||||
for (const auto& frame : src["frames"]) {
|
for (const auto& frame : src["frames"]) {
|
||||||
|
|||||||
@@ -5,8 +5,9 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "interfaces/Serializable.hpp"
|
#include "interfaces/Serializable.hpp"
|
||||||
|
#include "util/EnumMetadata.hpp"
|
||||||
|
|
||||||
enum ParticleSpawnShape {
|
enum class ParticleSpawnShape {
|
||||||
/// @brief Coordinates are regulary distributed within
|
/// @brief Coordinates are regulary distributed within
|
||||||
/// the volume of a ball.
|
/// the volume of a ball.
|
||||||
BALL = 0,
|
BALL = 0,
|
||||||
@@ -18,8 +19,11 @@ enum ParticleSpawnShape {
|
|||||||
BOX
|
BOX
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string to_string(ParticleSpawnShape shape);
|
VC_ENUM_METADATA(ParticleSpawnShape)
|
||||||
ParticleSpawnShape ParticleSpawnShape_from(std::string_view s);
|
{"ball", ParticleSpawnShape::BALL},
|
||||||
|
{"sphere", ParticleSpawnShape::SPHERE},
|
||||||
|
{"box", ParticleSpawnShape::BOX},
|
||||||
|
VC_ENUM_END
|
||||||
|
|
||||||
struct ParticlesPreset : public Serializable {
|
struct ParticlesPreset : public Serializable {
|
||||||
/// @brief Collision detection
|
/// @brief Collision detection
|
||||||
@@ -53,7 +57,7 @@ struct ParticlesPreset : public Serializable {
|
|||||||
/// @brief Maximum angular velocity
|
/// @brief Maximum angular velocity
|
||||||
float maxAngularVelocity = 0.0f;
|
float maxAngularVelocity = 0.0f;
|
||||||
/// @brief Spawn spread shape
|
/// @brief Spawn spread shape
|
||||||
ParticleSpawnShape spawnShape = BALL;
|
ParticleSpawnShape spawnShape = ParticleSpawnShape::BALL;
|
||||||
/// @brief Spawn spread
|
/// @brief Spawn spread
|
||||||
glm::vec3 spawnSpread {};
|
glm::vec3 spawnSpread {};
|
||||||
/// @brief Texture name
|
/// @brief Texture name
|
||||||
|
|||||||
Reference in New Issue
Block a user