loyalty ranges are mostly working

This commit is contained in:
Ryan Carpenter
2016-09-18 12:42:55 +08:00
parent cfb541a0a2
commit 9f82f96b3c
9 changed files with 2102 additions and 71 deletions
+30 -9
View File
@@ -14,7 +14,7 @@ angular.module('quartermaester')
characterPaths: true,
houseHeraldry: false,
geographicRegions: false,
politicalAllegiances: true,
politicalAllegiances: false,
characters: {}
};
$scope.map = {
@@ -36,7 +36,8 @@ angular.module('quartermaester')
smgMapType: smgMapType,
locationClick: locationClick,
heraldryClick: heraldryClick,
characterClick: characterClick
characterClick: characterClick,
loyaltyRangeClick: loyaltyRangeClick
};
$scope.mapModels = {
towns: [],
@@ -44,7 +45,8 @@ angular.module('quartermaester')
characters: [],
paths: [],
regions: [],
loyalties: []
politicalAllegiances: [],
editableLoyaltyRanges: []
};
$scope.episodes = [];
$scope.chapters = [];
@@ -68,6 +70,12 @@ angular.module('quartermaester')
function addToScope(d) {
qmData = d;
for (var i=0;i<qmData.loyaltyRanges.length; i++) {
qmData.loyaltyRanges[i].events = {
click: loyaltyRangeClick
};
}
// Add data from CSV files into $scope
$scope.episodes = qmData.episodes;
$scope.chapters = qmData.chapters;
@@ -91,6 +99,7 @@ angular.module('quartermaester')
$scope.mapModels.towns = $filter('qmSlider')(qmData.towns, $scope.slider);
$scope.mapModels.heraldry = $scope.options.houseHeraldry ? $filter('qmSlider')(qmData.heraldry, $scope.slider) : [];
$scope.mapModels.characters = $filter('qmSlider')(qmData.characterMarkers, $scope.slider, $scope.options);
$scope.belligerents = $filter('qmSlider')(qmData.belligerents, $scope.slider);
var staticPaths = $filter('qmSlider')(qmData.characterPaths, $scope.slider, $scope.options);
$scope.mapModels.paths = angular.copy(staticPaths);
$scope.mapModels.editablePaths = angular.copy(staticPaths).map(function(path) {
@@ -100,8 +109,11 @@ angular.module('quartermaester')
});
$scope.mapModels.loyaltyRanges = $filter('qmSlider')(qmData.loyaltyRanges, $scope.slider);
console.log("mapModels.loyaltyRanges", $scope.mapModels.loyaltyRanges);
//console.log("mapModels.regions", $scope.mapModels.regions);
$scope.mapModels.editableLoyaltyRanges = angular.copy($scope.mapModels.loyaltyRanges).map(function(polygon) {
polygon.static = false;
polygon.editable = true;
return polygon;
});
}
function panToCharacter(newValue, oldValue) {
@@ -189,8 +201,6 @@ angular.module('quartermaester')
}
function panTo(input) {
console.log("panTo", input);
var location = $filter('filter')($scope.map.locations, {key: input})[0];
$scope.map.control.getGMap().panTo({lat: location.coords.latitude, lng: location.coords.longitude});
$scope.locationDetail = location;
@@ -281,6 +291,19 @@ angular.module('quartermaester')
$scope.state = "location";
}
function loyaltyRangeClick(e, eventName, model) {
var keyMatch = /(.+)\-\d+\w?$/.exec(model.key);
var matchingBelligerant = $filter('filter')(qmData.belligerents, {key: keyMatch[1]})[0];
var filtered = $filter('filter')(qmData.belligerents, {key: keyMatch[1]});
$scope.locationDetail = {
house: matchingBelligerant.title + " " + matchingBelligerant.name,
houseImg: matchingBelligerant.houseImg,
houseUrl: matchingBelligerant.url
};
$scope.state = "location";
}
function mapClick(a, b, c, d) {
$scope.state = "slider";
//console.log(a, b, c, d);
@@ -295,8 +318,6 @@ angular.module('quartermaester')
latitude: latitude,
longitude: longitude
});
//console.log("history", $scope.clickHistory);
//$scope.$apply();
}
function onMapLoad(maps) {
+32 -17
View File
@@ -75,11 +75,12 @@ angular.module('quartermaester')
getFile('loyaltyRangeEdges.csv'),
getFile('stops.csv'),
getFile('waypoints.csv'),
getFile('paths.csv')
getFile('paths.csv'),
getFile('belligerents.csv')
]).spread(parseData);
}
function parseData(books, chapters, seasons, episodes, houses, characters, regions, loyaltyRanges, towns, borders, loyaltyRangeEdges, stops, waypoints, paths) {
function parseData(books, chapters, seasons, episodes, houses, characters, regions, loyaltyRanges, towns, borders, loyaltyRangeEdges, stops, waypoints, paths, belligerents) {
var qmData = {
borderArrays: {},
lrEdgeArrays: {},
@@ -98,12 +99,7 @@ angular.module('quartermaester')
if (!(loyaltyRangeEdges[i].key in qmData.lrEdgeArrays))
qmData.lrEdgeArrays[loyaltyRangeEdges[i].key] = [];
qmData.lrEdgeArrays[loyaltyRangeEdges[i].key].push(loyaltyRangeEdges[i]);
// qmData.lrEdgeArrays[loyaltyRangeEdges[i].key].push({
// latitude: parseFloat(loyaltyRangeEdges[i].latitude),
// longitude: parseFloat(loyaltyRangeEdges[i].longitude)
// });
}
//console.log("qmData.lrEdgeArrays", qmData.lrEdgeArrays);
for (var i=0; i<waypoints.length; i++) {
if (!(waypoints[i].key in qmData.waypointArrays))
@@ -120,13 +116,13 @@ angular.module('quartermaester')
qmData.books = books;
qmData.regions = regions.map(regionModel);
qmData.characters = characters.map(characterModel);
qmData.belligerents = belligerents.map(belligerentModel);
qmData.loyaltyRanges = loyaltyRanges.map(loyaltyRangeModel);
qmData.towns = getTownMarkers(towns, houses);
qmData.heraldry = houses.map(heraldryMarkerModel);
qmData.characterMarkers = stops.map(characterMarkerModel);
qmData.characterPaths = paths.map(characterPathModel);
qmData.searchResults = [].concat(
towns.map(townSearchModel),
characters.map(characterSearchModel),
@@ -337,15 +333,12 @@ angular.module('quartermaester')
}
function loyaltyRangeModel(loyaltyRange) {
var matchingCharacter = {color: "#eeeeee"};
console.log(loyaltyRange);
var keyMatch = /(.+)\-\d+$/.exec(loyaltyRange.key);
if (keyMatch[1]!="Undeclared") matchingCharacter = $filter('filter')(qmData.characters, {key: keyMatch[1]})[0];
var keyMatch = /(.+)\-\d+\w?$/.exec(loyaltyRange.key);
var matchingBelligerant = $filter('filter')(qmData.belligerents, {key: keyMatch[1]})[0];
return {
key: loyaltyRange.key,
fill: {
color: matchingCharacter.color,
color: matchingBelligerant.color,
opacity: 0.5
},
stroke: {weight: 0},
@@ -353,7 +346,8 @@ angular.module('quartermaester')
timing: {
episodes: [getEpisodeId(loyaltyRange.firstEpisode), getEpisodeId(loyaltyRange.lastEpisode)],
chapters: [getChapterId(loyaltyRange.firstChapter), getChapterId(loyaltyRange.lastChapter)]
}
},
clickable: true
};
}
@@ -452,12 +446,35 @@ angular.module('quartermaester')
};
}
function belligerentModel(belligerent) {
var matchingHouse = $filter('filter')(houses, {wikiKey: belligerent.house})[0];
return {
key: belligerent.key,
title: belligerent.title,
name: belligerent.name,
url: "http://awoiaf.westeros.org/index.php/" + belligerent.key,
houseImg: matchingHouse.img,
houseUrl: "http://awoiaf.westeros.org/index.php/" + belligerent.house,
color: belligerent.color,
timing: {
episodes: [
getEpisodeId(belligerent.firstEpisode),
getEpisodeId(belligerent.lastEpisode)
],
chapters: [
getChapterId(belligerent.firstChapter),
getChapterId(belligerent.lastChapter)
]
}
};
}
function getChapterId(chapterKey) {
//AGOT-2 to 2
if (chapterKey=="") return -1;
if (chapterKey=="TWOW-?") return 344;
if (chapterKey=="TWOW-???") return 344;
var reMatch = /(\w{4})\-(\d+)/.exec(chapterKey);
var precedingChapters = parseInt(qmData.bookLookup[ reMatch[1] ].precedingChapters, 10)
return precedingChapters + parseInt(reMatch[2], 10);
@@ -525,10 +542,8 @@ angular.module('quartermaester')
return {
restrict: 'A',
link: function (scope, elem, attrs) {
// console.log(elem, attrs);
var winHeight = $window.innerHeight;
// var listHeight = attrs.qmList ? 41*parseInt(attrs.qmList, 10) : 0;
// console.log(winHeight, attrs.qmList, listHeight);
// if (listHeight>winHeight) elem.css('height', winHeight - 48 + 'px');
elem.css('height', winHeight - 55 + 'px');
}