|
|
@ -263,54 +263,94 @@ function BurningDataService($http) { |
|
|
|
// A hash of StartingStatPoints objects keyed by stock.
|
|
|
|
// A hash of StartingStatPoints objects keyed by stock.
|
|
|
|
this.startingStatPts = {}; |
|
|
|
this.startingStatPts = {}; |
|
|
|
|
|
|
|
|
|
|
|
// this.dataSetsLoaded = 0;
|
|
|
|
this.events = { |
|
|
|
// // Total data sets:
|
|
|
|
stocksLoaded: { triggered : false, callbacks : [] }, |
|
|
|
// // lifepaths: 7 (man, dwarf, elf, orc, roden, wolf, troll)
|
|
|
|
traitsLoaded: { triggered : false, callbacks : [] }, |
|
|
|
// // stat points: 7 (man, dwarf, elf, orc, roden, wolf, troll)
|
|
|
|
skillsLoaded: { triggered : false, callbacks : [] }, |
|
|
|
// // skills
|
|
|
|
} |
|
|
|
// // traits
|
|
|
|
|
|
|
|
// // resources: 7 (man, dwarf, elf, orc, roden, wolf. troll)
|
|
|
|
this.registerEvent = function(eventName, callback){ |
|
|
|
// // TOTAL: 23
|
|
|
|
if(this.events[eventName].triggered) |
|
|
|
// this.totalDataSets = 23;
|
|
|
|
callback(); |
|
|
|
// this.onAllDatasetsLoaded = null;
|
|
|
|
this.events[eventName].callbacks.push(callback); |
|
|
|
this.registerOnAllDatasetsLoaded = function(callback){ |
|
|
|
} |
|
|
|
if ( this.dataSetsLoaded >= this.totalDataSets ){ |
|
|
|
this.triggerEvent = function(eventName) { |
|
|
|
|
|
|
|
myself.events[eventName].triggered = true; |
|
|
|
|
|
|
|
for(var callback of myself.events[eventName].callbacks) { |
|
|
|
|
|
|
|
callback(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.stockEvents = {}; |
|
|
|
|
|
|
|
this.defineStockEvent = function(stockName, eventName) { |
|
|
|
|
|
|
|
if(!(stockName in myself.stockEvents)) myself.stockEvents[stockName] = {}; |
|
|
|
|
|
|
|
myself.stockEvents[stockName][eventName] = { triggered : false, callbacks : [] } ; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.registerStockEvent = function(stockName, eventName, callback){ |
|
|
|
|
|
|
|
if(myself.stockEvents[stockName][eventName].triggered) |
|
|
|
|
|
|
|
callback(); |
|
|
|
|
|
|
|
myself.stockEvents[stockName][eventName].callbacks.push(callback); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.triggerStockEvent = function(stockName, eventName) { |
|
|
|
|
|
|
|
myself.stockEvents[stockName][eventName].triggered = true; |
|
|
|
|
|
|
|
for(var callback of myself.stockEvents[stockName][eventName].callbacks) { |
|
|
|
callback(); |
|
|
|
callback(); |
|
|
|
} |
|
|
|
} |
|
|
|
this.onAllDatasetsLoaded = callback; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// this.datasetLoaded = function(){
|
|
|
|
|
|
|
|
// this.dataSetsLoaded += 1;
|
|
|
|
|
|
|
|
// if ( this.onAllDatasetsLoaded && (this.dataSetsLoaded >= this.totalDataSets) ){
|
|
|
|
|
|
|
|
// this.onAllDatasetsLoaded();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if ( this.dataSetsLoaded > this.totalDataSets){
|
|
|
|
|
|
|
|
// console.log("Error: the totalDataSets setting in BurningDataService is too low! This will cause wierd errors. Please adjust it");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var myself = this; |
|
|
|
var myself = this; |
|
|
|
var stocks; |
|
|
|
var stocks; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Log events
|
|
|
|
|
|
|
|
this.registerEvent("stocksLoaded", function() { |
|
|
|
|
|
|
|
console.log("Stocks fetched from server: ", Object.keys(myself.stocks)) |
|
|
|
|
|
|
|
// DEBUG:
|
|
|
|
|
|
|
|
// console.log("Stocks fetched from server: ", myself.stocks)
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
this.registerEvent("skillsLoaded", function() { |
|
|
|
|
|
|
|
console.log("Loaded " + Object.keys(myself.skills).length + " skills."); |
|
|
|
|
|
|
|
// DEBUG:
|
|
|
|
|
|
|
|
// console.log("Loaded skills: ", myself.skills);
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
this.registerEvent("traitsLoaded", function() { |
|
|
|
|
|
|
|
console.log("Loaded " + Object.keys(myself.traits).length + " traits."); |
|
|
|
|
|
|
|
// DEBUG:
|
|
|
|
|
|
|
|
// console.log("Loaded traits: ", myself.traits);
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
$http.get("/stocks", {'timeout': 3000}). |
|
|
|
$http.get("/stocks", {'timeout': 3000}). |
|
|
|
success(function(data,status,headers,config){ |
|
|
|
success(function(data,status,headers,config){ |
|
|
|
console.log(data); |
|
|
|
// DEBUG:
|
|
|
|
|
|
|
|
// console.log(data);
|
|
|
|
myself.stocks = data; |
|
|
|
myself.stocks = data; |
|
|
|
stocks = Object.keys(data); |
|
|
|
stocks = Object.keys(data); |
|
|
|
for (var i = 0; i < stocks.length; i++) { |
|
|
|
for (var stock of stocks) { |
|
|
|
loadLifepathsForStock(stocks[i]); |
|
|
|
myself.startingStatPts[stock] = new StartingStatPoints(myself.stocks[stock].starting_stats); |
|
|
|
loadStartingStatPtsForStock(stocks[i]); |
|
|
|
myself.defineStockEvent(stock, "lifepathsLoaded"); |
|
|
|
loadResourcesForStock(stocks[i]); |
|
|
|
myself.defineStockEvent(stock, "resourcesLoaded"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Log events
|
|
|
|
|
|
|
|
myself.registerStockEvent(stock, "lifepathsLoaded", function () { |
|
|
|
|
|
|
|
// console.log("Loaded " + Object.keys(myself.lifepaths[stock]).length + " lifepaths for " + stock + ".");
|
|
|
|
|
|
|
|
// DEBUG:
|
|
|
|
|
|
|
|
console.log("Loaded " + stock, myself.lifepaths[stock]); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
myself.registerStockEvent(stock, "resourcesLoaded", function () { |
|
|
|
|
|
|
|
// console.log("Loaded " + Object.keys(myself.resources[stock]).length + " resources for " + stock + ".");
|
|
|
|
|
|
|
|
// DEBUG:
|
|
|
|
|
|
|
|
console.log("Loaded " + stock, myself.resources[stock]); |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
console.log("Stocks fetched from server: " + stocks) |
|
|
|
myself.triggerEvent("stocksLoaded"); |
|
|
|
myself.onAllDatasetsLoaded() |
|
|
|
|
|
|
|
}). |
|
|
|
}). |
|
|
|
error(function(data,status,headers,config){ |
|
|
|
error(function(data,status,headers,config){ |
|
|
|
console.log("Error: Getting stocks from server failed: HTTP code " + status + ": " + data); |
|
|
|
console.log("Error: Getting stocks from server failed: HTTP code " + status + ": " + data); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
/* Load lifepaths from server */ |
|
|
|
/* Load lifepaths from server */ |
|
|
|
var loadLifepathsForStock = function(stock){ |
|
|
|
this.loadLifepathsForStock = function(stock){ |
|
|
|
if( ! isValidStock(stock) ){ |
|
|
|
if( ! isValidStock(stock) ){ |
|
|
|
console.log("Loading lifepaths failed: asked to load lifepaths for invalid stock " + stock); |
|
|
|
console.log("Loading lifepaths failed: asked to load lifepaths for invalid stock " + stock); |
|
|
|
return |
|
|
|
return |
|
|
@ -319,26 +359,16 @@ function BurningDataService($http) { |
|
|
|
$http.get("/lifepaths/" + stock, {'timeout': 3000} ). |
|
|
|
$http.get("/lifepaths/" + stock, {'timeout': 3000} ). |
|
|
|
success(function(data,status,headers,config){ |
|
|
|
success(function(data,status,headers,config){ |
|
|
|
myself.lifepaths[stock] = data; |
|
|
|
myself.lifepaths[stock] = data; |
|
|
|
// myself.datasetLoaded();
|
|
|
|
myself.triggerStockEvent(stock, "lifepathsLoaded"); |
|
|
|
console.log("Loaded "+stock+" lifepaths. " + Object.keys(myself.lifepaths).length + " settings"); |
|
|
|
console.log("Loaded "+stock+" lifepaths. " + Object.keys(myself.lifepaths[stock]).length + " settings"); |
|
|
|
}). |
|
|
|
}). |
|
|
|
error(function(data,status,headers,config){ |
|
|
|
error(function(data,status,headers,config){ |
|
|
|
// myself.datasetLoaded();
|
|
|
|
|
|
|
|
console.log("Error: Getting "+stock+" lifepaths from server failed: HTTP code " + status + ": " + data); |
|
|
|
console.log("Error: Getting "+stock+" lifepaths from server failed: HTTP code " + status + ": " + data); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Load starting stat points table from server */ |
|
|
|
|
|
|
|
var loadStartingStatPtsForStock = function(stock){ |
|
|
|
|
|
|
|
if( ! isValidStock(stock) ){ |
|
|
|
|
|
|
|
console.log("Loading starting stat points failed: asked to load pts for invalid stock " + stock); |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
myself.startingStatPts[stock] = new StartingStatPoints(myself.stocks[stock].starting_stats); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Load resources from server */ |
|
|
|
/* Load resources from server */ |
|
|
|
var loadResourcesForStock = function(stock){ |
|
|
|
this.loadResourcesForStock = function(stock){ |
|
|
|
if( ! isValidStock(stock) ){ |
|
|
|
if( ! isValidStock(stock) ){ |
|
|
|
console.log("Loading resources failed: asked to load for invalid stock " + stock); |
|
|
|
console.log("Loading resources failed: asked to load for invalid stock " + stock); |
|
|
|
return |
|
|
|
return |
|
|
@ -347,11 +377,10 @@ function BurningDataService($http) { |
|
|
|
$http.get("/resources/" + stock, {'timeout': 3000} ). |
|
|
|
$http.get("/resources/" + stock, {'timeout': 3000} ). |
|
|
|
success(function(data,status,headers,config){ |
|
|
|
success(function(data,status,headers,config){ |
|
|
|
myself.resources[stock] = data; |
|
|
|
myself.resources[stock] = data; |
|
|
|
// myself.datasetLoaded();
|
|
|
|
myself.triggerStockEvent(stock, "resourcesLoaded"); |
|
|
|
console.log("Loaded "+stock+" resources. "); |
|
|
|
console.log("Loaded "+stock+" resources. "); |
|
|
|
}). |
|
|
|
}). |
|
|
|
error(function(data,status,headers,config){ |
|
|
|
error(function(data,status,headers,config){ |
|
|
|
// myself.datasetLoaded();
|
|
|
|
|
|
|
|
console.log("Error: Getting "+stock+" stat points from server failed: HTTP code " + status + ": " + data); |
|
|
|
console.log("Error: Getting "+stock+" stat points from server failed: HTTP code " + status + ": " + data); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -361,11 +390,9 @@ function BurningDataService($http) { |
|
|
|
$http.get("/skills", {'timeout': 3000} ). |
|
|
|
$http.get("/skills", {'timeout': 3000} ). |
|
|
|
success(function(data,status,headers,config){ |
|
|
|
success(function(data,status,headers,config){ |
|
|
|
myself.skills = data; |
|
|
|
myself.skills = data; |
|
|
|
// myself.datasetLoaded();
|
|
|
|
myself.triggerEvent("skillsLoaded"); |
|
|
|
console.log("Loaded skills. "); |
|
|
|
|
|
|
|
}). |
|
|
|
}). |
|
|
|
error(function(data,status,headers,config){ |
|
|
|
error(function(data,status,headers,config){ |
|
|
|
// myself.datasetLoaded();
|
|
|
|
|
|
|
|
console.log("Error: Getting skills from server failed: HTTP code " + status + ": " + data); |
|
|
|
console.log("Error: Getting skills from server failed: HTTP code " + status + ": " + data); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -373,13 +400,22 @@ function BurningDataService($http) { |
|
|
|
$http.get("/traits", {'timeout': 3000} ). |
|
|
|
$http.get("/traits", {'timeout': 3000} ). |
|
|
|
success(function(data,status,headers,config){ |
|
|
|
success(function(data,status,headers,config){ |
|
|
|
myself.traits = data; |
|
|
|
myself.traits = data; |
|
|
|
// myself.datasetLoaded();
|
|
|
|
myself.triggerEvent("traitsLoaded"); |
|
|
|
console.log("Loaded traits. "); |
|
|
|
|
|
|
|
}). |
|
|
|
}). |
|
|
|
error(function(data,status,headers,config){ |
|
|
|
error(function(data,status,headers,config){ |
|
|
|
// myself.datasetLoaded();
|
|
|
|
|
|
|
|
console.log("Error: Getting traits from server failed: HTTP code " + status + ": " + data); |
|
|
|
console.log("Error: Getting traits from server failed: HTTP code " + status + ": " + data); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
// DEBUG:
|
|
|
|
|
|
|
|
// setTimeout(() => testStockLoading(myself), (2 * 1000));
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function testStockLoading(dataService) { |
|
|
|
|
|
|
|
console.log(dataService); |
|
|
|
|
|
|
|
for (var stock in dataService.stocks) { |
|
|
|
|
|
|
|
console.log(stock); |
|
|
|
|
|
|
|
dataService.loadLifepathsForStock(stock); |
|
|
|
|
|
|
|
dataService.loadResourcesForStock(stock); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
/**** End BurningDataService ****/ |
|
|
|
/**** End BurningDataService ****/ |
|
|
|
|
|
|
|
|
|
|
|