Skip to content

Commit

Permalink
Add updater of global illumination & enable filter
Browse files Browse the repository at this point in the history
- Updater of global illumination
- Updater of enabled / disabled filter
  • Loading branch information
Jim00000 committed Mar 16, 2021
1 parent 0a83999 commit e5145f8
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions JPC_Lighting.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

JPC.lighting = {};
JPC.lighting.__version = 'wip';
JPC.lighting.manager = null;
JPC.lighting.enable = false;

// Awating jpc.core.logger is ready.
await JPC.import['core_logger'];
Expand Down Expand Up @@ -89,25 +91,28 @@

// This class contains metadata of the game map related to lighting.
class JLightingMapConfig extends JPC.core.xmlparser.XMLDocument {
#_enable
#_global_illumination

constructor(text) {
super(text);
const select = JPC.core.misc.select;
this.#_enable = select(this.query('jpc', 'lighting', 'enable').boolean, JLightingMapDefaultConfig.enable);
JPC.lighting.enable = select(this.query('jpc', 'lighting', 'enable').boolean, JLightingMapDefaultConfig.enable);
this.#_global_illumination = select(
this.query('jpc', 'lighting', 'global_illumination').number,
JLightingMapDefaultConfig.global_illumination);
};

get enable() {
return this.#_enable;
return JPC.lighting.enable;
};

get global_illumination() {
return this.#_global_illumination;
};

set global_illumination(value) {
this.#_global_illumination = value;
};
};

// default configuration of game map setting
Expand Down Expand Up @@ -577,7 +582,9 @@
this.updatePlayer();
this.updateLightEventPosition();
this.updateLightEvent();
this.updateGlobalIllumination();
}
this.updateEnableFilter();
};

JLightingManager.prototype.updatePlayer = function() {
Expand All @@ -598,6 +605,15 @@
}
};

JLightingManager.prototype.updateGlobalIllumination = function() {
this.filter.uniforms.globalIllumination = this.mapConfig.global_illumination;
this.filter.enabled = this.mapConfig.enable;
};

JLightingManager.prototype.updateEnableFilter = function() {
this.filter.enabled = this.mapConfig.enable;
}

////////////////////////////////////////////
///// Hook /////
////////////////////////////////////////////
Expand All @@ -606,6 +622,7 @@
Spriteset_Map.prototype.initialize = function() {
_Spriteset_Map__initialize.apply(this, arguments);
this.lighting_manager = new JLightingManager();
JPC.lighting.manager = this.lighting_manager;
this.filters.push(this.lighting_manager.filter);
};

Expand Down

0 comments on commit e5145f8

Please sign in to comment.