@benev/nubs
Version:
user-input system for web games
90 lines • 4.72 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _NubContext_bindings_controller, _NubContext_effects, _NubContext_translate;
import { html, LitElement } from "lit";
import { property } from "lit/decorators.js";
import { set_initial_modes } from "./utils/set_initial_modes.js";
import { Bindings_Controller } from "./bindings/bindings_controller.js";
import { NubModesEvent } from "../../events/modes.js";
import { NubEffectEvent } from "../../events/effect.js";
import { NubBindingsEvent } from "../../events/bindings.js";
import { setup_modes_and_handle_changes } from "./setups/setup_modes_and_handle_changes.js";
import { setup_effects_and_readable_proxy } from "./setups/setup_effects_and_readable_proxy.js";
import { setup_cause_and_effect_translation } from "./setups/setup_cause_and_effect_translation.js";
export class NubContext extends LitElement {
constructor() {
super(...arguments);
this["name"] = "default";
this["initial-modes"] = "humanoid";
this.modes = "";
this.modes_set = setup_modes_and_handle_changes(modes => {
this.modes = modes.array().join(" ");
NubModesEvent
.target(this)
.dispatch({ modes });
});
_NubContext_bindings_controller.set(this, new Bindings_Controller({
storage: localStorage,
on_bindings_change: bindings => NubBindingsEvent
.target(this)
.dispatch({ bindings }),
}));
_NubContext_effects.set(this, setup_effects_and_readable_proxy());
_NubContext_translate.set(this, setup_cause_and_effect_translation({
modes: this.modes_set.readable,
effects: __classPrivateFieldGet(this, _NubContext_effects, "f").writable,
get_current_bindings: () => __classPrivateFieldGet(this, _NubContext_bindings_controller, "f").bindings,
dispatch_effect: detail => NubEffectEvent
.target(this)
.dispatch(detail),
}));
}
get effects() {
return __classPrivateFieldGet(this, _NubContext_effects, "f").readable;
}
get schema() {
return __classPrivateFieldGet(this, _NubContext_bindings_controller, "f").schema;
}
set schema(schema) {
__classPrivateFieldGet(this, _NubContext_bindings_controller, "f").schema = schema;
}
get bindings() {
return __classPrivateFieldGet(this, _NubContext_bindings_controller, "f").bindings;
}
set bindings(b) {
__classPrivateFieldGet(this, _NubContext_bindings_controller, "f").bindings = b;
}
reset_bindings_to_defaults() {
__classPrivateFieldGet(this, _NubContext_bindings_controller, "f").bindings = __classPrivateFieldGet(this, _NubContext_bindings_controller, "f").defaults;
}
firstUpdated() {
set_initial_modes(this.modes_set, this["initial-modes"]);
__classPrivateFieldGet(this, _NubContext_bindings_controller, "f").storage_key = "nub_bindings_" + this["name"];
__classPrivateFieldGet(this, _NubContext_bindings_controller, "f").load_from_storage();
}
render() {
return html `
<slot =${__classPrivateFieldGet(this, _NubContext_translate, "f")}></slot>
`;
}
}
_NubContext_bindings_controller = new WeakMap(), _NubContext_effects = new WeakMap(), _NubContext_translate = new WeakMap();
__decorate([
property({ type: String })
], NubContext.prototype, "name", void 0);
__decorate([
property({ type: String })
], NubContext.prototype, "initial-modes", void 0);
__decorate([
property({ type: String, reflect: true })
], NubContext.prototype, "modes", void 0);
//# sourceMappingURL=element.js.map