Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Command Sorting #1580

Merged
merged 23 commits into from
May 17, 2024
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c6c97cc
Update SlashCommandHandler.cpp
Tiernan-Alderman May 14, 2024
aff2d6f
Update SlashCommandHandler.cpp
Tiernan-Alderman May 15, 2024
011317b
Update SlashCommandHandler.cpp
Tiernan-Alderman May 15, 2024
bea742b
Update SlashCommandHandler.cpp
Tiernan-Alderman May 16, 2024
d2eb033
Update dGame/dUtilities/SlashCommandHandler.cpp
Tiernan-Alderman May 16, 2024
490303f
Update SlashCommandHandler.cpp
Tiernan-Alderman May 16, 2024
6866b60
Merge branch 'HelpAlphabetization' of https://github.com/TAHuntling/D…
Tiernan-Alderman May 16, 2024
46e6365
Update SlashCommandHandler.cpp
Tiernan-Alderman May 16, 2024
a61a137
Update SlashCommandHandler.cpp
Tiernan-Alderman May 16, 2024
9e7aa6d
Update dGame/dUtilities/SlashCommandHandler.cpp
Tiernan-Alderman May 16, 2024
9485ccb
Update SlashCommandHandler.cpp
Tiernan-Alderman May 16, 2024
f94ba0c
Merge branch 'HelpAlphabetization' of https://github.com/TAHuntling/D…
Tiernan-Alderman May 16, 2024
1013763
Update SlashCommandHandler.cpp
Tiernan-Alderman May 16, 2024
c1eff9b
Update dGame/dUtilities/SlashCommandHandler.cpp
Tiernan-Alderman May 16, 2024
668872b
Update dGame/dUtilities/SlashCommandHandler.cpp
Tiernan-Alderman May 16, 2024
1bdd242
Update dGame/dUtilities/SlashCommandHandler.cpp
Tiernan-Alderman May 16, 2024
020c4b2
Update dGame/dUtilities/SlashCommandHandler.cpp
Tiernan-Alderman May 16, 2024
34fc9cc
Update dGame/dUtilities/SlashCommandHandler.cpp
Tiernan-Alderman May 16, 2024
21a2301
Update dGame/dUtilities/SlashCommandHandler.cpp
Tiernan-Alderman May 16, 2024
bcf7b0a
Update SlashCommandHandler.cpp
Tiernan-Alderman May 16, 2024
a400e4d
Update dGame/dUtilities/SlashCommandHandler.cpp
Tiernan-Alderman May 16, 2024
edc6ed6
Update SlashCommandHandler.cpp
Tiernan-Alderman May 16, 2024
ac44e37
Update SlashCommandHandler.cpp
Tiernan-Alderman May 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 19 additions & 27 deletions dGame/dUtilities/SlashCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "dServer.h"

namespace {
std::vector<Command> CommandInfos;
std::map<std::string, Command> CommandInfos;
std::map<std::string, Command> RegisteredCommands;
}

Expand All @@ -38,9 +38,8 @@ void SlashCommandHandler::RegisterCommand(Command command) {
continue;
}
}

CommandInfos.push_back(command);
};
CommandInfos[command.aliases[0]] = command;
}

void SlashCommandHandler::HandleChatCommand(const std::u16string& chat, Entity* entity, const SystemAddress& sysAddr) {
auto input = GeneralUtils::UTF16ToWTF8(chat);
Expand Down Expand Up @@ -74,38 +73,31 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& chat, Entity*
}
}

// This commands in here so we can access the CommandInfos to display info
void GMZeroCommands::Help(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
std::ostringstream feedback;
if (args.empty()) {
feedback << "----- Commands -----";
for (const auto& command : CommandInfos) {
for (const auto& [alias, command] : CommandInfos) {
// TODO: Limit displaying commands based on GM level they require
if (command.requiredLevel > entity->GetGMLevel()) continue;
LOG("Help command: %s", command.aliases[0].c_str());
feedback << "\n/" << command.aliases[0] << ": " << command.help;
LOG("Help command: %s", alias.c_str());
feedback << "\n/" << alias << ": " << command.help;
}
} else {
bool foundCommand = false;
for (const auto& command : CommandInfos) {
if (std::ranges::find(command.aliases, args) == command.aliases.end()) continue;

if (entity->GetGMLevel() < command.requiredLevel) break;
foundCommand = true;
feedback << "----- " << command.aliases.at(0) << " -----\n";
// info can be a localizable string
feedback << command.info;
if (command.aliases.size() == 1) break;

feedback << "\nAliases: ";
for (size_t i = 0; i < command.aliases.size(); i++) {
if (i > 0) feedback << ", ";
feedback << command.aliases[i];
auto it = CommandInfos.find(args);
if (it != CommandInfos.end() && entity->GetGMLevel() >= it->second.requiredLevel) {
feedback << "----- " << args << " -----\n";
feedback << it->second.info;
if (it->second.aliases.size() > 1) {
feedback << "\nAliases: ";
for (size_t i = 0; i < it->second.aliases.size(); i++) {
if (i > 0) feedback << ", ";
feedback << it->second.aliases[i];
}
}
} else if (entity->GetGMLevel() > eGameMasterLevel::CIVILIAN) {
feedback << "Command " << std::quoted(args) << " does not exist!";
}

// Let GameMasters know if the command doesn't exist
if (!foundCommand && entity->GetGMLevel() > eGameMasterLevel::CIVILIAN) feedback << "Command " << std::quoted(args) << " does not exist!";
}
const auto feedbackStr = feedback.str();
if (!feedbackStr.empty()) GameMessages::SendSlashCommandFeedbackText(entity, GeneralUtils::ASCIIToUTF16(feedbackStr));
Expand Down Expand Up @@ -900,7 +892,7 @@ void SlashCommandHandler::Startup() {

Command HelpCommand{
.help = "Display command info",
.info = "If a command is given, display detailed info on that command. Otherwise display a list of commands with short desctiptions.",
.info = "If a command is given, display detailed info on that command. Otherwise display a list of commands with short descriptions.",
.aliases = { "help", "h"},
.handle = GMZeroCommands::Help,
.requiredLevel = eGameMasterLevel::CIVILIAN
Expand Down
Loading