Skip to content

Commit

Permalink
Updated block property handling
Browse files Browse the repository at this point in the history
  • Loading branch information
SmokeyStack committed Aug 12, 2024
1 parent 4de5bac commit 288b5d9
Show file tree
Hide file tree
Showing 17 changed files with 788 additions and 1,616 deletions.
1,026 changes: 7 additions & 1,019 deletions adk/data/assets/stairs.geo.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions adk/data/include/block/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace adk {
class Block {
public:
Block() {};
~Block() {};

/**
* @brief Returns the type of the object
Expand Down
155 changes: 133 additions & 22 deletions adk/data/include/block/property.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
#pragma once

#include <set>
#include <unordered_set>
#include <vector>

#include "json.hpp"

namespace adk {
class PropertyTrait {
/**
* @brief Property Class
*/
class Property {
public:
Property() {}
~Property() {}
virtual nlohmann::json::object_t Generate() = 0;
};

// Property Traits

/**
* @brief Block Trait
*/
class PropertyTrait : public Property {
public:
PropertyTrait() {}
~PropertyTrait() {}
virtual nlohmann::json::object_t Generate() = 0;
};

/**
* @brief Block Trait - Placement Direction
*/
class PlacementDirection : public PropertyTrait {
public:
enum class EnabledStates {
Expand All @@ -21,13 +40,30 @@ namespace adk {
PlacementDirection() {}
~PlacementDirection() {}
nlohmann::json::object_t Generate() override;

/**
* @brief Adds the enabled state
*
* @param state EnabledStates enum
*
* @return PlacementDirection&
*/
PlacementDirection& AddEnabledState(EnabledStates state);

/**
* @brief Sets the Y rotation offset
*
* @param offset Rotation Offset in Degrees
*/
void SetYRotationOffset(double offset);
private:
std::set<EnabledStates> enabled_states_;
std::unordered_set<EnabledStates> enabled_states_;
double y_rotation_offset_ = 0.0;
};

/**
* @brief Block Trait - Placement Position
*/
class PlacementPosition : public PropertyTrait {
public:
enum class EnabledStates {
Expand All @@ -37,70 +73,145 @@ namespace adk {
PlacementPosition() {}
~PlacementPosition() {}
nlohmann::json::object_t Generate() override;

/**
* @brief Adds the enabled state
* @param state
* @return
*/
PlacementPosition& AddEnabledState(EnabledStates state);
private:
std::set<EnabledStates> enabled_states_;
std::unordered_set<EnabledStates> enabled_states_;
};

class PropertyState {
// Property States

/**
* @brief Block State
*/
class PropertyState : public Property {
public:
/**
* @brief Block State
*
* @param name The name of the block state
*/
PropertyState(std::string name) : name_(name) {}
~PropertyState() {}
virtual nlohmann::json::object_t Generate() = 0;
protected:
std::string name_;
};

/**
* @brief Block State - String
*/
class StateString : public PropertyState {
public:
/**
* @brief Block State - String
*
* @param name The name of the block state
*/
StateString(std::string name) : PropertyState(name) {}
~StateString() {}
nlohmann::json::object_t Generate() override;

/**
* @brief Adds a value to the block state
*
* @param value The value to add
*
* @return StateString&
*/
StateString& AddValue(std::string value);
StateString& AddValue(std::set<std::string> value);

/**
* @brief Adds a value to the block state
*
* @param value The value to add
*
* @return StateString&
*/
StateString& AddValue(std::unordered_set<std::string> value);
private:
std::set<std::string> values_;
std::vector<std::string> values_;
std::unordered_set<std::string> internal_values_;
};

/**
* @brief Block State - Boolean
*/
class StateBoolean : public PropertyState {
public:
/**
* @brief Block State - Boolean
*
* @param name The name of the block state
*
* @param default_value The default value of the block state
*/
StateBoolean(std::string name, bool default_value) : default_value_(default_value), PropertyState(name) {}
~StateBoolean() {}
nlohmann::json::object_t Generate() override;
private:
bool default_value_;
};

/**
* @brief Block State - Integer
*/
class StateInt : public PropertyState {
public:
/**
* @brief Block State - Integer
*
* @param name The name of the block state
*/
StateInt(std::string name) : PropertyState(name) {}
~StateInt() {}
nlohmann::json::object_t Generate() override;

/**
* @brief Adds a value to the block state
*
* @param value The value to add
*
* @return StateInt&
*/
StateInt& AddValue(int value);
StateInt& AddValue(std::set<int> value);

/**
* @brief Adds a value to the block state
*
* @param value The value to add
*
* @return StateInt&
*/
StateInt& AddValue(std::unordered_set<int> value);
private:
std::set<int> values_;
std::vector<int> values_;
std::unordered_set<int> internal_values_;
};

/**
* @brief Block State - Integer Range
*/
class StateIntRange : public PropertyState {
public:
/**
* @brief Block State - Integer Range
*
* @param name The name of the block state
*
* @param min The minimum value of the block state
*
* @param max The maximum value of the block state
*/
StateIntRange(std::string name, int min, int max) : min_(min), max_(max), PropertyState(name) {}
~StateIntRange() {}
nlohmann::json::object_t Generate() override;
private:
int min_;
int max_;
};

class Property {
public:
Property() {}
~Property() {}
nlohmann::json Generate();
Property& AddTrait(std::unique_ptr<PropertyTrait> trait);
Property& AddState(std::unique_ptr<PropertyState> state);
private:
std::set<std::unique_ptr<PropertyTrait>> traits_;
std::set<std::unique_ptr<PropertyState>> states_;
};
} // namespace adk
Loading

0 comments on commit 288b5d9

Please sign in to comment.