-
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make param option and praser into traits
- Loading branch information
Showing
14 changed files
with
175 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
#include "ll/api/base/StdInt.h" | ||
#include "ll/api/command/ParamTraits.h" | ||
|
||
namespace ll::command { | ||
struct RuntimeEnum { | ||
std::string name; | ||
uint64 index; | ||
}; | ||
struct RuntimeSoftEnum : std::string { | ||
using std::string::string; | ||
}; | ||
template <> | ||
struct ParamTraits<RuntimeEnum> : ParamTraitsBase<RuntimeEnum> { | ||
struct Parser { | ||
bool | ||
operator()(CommandRegistry const& registry, void* storage, CommandRegistry::ParseToken const& token, CommandOrigin const&, int, std::string&, std::vector<std::string>&) | ||
const { | ||
*(RuntimeEnum*)storage = {token.toString(), registry.getEnumData(token)}; | ||
return true; | ||
} | ||
}; | ||
static constexpr CommandParameterDataType dataType() { return CommandParameterDataType::Enum; } | ||
static constexpr CommandParameterOption options() { return CommandParameterOption::EnumAutocompleteExpansion; } | ||
}; | ||
template <> | ||
struct ParamTraits<RuntimeSoftEnum> : ParamTraitsBase<RuntimeSoftEnum> { | ||
static constexpr CommandParameterDataType dataType() { return CommandParameterDataType::SoftEnum; } | ||
static constexpr CommandParameterOption options() { return CommandParameterOption::EnumAutocompleteExpansion; } | ||
static inline CommandRegistry::ParseFn parseFn() { return &CommandRegistry::parse<std::string>; } | ||
static Bedrock::typeid_t<CommandRegistry> typeId() { return Bedrock::type_id<CommandRegistry, std::string>(); } | ||
}; | ||
} // namespace ll::command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.