@benev/nubs
Version:
user-input system for web games
27 lines • 1.17 kB
JavaScript
import { find_effects_for_cause_by_consulting_bindings } from "../bindings/find_effects_for_cause_by_consulting_bindings.js";
export const setup_cause_and_effect_translation = ({ modes, effects, dispatch_effect, get_current_bindings, }) => {
const keys_pressed = new Set();
return ({ detail: cause_detail }) => {
if (cause_detail.kind === "key") {
if (cause_detail.pressed) {
keys_pressed.add(cause_detail.cause);
}
else {
keys_pressed.delete(cause_detail.cause);
}
}
const matching_effect_names = (find_effects_for_cause_by_consulting_bindings({
modes,
keys_pressed,
cause_detail,
bindings: get_current_bindings(),
}));
const causes = Array.from(keys_pressed).join(" ");
for (const effect of matching_effect_names) {
const effect_detail = { ...cause_detail, effect, cause: causes };
effects[cause_detail.kind][effect] = effect_detail;
dispatch_effect(effect_detail);
}
};
};
//# sourceMappingURL=setup_cause_and_effect_translation.js.map