}
var keys = [], click = [];
+ loadevents();
+
window.addEventListener("keydown", e => keys[e.keyCode] = true );
window.addEventListener("keyup" , e => keys[e.keyCode] = false);
window.addEventListener("click", m => click = [ map.mapX(m.clientX), map.mapY(m.clientY) ] );
// Process on_trigger events at pixel position x/y
function triggers(x, y) {
const i = map.tileAt(x,y);
- var trigger, item;
- if (map.triggers[i]) for ( trigger of map.triggers[i].filter(
- t => (!t.requires_status) ? true : t.requires_status.find(s => qstatus[s])
- ).filter( t => (!t.requires_not_status) ? true : !t.requires_not_status.find(s => qstatus[s]) )
- ) {
+ if ( map.triggers[i] ) events (
+ map.triggers[i].filter( t => (!t.requires_status) ? true : t.requires_status.find(s => qstatus[s])
+ ).filter( t => (!t.requires_not_status) ? true : !t.requires_not_status.find(s => qstatus[s]) )
+ );
+ }
+
+ function loadevents() {
+ if ( map.info.event ) events(
+ map.info.event.filter( ev => ev.activate == "on_load"
+ ).filter( t => (!t.requires_status) ? true : t.requires_status.find(s => qstatus[s])
+ ).filter( t => (!t.requires_not_status) ? true : !t.requires_not_status.find(s => qstatus[s]) )
+ )
+ }
+
+ function events( events ) {
+ var ev, item;
+
+ for ( ev of events ) {
// game status modification
- if ( trigger.set_status ) for (item of trigger.set_status) {
+ if ( ev.set_status ) for (item of ev.set_status) {
qstatus[item] = true;
}
- if ( trigger.unset_status ) for (item of trigger.unset_status) {
+ if ( ev.unset_status ) for (item of ev.unset_status) {
qstatus[item] = false;
}
- if ( item = trigger.msg ) {
+ if ( item = ev.msg ) {
console.log(item);
}
// intramap (i.e. teleporters)
- if ( item = trigger.intramap ){
+ if ( item = ev.intramap ){
hero.place( map.xOf(item[0], item[1]), map.yOf(item[0], item[1]) );
map.center( map.xOf(item[0], item[1]), map.yOf(item[0], item[1]) );
}
// mapmod (e.g. opening doors, activating platforms, changing terrain, ...)
- if ( trigger.mapmod ) for (item of trigger.mapmod) {
+ if ( ev.mapmod ) for (item of ev.mapmod) {
map.info.layer.find(l => l.type == item[0]).data[item[2] * map.info.header.width + item[1]] = item[3];
}
// intermap (i.e. enter new area)
- if ( item = trigger.intermap ){
+ if ( item = ev.intermap ){
map = new Map(item[0]);
hero.place( map.xOf(item[1], item[2]), map.yOf(item[1], item[2]) );
map.center( map.xOf(item[1], item[2]), map.yOf(item[1], item[2]) );
+ loadevents();
break; // further events would not be valid on new map
}
}