Fix: restructing session manager, ES6 -> ES5

This commit is contained in:
2018-09-14 22:22:22 +09:00
parent 72e7c1a28f
commit 3f340535ac
44 changed files with 3100 additions and 3262 deletions
+76 -79
View File
@@ -1,105 +1,102 @@
class HeartManager {
function HeartManager() {
this.countHearts = HeartManager.DEFAULT_COUNT;
this.countMaxHearts = HeartManager.DEFAULT_COUNT;
constructor() {
this.countHearts = HeartManager.DEFAULT_COUNT;
this.countMaxHearts = HeartManager.DEFAULT_COUNT;
this.onChangeCountListeners = [];
this.onChangeMaxCountListeners = [];
this.onChangeGameOverListeners = [];
}
this.onChangeCountListeners = [];
this.onChangeMaxCountListeners = [];
this.onChangeGameOverListeners = [];
}
callListener(functionArray) {
if(functionArray.length > 0) {
for(let i = 0; i < functionArray.length; i++) {
functionArray[i](this.score);
}
HeartManager.prototype.callListener = function(functionArray) {
if(functionArray.length > 0) {
for(var i = 0; i < functionArray.length; i++) {
functionArray[i](this.score);
}
}
}
addOnChangeCountListener(onChangeFunction) {
this.onChangeCountListeners.push(onChangeFunction);
}
HeartManager.prototype.addOnChangeCountListener = function(onChangeFunction) {
this.onChangeCountListeners.push(onChangeFunction);
}
removeOnChangeCountListener(onChangeFunction) {
let itemIndex = this.onChangeCountListeners.indexOf(onChangeFunction);
if(itemIndex > -1)
this.onChangeCountListeners.splice(itemIndex, 1);
}
HeartManager.prototype.removeOnChangeCountListener = function(onChangeFunction) {
var itemIndex = this.onChangeCountListeners.indexOf(onChangeFunction);
if(itemIndex > -1)
this.onChangeCountListeners.splice(itemIndex, 1);
}
addOnChangeMaxCountListener(onChangeMaxFunction) {
this.onChangeMaxCountListeners.push(onChangeMaxFunction);
}
HeartManager.prototype.addOnChangeMaxCountListener = function(onChangeMaxFunction) {
this.onChangeMaxCountListeners.push(onChangeMaxFunction);
}
removeOnChangeMaxCountListener(onChangeMaxFunction) {
let itemIndex = this.onChangeMaxCountListeners.indexOf(onChangeMaxFunction);
if(itemIndex > -1)
this.onChangeMaxCountListeners.splice(itemIndex, 1);
}
HeartManager.prototype.removeOnChangeMaxCountListener = function(onChangeMaxFunction) {
var itemIndex = this.onChangeMaxCountListeners.indexOf(onChangeMaxFunction);
if(itemIndex > -1)
this.onChangeMaxCountListeners.splice(itemIndex, 1);
}
addOnChangeGameOverListener(onChangeGameOverFunction) {
this.onChangeGameOverListeners.push(onChangeGameOverFunction);
}
HeartManager.prototype.addOnChangeGameOverListener = function(onChangeGameOverFunction) {
this.onChangeGameOverListeners.push(onChangeGameOverFunction);
}
removeOnChangeHighScoreListener(onChangeGameOverFunction) {
let itemIndex = this.onChangeGameOverListeners.indexOf(onChangeGameOverFunction);
if(itemIndex > -1)
this.onChangeGameOverListeners.splice(itemIndex, 1);
}
HeartManager.prototype.removeOnChangeHighScoreListener = function(onChangeGameOverFunction) {
var itemIndex = this.onChangeGameOverListeners.indexOf(onChangeGameOverFunction);
if(itemIndex > -1)
this.onChangeGameOverListeners.splice(itemIndex, 1);
}
removeAllListeners() {
this.onChangeCountListeners = [];
this.onChangeMaxCountListeners = [];
this.onChangeGameOverListeners = [];
}
HeartManager.prototype.removeAllListeners = function() {
this.onChangeCountListeners = [];
this.onChangeMaxCountListeners = [];
this.onChangeGameOverListeners = [];
}
setCount(amount) {
let beforeCountHearts = this.countHearts;
this.countHearts = amount;
if(this.countHearts < 0)
this.countHearts = 0;
else if(this.countHearts > this.countMaxHearts)
this.countHearts = this.countMaxHearts;
HeartManager.prototype.setCount = function(amount) {
var beforeCountHearts = this.countHearts;
this.countHearts = amount;
if(this.countHearts < 0)
this.countHearts = 0;
else if(this.countHearts > this.countMaxHearts)
this.countHearts = this.countMaxHearts;
if(beforeCountHearts !== this.countHearts)
this.callListener(this.onChangeCountListeners);
if(beforeCountHearts !== this.countHearts)
this.callListener(this.onChangeCountListeners);
if(this.countHearts === 0)
this.callListener(this.onChangeGameOverListeners);
}
if(this.countHearts === 0)
this.callListener(this.onChangeGameOverListeners);
}
getCount() {
return this.countHearts;
}
HeartManager.prototype.getCount = function() {
return this.countHearts;
}
setMaxCount(amount) {
let beforeCountHearts = this.countMaxHearts;
this.countMaxHearts = amount;
if(this.countMaxHearts > HeartManager.HEART_MAX_COUNT)
this.countMaxHearts = HeartManager.HEART_MAX_COUNT;
HeartManager.prototype.setMaxCount = function(amount) {
var beforeCountHearts = this.countMaxHearts;
this.countMaxHearts = amount;
if(this.countMaxHearts > HeartManager.HEART_MAX_COUNT)
this.countMaxHearts = HeartManager.HEART_MAX_COUNT;
if(beforeCountHearts !== this.countMaxHearts)
this.callListener(this.onChangeMaxCountListeners);
if(beforeCountHearts !== this.countMaxHearts)
this.callListener(this.onChangeMaxCountListeners);
if(this.countHearts > this.countMaxHearts)
this.setCount(this.countMaxHearts);
}
if(this.countHearts > this.countMaxHearts)
this.setCount(this.countMaxHearts);
}
getMaxCount() {
return this.countMaxHearts;
}
HeartManager.prototype.getMaxCount = function() {
return this.countMaxHearts;
}
addHearts(amount) {
this.setCount(this.countHearts + amount);
}
breakHearts(amount) {
this.addHearts(-1 * amount);
}
HeartManager.prototype.addHearts = function(amount) {
this.setCount(this.countHearts + amount);
}
HeartManager.prototype.breakHearts = function(amount) {
this.addHearts(-1 * amount);
}
HeartManager.DEFAULT_COUNT = 3;
HeartManager.HEART_MAX_COUNT = 5;