Remove unneccesary argument

This commit is contained in:
illegitimate-egg 2025-03-02 16:54:47 +00:00
parent a58b1c9afe
commit f4a75deba7
3 changed files with 3 additions and 11 deletions

View File

@ -206,29 +206,21 @@ impl PlayersWrapper {
struct Context {
#[rhai_type(skip)]
commands: HashMap<String, FnPtr>,
#[rhai_type(skip)]
players: PlayersWrapper,
}
impl Context {
fn new(players: PlayersWrapper) -> Self {
fn new() -> Self {
Self {
commands: HashMap::new(),
players,
}
}
pub fn players(&mut self) -> PlayersWrapper {
self.players.clone()
}
fn register_command(&mut self, name: String, callback: FnPtr) {
self.commands.insert(name, callback);
}
fn build_extra(builder: &mut TypeBuilder<Self>) {
builder.with_fn("Context", Self::new);
builder.with_fn("players", Self::players);
builder.with_fn("register_command", Self::register_command);
}
}

View File

@ -3,7 +3,7 @@ fn metadata() {
}
fn init(players) {
let ctx = Context(players);
let ctx = Context();
ctx.register_command("jimmy", |player| {
players.send_message(player, "He's dead")
});

View File

@ -3,7 +3,7 @@ fn metadata() {
}
fn init(players) {
let ctx = Context(players);
let ctx = Context();
ctx.register_command("ping", |player| {
players.send_message(player, "pong")