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

Game: API der PlayerComponent zwingt zu redundanten Code-Schnipseln #1530

Open
cagix opened this issue May 14, 2024 · 0 comments
Open

Game: API der PlayerComponent zwingt zu redundanten Code-Schnipseln #1530

cagix opened this issue May 14, 2024 · 0 comments
Labels
bug Something isn't working dungeon

Comments

@cagix
Copy link
Member

cagix commented May 14, 2024

Mir ist aufgefallen, dass die API der PlayerComponent ... suboptimal ist. Man wird als Nutzer gezwungen, folgenden redundanten Code zu schreiben:

VelocityComponent vc = new VelocityComponent(5f, 5f);
PlayerComponent pc = new PlayerComponent();

pc.registerCallback(
        KeyboardConfig.MOVEMENT_UP.value(),
        entity -> vc.currentYVelocity(vc.yVelocity())
        );

Was hat es mit dem value() auf sich?! Warum muss ich das als Nutzer der API selbst schreiben? Das sollte die PlayerComponent bitte selbst hinkriegen.

Es soll deshalb eine Convenience-Methode hinzugefügt werden:

public final class PlayerComponent implements Component {

    ...

    public Optional<Consumer<Entity>> registerCallback(
            ConfigKey<Integer> key, final Consumer<Entity> callback) {
        return registerCallback(key.value(), callback);
    }

}

Perspektivisch muss die alte API raus. Dazu muss aber (a) eine Deprecation-Warnung erzeugt werden und (b) alle Verwendungen umgebaut werden und (c) die Verschränkung mit dem DSL-Kram geprüft werden.

@cagix cagix added bug Something isn't working dungeon labels May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dungeon
Projects
None yet
Development

No branches or pull requests

1 participant