Browse Source

added times triggers, fixed multiple win dialogs

Erinn 8 years ago
parent
commit
62c1b22938
2 changed files with 9 additions and 5 deletions
  1. 9 3
      phaser.inc.php
  2. 0 2
      todo

+ 9 - 3
phaser.inc.php

@@ -143,11 +143,14 @@ function getPortRecipient(from, portNum) {
 function update() {
 function update() {
 }
 }
 
 
+var levelOver = false;
 function donePacket() {
 function donePacket() {
 	this.kill();
 	this.kill();
 	var youWin = true;
 	var youWin = true;
 
 
 	for (var i = 0; i < level.triggers.length; i++) {
 	for (var i = 0; i < level.triggers.length; i++) {
+		if (level.triggers[i].hasOwnProperty("times")) level.triggers[i].times--;
+
 		if (satisfiesTrigger(this, level.triggers[i])) {
 		if (satisfiesTrigger(this, level.triggers[i])) {
 			level.triggers[i].completed = true;
 			level.triggers[i].completed = true;
 		}
 		}
@@ -155,7 +158,8 @@ function donePacket() {
 		if (!level.triggers[i].hasOwnProperty("completed")) youWin = false;
 		if (!level.triggers[i].hasOwnProperty("completed")) youWin = false;
 	}
 	}
 
 
-	if (youWin) {
+	if (!levelOver && youWin) {
+		levelOver = true;
 		$.get("./solns.ajax.php?level="+levelid+"&method=win");
 		$.get("./solns.ajax.php?level="+levelid+"&method=win");
 		$("#winner").dialog({
 		$("#winner").dialog({
 			title:"You win!",
 			title:"You win!",
@@ -172,10 +176,10 @@ function donePacket() {
 
 
 function satisfiesTrigger(pkt, t) {
 function satisfiesTrigger(pkt, t) {
 	if (pkt.dst != t.device) return false;
 	if (pkt.dst != t.device) return false;
-	if (!t.hasOwnProperty("payload")) return true;
+	if (!t.hasOwnProperty("payload") && !t.hasOwnProperty("times")) return true;
 	if (!pkt.hasOwnProperty("payload")) return false;
 	if (!pkt.hasOwnProperty("payload")) return false;
 
 
-	var layers = Object.keys(t.payload);
+	var layers = t.hasOwnProperty("payload") ? Object.keys(t.payload) : [];
 	for (var i = 0; i < layers.length; i++) {
 	for (var i = 0; i < layers.length; i++) {
 		if (!pkt.payload.hasOwnProperty(layers[i])) return false;
 		if (!pkt.payload.hasOwnProperty(layers[i])) return false;
 
 
@@ -186,6 +190,8 @@ function satisfiesTrigger(pkt, t) {
 		}
 		}
 	}
 	}
 
 
+	if (t.hasOwnProperty("times") && t.times > 0) return false;
+
 	return true;
 	return true;
 }
 }
 
 

+ 0 - 2
todo

@@ -5,11 +5,9 @@ blocking
 - convert triggers in level files to arrays
 - convert triggers in level files to arrays
 - update nextLevel in each file
 - update nextLevel in each file
 - update "you win" dialog to handle no nextLevel property
 - update "you win" dialog to handle no nextLevel property
-- process timing triggers
 - prettier level listing
 - prettier level listing
 - resize game on resize viewport (attempt at this at top of ui.js but it's laggy)
 - resize game on resize viewport (attempt at this at top of ui.js but it's laggy)
 - 'repeat' packet property
 - 'repeat' packet property
-- prevent launcher click-spamming?
 - device scripts (?list)
 - device scripts (?list)
 - method to work on test levels
 - method to work on test levels
 - hosted version on DO
 - hosted version on DO