|
|
|
@ -263,54 +263,94 @@ function BurningDataService($http) { |
|
|
|
|
// A hash of StartingStatPoints objects keyed by stock.
|
|
|
|
|
this.startingStatPts = {}; |
|
|
|
|
|
|
|
|
|
// this.dataSetsLoaded = 0;
|
|
|
|
|
// // Total data sets:
|
|
|
|
|
// // lifepaths: 7 (man, dwarf, elf, orc, roden, wolf, troll)
|
|
|
|
|
// // stat points: 7 (man, dwarf, elf, orc, roden, wolf, troll)
|
|
|
|
|
// // skills
|
|
|
|
|
// // traits
|
|
|
|
|
// // resources: 7 (man, dwarf, elf, orc, roden, wolf. troll)
|
|
|
|
|
// // TOTAL: 23
|
|
|
|
|
// this.totalDataSets = 23;
|
|
|
|
|
// this.onAllDatasetsLoaded = null;
|
|
|
|
|
this.registerOnAllDatasetsLoaded = function(callback){ |
|
|
|
|
if ( this.dataSetsLoaded >= this.totalDataSets ){ |
|
|
|
|
this.events = { |
|
|
|
|
stocksLoaded: { triggered : false, callbacks : [] }, |
|
|
|
|
traitsLoaded: { triggered : false, callbacks : [] }, |
|
|
|
|
skillsLoaded: { triggered : false, callbacks : [] }, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.registerEvent = function(eventName, callback){ |
|
|
|
|
if(this.events[eventName].triggered) |
|
|
|
|
callback(); |
|
|
|
|
this.events[eventName].callbacks.push(callback); |
|
|
|
|
} |
|
|
|
|
this.triggerEvent = function(eventName) { |
|
|
|
|
myself.events[eventName].triggered = true; |
|
|
|
|
for(var callback of myself.events[eventName].callbacks) { |
|
|
|
|
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");
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
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(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var myself = this; |
|
|
|
|
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}). |
|
|
|
|
success(function(data,status,headers,config){ |
|
|
|
|
console.log(data); |
|
|
|
|
// DEBUG:
|
|
|
|
|
// console.log(data);
|
|
|
|
|
myself.stocks = data; |
|
|
|
|
stocks = Object.keys(data); |
|
|
|
|
for (var i = 0; i < stocks.length; i++) { |
|
|
|
|
loadLifepathsForStock(stocks[i]); |
|
|
|
|
loadStartingStatPtsForStock(stocks[i]); |
|
|
|
|
loadResourcesForStock(stocks[i]); |
|
|
|
|
for (var stock of stocks) { |
|
|
|
|
myself.startingStatPts[stock] = new StartingStatPoints(myself.stocks[stock].starting_stats); |
|
|
|
|
myself.defineStockEvent(stock, "lifepathsLoaded"); |
|
|
|
|
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.onAllDatasetsLoaded() |
|
|
|
|
myself.triggerEvent("stocksLoaded"); |
|
|
|
|
}). |
|
|
|
|
error(function(data,status,headers,config){ |
|
|
|
|
console.log("Error: Getting stocks from server failed: HTTP code " + status + ": " + data); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
/* Load lifepaths from server */ |
|
|
|
|
var loadLifepathsForStock = function(stock){ |
|
|
|
|
this.loadLifepathsForStock = function(stock){ |
|
|
|
|
if( ! isValidStock(stock) ){ |
|
|
|
|
console.log("Loading lifepaths failed: asked to load lifepaths for invalid stock " + stock); |
|
|
|
|
return |
|
|
|
@ -319,26 +359,16 @@ function BurningDataService($http) { |
|
|
|
|
$http.get("/lifepaths/" + stock, {'timeout': 3000} ). |
|
|
|
|
success(function(data,status,headers,config){ |
|
|
|
|
myself.lifepaths[stock] = data; |
|
|
|
|
// myself.datasetLoaded();
|
|
|
|
|
console.log("Loaded "+stock+" lifepaths. " + Object.keys(myself.lifepaths).length + " settings"); |
|
|
|
|
myself.triggerStockEvent(stock, "lifepathsLoaded"); |
|
|
|
|
console.log("Loaded "+stock+" lifepaths. " + Object.keys(myself.lifepaths[stock]).length + " settings"); |
|
|
|
|
}). |
|
|
|
|
error(function(data,status,headers,config){ |
|
|
|
|
// myself.datasetLoaded();
|
|
|
|
|
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 */ |
|
|
|
|
var loadResourcesForStock = function(stock){ |
|
|
|
|
this.loadResourcesForStock = function(stock){ |
|
|
|
|
if( ! isValidStock(stock) ){ |
|
|
|
|
console.log("Loading resources failed: asked to load for invalid stock " + stock); |
|
|
|
|
return |
|
|
|
@ -347,11 +377,10 @@ function BurningDataService($http) { |
|
|
|
|
$http.get("/resources/" + stock, {'timeout': 3000} ). |
|
|
|
|
success(function(data,status,headers,config){ |
|
|
|
|
myself.resources[stock] = data; |
|
|
|
|
// myself.datasetLoaded();
|
|
|
|
|
myself.triggerStockEvent(stock, "resourcesLoaded"); |
|
|
|
|
console.log("Loaded "+stock+" resources. "); |
|
|
|
|
}). |
|
|
|
|
error(function(data,status,headers,config){ |
|
|
|
|
// myself.datasetLoaded();
|
|
|
|
|
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} ). |
|
|
|
|
success(function(data,status,headers,config){ |
|
|
|
|
myself.skills = data; |
|
|
|
|
// myself.datasetLoaded();
|
|
|
|
|
console.log("Loaded skills. "); |
|
|
|
|
myself.triggerEvent("skillsLoaded"); |
|
|
|
|
}). |
|
|
|
|
error(function(data,status,headers,config){ |
|
|
|
|
// myself.datasetLoaded();
|
|
|
|
|
console.log("Error: Getting skills from server failed: HTTP code " + status + ": " + data); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -373,13 +400,22 @@ function BurningDataService($http) { |
|
|
|
|
$http.get("/traits", {'timeout': 3000} ). |
|
|
|
|
success(function(data,status,headers,config){ |
|
|
|
|
myself.traits = data; |
|
|
|
|
// myself.datasetLoaded();
|
|
|
|
|
console.log("Loaded traits. "); |
|
|
|
|
myself.triggerEvent("traitsLoaded"); |
|
|
|
|
}). |
|
|
|
|
error(function(data,status,headers,config){ |
|
|
|
|
// myself.datasetLoaded();
|
|
|
|
|
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 ****/ |
|
|
|
|
|
|
|
|
|