This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
YimMenu/src/backend/player_command.hpp
DayibBaba b90ce402a1
Some checks failed
Nightly Build / Check Recent Commit (push) Failing after 5s
Nightly Build / Build Nightly (push) Has been skipped
Nightly Build / Recreate Release (push) Has been skipped
Expand Cmd Executor (#2884)
Added additional commands to showcase suggestion system.
Added a new util file to operate on strings in a unified manner.
Changed input_text_with_hint component to allow for more flags than one.
Added more player seeking features to player_service such as get_by_name()

* Fixed out of bounds suggestion navigation

* Added suggestions to spawn_vehicle command

* Created command play_animation

* Added suggestion support for multi commands

using a semicolon allows for more commands to fire at once, and is now supported with appropriate suggestions

* Added rotation to teleport_to_location command

* Fixed stupid error & added multiple raw command auto fills

* Added sanity checks to avoid nullpointers

* Added context identifiers to player commands

* Added temporary self inclusion to player commands

Needs translation on the translations repo

* Applied rudamentary reviews

* Experimental proxy globalization

* Fixed argument sensitivity on spawn vehicle

* Scrapped 2 ideas (maybe for future)

* Added true and false suggestions to bool commands

---------

Co-authored-by: Andreas Maerten <24669514+Yimura@users.noreply.github.com>
Co-authored-by: gir489 <100792176+gir489returns@users.noreply.github.com>
2024-07-13 00:26:34 +02:00

62 lines
2.5 KiB
C++

#pragma once
#include "command.hpp"
#include "services/players/player_service.hpp"
namespace big
{
class player_command;
class player_all_component : public command
{
player_command* m_parent;
protected:
virtual void execute(const command_arguments& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) override;
virtual std::optional<command_arguments> parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) override;
public:
player_all_component(player_command* parent, const std::string& name, const std::string& label, const std::string& description, std::optional<uint8_t> num_args);
};
inline std::unordered_map<rage::joaat_t, player_command*> g_player_commands;
class player_command : public command
{
friend player_all_component;
std::unique_ptr<player_all_component> m_all_component;
protected:
virtual void execute(const command_arguments& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) override;
virtual void execute(player_ptr player, const command_arguments& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) = 0;
virtual std::optional<command_arguments> parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) override;
virtual std::optional<command_arguments> parse_args_p(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>())
{
return {0};
};
virtual std::optional<std::vector<std::string>> get_argument_suggestions(int arg) override
{
if (arg == 1) // First argument of all player commands is the player name
{
std::vector<std::string> suggestions;
for (auto& player : g_player_service->players() | std::ranges::views::values)
{
suggestions.push_back(player->get_name());
}
return suggestions;
}
return std::nullopt;
};
public:
static player_command* get(rage::joaat_t command)
{
return g_player_commands[command];
}
void call(player_ptr player, const command_arguments& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>());
player_command(const std::string& name, const std::string& label, const std::string& description, std::optional<uint8_t> num_args, bool make_all_version = true);
};
}