UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

67 lines (52 loc) 1.57 kB
import { SystemEntityContext } from "../../../ecs/system/SystemEntityContext.js"; import { FPLightBinding } from "./binding/fp/FPLightBinding.js"; import { ThreeLightBinding } from "./binding/three/ThreeLightBinding.js"; import { LightType } from "./LightType.js"; export class LightContext extends SystemEntityContext { /** * * @type {LightBinding|null} * @private */ __binding = null; /** * * @return {Light} */ getLight() { return this.components[0]; } /** * * @return {Transform} */ getTransform() { return this.components[1]; } __rebuild() { this.__binding.unlink(this); this.__build(); this.__binding.link(this); } __build() { if (this.getLight().type.getValue() === LightType.POINT && this.system.__use_forward_plus) { this.__binding = new FPLightBinding(); } else { this.__binding = new ThreeLightBinding(); } this.__binding.component_light = this.getLight(); this.__binding.component_transform = this.getTransform(); } applySettings() { this.__binding.applySettings(this.system.settings); } link() { this.__build(); this.__binding.link(this); this.getLight().type.onChanged.add(this.__rebuild, this); } unlink() { this.getLight().type.onChanged.remove(this.__rebuild, this); this.__binding.unlink(this); } }