|
|
@ -1,4 +1,4 @@ |
|
|
|
|
|
|
|
var DEBUG = false; |
|
|
|
/**** Class Settings (Angular Service) ****/ |
|
|
|
/**** Class Settings (Angular Service) ****/ |
|
|
|
function Settings() { |
|
|
|
function Settings() { |
|
|
|
this.enforceLifepathReqts = true; |
|
|
|
this.enforceLifepathReqts = true; |
|
|
@ -218,13 +218,14 @@ function CharacterStorageService($http) { |
|
|
|
|
|
|
|
|
|
|
|
/* Load character names from server */ |
|
|
|
/* Load character names from server */ |
|
|
|
this.loadCharacterNames = function(){ |
|
|
|
this.loadCharacterNames = function(){ |
|
|
|
$http.get("/list_chars/user1", {'timeout': 3000} ). |
|
|
|
fetch("/list_chars/user1") |
|
|
|
success(function(data,status,headers,config){ |
|
|
|
.then((response) => response.json()) |
|
|
|
|
|
|
|
.then((data) => { |
|
|
|
myself.characterIdAndNames = data; |
|
|
|
myself.characterIdAndNames = data; |
|
|
|
console.log("Loaded saved character names"); |
|
|
|
console.log("Loaded saved character names"); |
|
|
|
}). |
|
|
|
}) |
|
|
|
error(function(data,status,headers,config){ |
|
|
|
.catch((error) => { |
|
|
|
console.log("Error: Loading saved character names from server failed: HTTP code " + status + ": " + data); |
|
|
|
console.log("Error: Loading saved character names from server failed: "+error); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -236,6 +237,10 @@ function CharacterStorageService($http) { |
|
|
|
/**** Class BurningDataService (Angular Service) ****/ |
|
|
|
/**** Class BurningDataService (Angular Service) ****/ |
|
|
|
// This service is used to load the lifepaths, skills, traits, etc. from the server.
|
|
|
|
// This service is used to load the lifepaths, skills, traits, etc. from the server.
|
|
|
|
function BurningDataService($http) { |
|
|
|
function BurningDataService($http) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Used to reference the object from within functions and callbacks
|
|
|
|
|
|
|
|
var myself = this; |
|
|
|
|
|
|
|
|
|
|
|
/* JSON Data structure representing lifepaths. The structure is: |
|
|
|
/* JSON Data structure representing lifepaths. The structure is: |
|
|
|
stock: |
|
|
|
stock: |
|
|
|
setting_name: |
|
|
|
setting_name: |
|
|
@ -263,135 +268,78 @@ function BurningDataService($http) { |
|
|
|
// A hash of StartingStatPoints objects keyed by stock.
|
|
|
|
// A hash of StartingStatPoints objects keyed by stock.
|
|
|
|
this.startingStatPts = {}; |
|
|
|
this.startingStatPts = {}; |
|
|
|
|
|
|
|
|
|
|
|
this.events = { |
|
|
|
/* Loading of stocks, skills, and traits begins on initializing the service |
|
|
|
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.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(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Load stocks from server */ |
|
|
|
|
|
|
|
this.whenStocksLoaded = fetch("/stocks") |
|
|
|
var myself = this; |
|
|
|
.then((response) => response.json()) |
|
|
|
|
|
|
|
.then((data) => { |
|
|
|
// Log events
|
|
|
|
if(DEBUG) |
|
|
|
this.registerEvent("stocksLoaded", function() { |
|
|
|
console.log("Loaded stock data: "+data); |
|
|
|
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){ |
|
|
|
|
|
|
|
// DEBUG:
|
|
|
|
|
|
|
|
// console.log(data);
|
|
|
|
|
|
|
|
myself.stocks = data; |
|
|
|
myself.stocks = data; |
|
|
|
for (var stock of Object.keys(data)) { |
|
|
|
for (var stock of Object.keys(data)) { |
|
|
|
myself.startingStatPts[stock] = new StartingStatPoints(myself.stocks[stock].starting_stats); |
|
|
|
myself.startingStatPts[stock] = new StartingStatPoints(myself.stocks[stock].starting_stats); |
|
|
|
myself.defineStockEvent(stock, "lifepathsLoaded"); |
|
|
|
|
|
|
|
myself.defineStockEvent(stock, "resourcesLoaded"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
myself.triggerEvent("stocksLoaded"); |
|
|
|
}) |
|
|
|
}). |
|
|
|
.catch((error) => { |
|
|
|
error(function(data,status,headers,config){ |
|
|
|
console.log("Error: Getting stocks from server failed: "+error); |
|
|
|
console.log("Error: Getting stocks from server failed: HTTP code " + status + ": " + data); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Load skills from server */ |
|
|
|
|
|
|
|
this.whenSkillsLoaded = fetch("/skills") |
|
|
|
|
|
|
|
.then((response) => response.json()) |
|
|
|
|
|
|
|
.then((data) => { |
|
|
|
|
|
|
|
myself.skills = data; |
|
|
|
|
|
|
|
if(DEBUG) |
|
|
|
|
|
|
|
console.log("Loaded skill data: "+data); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.catch((error) => { |
|
|
|
|
|
|
|
console.log("Error: Getting skills from server failed: "+error); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Load traits from server */ |
|
|
|
|
|
|
|
this.whenTraitsLoaded = fetch("/traits") |
|
|
|
|
|
|
|
.then((response) => response.json()) |
|
|
|
|
|
|
|
.then((data) => { |
|
|
|
|
|
|
|
myself.traits = data; |
|
|
|
|
|
|
|
if(DEBUG) |
|
|
|
|
|
|
|
console.log("Loaded trait data: "+data); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.catch((error) => { |
|
|
|
|
|
|
|
console.log("Error: Getting traits from server failed: "+error); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Lifepaths and resources defer until their stock is selected */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.whenLifePathsLoadedForStock = {}; |
|
|
|
/* Load lifepaths from server */ |
|
|
|
/* Load lifepaths from server */ |
|
|
|
this.loadLifepathsForStock = function(stock){ |
|
|
|
this.loadLifepathsForStock = function(stock){ |
|
|
|
$http.get("/lifepaths/" + stock, {'timeout': 3000} ). |
|
|
|
return myself.whenLifePathsLoadedForStock[stock] = fetch("/lifepaths/" + stock) |
|
|
|
success(function(data,status,headers,config){ |
|
|
|
.then((response) => response.json()) |
|
|
|
|
|
|
|
.then((data) => { |
|
|
|
myself.lifepaths[stock] = data; |
|
|
|
myself.lifepaths[stock] = data; |
|
|
|
myself.triggerStockEvent(stock, "lifepathsLoaded"); |
|
|
|
if(DEBUG) |
|
|
|
console.log("Loaded "+stock+" lifepaths. " + Object.keys(myself.lifepaths[stock]).length + " settings"); |
|
|
|
console.log("Loaded "+stock+" lifepaths. " + Object.keys(myself.lifepaths[stock]).length + " settings"); |
|
|
|
}). |
|
|
|
}) |
|
|
|
error(function(data,status,headers,config){ |
|
|
|
.catch((error) => { |
|
|
|
console.log("Error: Getting "+stock+" lifepaths from server failed: HTTP code " + status + ": " + data); |
|
|
|
console.log("Error: Getting "+stock+" lifepaths from server failed: "+error); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/* Load resources from server */ |
|
|
|
/* Load resources from server */ |
|
|
|
|
|
|
|
this.whenResourcesLoadedForStock = {}; |
|
|
|
this.loadResourcesForStock = function(stock){ |
|
|
|
this.loadResourcesForStock = function(stock){ |
|
|
|
$http.get("/resources/" + stock, {'timeout': 3000} ). |
|
|
|
return myself.whenResourcesLoadedForStock[stock] = fetch("/resources/" + stock) |
|
|
|
success(function(data,status,headers,config){ |
|
|
|
.then((response) => response.json()) |
|
|
|
|
|
|
|
.then((data) => { |
|
|
|
myself.resources[stock] = data; |
|
|
|
myself.resources[stock] = data; |
|
|
|
myself.triggerStockEvent(stock, "resourcesLoaded"); |
|
|
|
if(DEBUG) |
|
|
|
console.log("Loaded "+stock+" resources. "); |
|
|
|
console.log("Loaded "+stock+" resources. "); |
|
|
|
}). |
|
|
|
}) |
|
|
|
error(function(data,status,headers,config){ |
|
|
|
.catch((error) => { |
|
|
|
console.log("Error: Getting "+stock+" stat points from server failed: HTTP code " + status + ": " + data); |
|
|
|
console.log("Error: Getting "+stock+" stat points from server failed: "+error); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Load skills from server */ |
|
|
|
|
|
|
|
$http.get("/skills", {'timeout': 3000} ). |
|
|
|
|
|
|
|
success(function(data,status,headers,config){ |
|
|
|
|
|
|
|
myself.skills = data; |
|
|
|
|
|
|
|
myself.triggerEvent("skillsLoaded"); |
|
|
|
|
|
|
|
}). |
|
|
|
|
|
|
|
error(function(data,status,headers,config){ |
|
|
|
|
|
|
|
console.log("Error: Getting skills from server failed: HTTP code " + status + ": " + data); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Load traits from server */ |
|
|
|
|
|
|
|
$http.get("/traits", {'timeout': 3000} ). |
|
|
|
|
|
|
|
success(function(data,status,headers,config){ |
|
|
|
|
|
|
|
myself.traits = data; |
|
|
|
|
|
|
|
myself.triggerEvent("traitsLoaded"); |
|
|
|
|
|
|
|
}). |
|
|
|
|
|
|
|
error(function(data,status,headers,config){ |
|
|
|
|
|
|
|
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 ****/ |
|
|
|
|
|
|
|
|
|
|
|