Skip to content

Commit

Permalink
Merge branch 'release/0.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Valandur committed Sep 16, 2015
2 parents c7e9847 + 768bc80 commit c3e9c7f
Show file tree
Hide file tree
Showing 6 changed files with 287 additions and 148 deletions.
46 changes: 23 additions & 23 deletions src/app/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ var app = angular.module('app.controllers', []);

app.controller('MainController', ['$scope', '$rootScope', '$mdDialog',
function($scope, $rootScope, $mdDialog) {

var ipc = require('ipc');

$scope.hasReplay = false;

$scope.loading = true;
$scope.msg = "Loading...";
$scope.replay = null;
$scope.leagueClientFound = false;
$scope.leagueClientVersion = "";
$scope.staticDataReady = false;
$scope.lolClientFound = false;
$scope.lolClientVersion = "";
$scope.aofClientInfo = {};

$scope.settings = [ { id: 1, name: "Select LoL Client" }, { id: 2, name: "Client info" } ];

$scope.showAofClientInfo = function(ev) {
var updateText = "";
if ($scope.aofClientInfo.newVersion) {
Expand All @@ -31,7 +31,7 @@ app.controller('MainController', ['$scope', '$rootScope', '$mdDialog',
.targetEvent(ev)
);
};

$scope.announceClick = function(index) {
if (index == 0) {
$scope.selectClient();
Expand All @@ -54,32 +54,32 @@ app.controller('MainController', ['$scope', '$rootScope', '$mdDialog',
ipc.send("play");
};

ipc.on("clientInfo", function(obj) {
ipc.on("loading", function(obj) {
$scope.$apply(function() {
$scope.leagueClientFound = obj.found;
$scope.leagueClientVersion = obj.version;
$scope.loading = obj.loading
$scope.msg = obj.msg;
});
});

ipc.on("parsedReplayFile", function(arg) {
ipc.on("aofUpdate", function(obj) {
$scope.$apply(function() {
$scope.replay = arg;
$scope.hasReplay = true;
$scope.aofClientInfo = obj;
});
});

ipc.on("staticData", function(arg) {
ipc.on("clientInfo", function(obj) {
$scope.$apply(function() {
$scope.staticDataReady = arg;
$scope.lolClientFound = obj.found;
$scope.lolClientVersion = obj.version;
});
});

ipc.on("update", function(arg) {
ipc.on("parsedReplayFile", function(obj) {
$scope.$apply(function() {
$scope.aofClientInfo = arg;
$scope.replay = obj;
});
});

ipc.send("ready");
}
]);
2 changes: 1 addition & 1 deletion src/app/tpl/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<span id="md-toolbar-title">AnalyzeOrFeed Replay Client</span>
<span flex></span>
<span ng-show="aofClientInfo.newVersion" ng-click="showAofClientInfo($event)">Update available!</span>
<md-menu>
<md-menu ng-hide="loading">
<md-button aria-label="Open demo menu" class="md-icon-button" ng-click="$mdOpenMenu($event)">
<md-icon>settings</md-icon>
</md-button>
Expand Down
28 changes: 14 additions & 14 deletions src/app/tpl/main.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<div layout="column" flex="100">
<div ng-hide="staticDataReady" layout="row" layout-sm="column" layout-align="space-around" style="margin-top:200px;">
<md-tooltip md-direction="top">
Loading static data from server...
</md-tooltip>
<div ng-show="loading" layout="row" layout-sm="column" layout-align="space-around" style="margin-top: 150px;">
<md-progress-circular md-mode="indeterminate"></md-progress-circular>
</div>
<md-content ng-show="staticDataReady" style="height: 493px" flex>
<div ng-show="loading" layout="row" layout-sm="column" layout-align="space-around">
{{ msg }}
</div>
<md-content ng-hide="loading" style="height: 493px" flex>
<md-button class="md-icon-button" style="float:right;">
<md-icon id="clientFound" ng-class="leagueClientFound ? 'client-found-true' : 'client-found-false'">{{leagueClientFound ? 'check_circle' : 'error'}}</md-icon>
<md-icon id="clientFound" ng-class="lolClientFound ? 'client-found-true' : 'client-found-false'">{{ lolClientFound ? 'check_circle' : 'error' }}</md-icon>
<md-tooltip md-direction="left">
{{leagueClientFound ? "LoL Client found: " : "No LoL Client found!"}} {{leagueClientVersion}}
{{ lolClientFound ? "LoL Client found: " : "No LoL Client found!" }} {{ lolClientVersion }}
</md-tooltip>
</md-button>
<md-button class="aof md-raised md-primary md-button md-default-theme" style="top: 3px;" ng-click="openFile()">Open file...</md-button>
<div class="content" ng-show="replay" style="padding: 10px;">
<div style="float:right;">v{{replay.riotVersion}}</div>
<div>Game ID: {{replay.gameId}} ({{replay.region}})
<div style="float:right;">v{{ replay.riotVersion }}</div>
<div>Game ID: {{ replay.gameId }} ({{ replay.region }})
<span ng-hide="replay.complete" style="color: red;">
INCOMPLETE
<md-tooltip md-direction="top">
Expand All @@ -32,7 +32,7 @@
<td width="15%">&nbsp;</td>
</thead>
<tr ng-repeat="player in replay.players | filter: { 'teamNr': 0 }">
<td>{{player.summonerName}}</td>
<td>{{ player.summonerName }}</td>
<td style="text-align: center;">
<img style="float: left; margin-right: 2px; margin-left: 2px;" ng-src="http://api.aof.gg/static/champion/{{player.champion.image}}" width="48" height="48" />
<div style="float: left;">
Expand All @@ -43,7 +43,7 @@
<td style="text-align: center;">
<img style="margin-top: 5px;" ng-src="http://api.aof.gg/static/league/{{player.league.image}}" width="48" height="48" />
<md-tooltip md-direction="right">
{{player.league.name}} {{player.leagueRank != 0 ? player.leagueRank : ""}}
{{ player.league.name }} {{ player.leagueRank != 0 ? player.leagueRank : "" }}
</md-tooltip>
</td>
</tr>
Expand All @@ -60,7 +60,7 @@
<td style="text-align: center;">
<img style="margin-top: 5px;" ng-src="http://api.aof.gg/static/league/{{player.league.image}}" width="48" height="48" />
<md-tooltip md-direction="left">
{{player.league.name}} {{player.leagueRank != 0 ? player.leagueRank : ""}}
{{ player.league.name }} {{ player.leagueRank != 0 ? player.leagueRank : "" }}
</md-tooltip>
</td>
<td style="text-align: center;">
Expand All @@ -69,12 +69,12 @@
<div class="spell1"><img ng-src="http://api.aof.gg/static/spell/{{player.d.image}}" width="23" height="23"></div>
<div class="spell2"><img ng-src="http://api.aof.gg/static/spell/{{player.f.image}}" width="23" height="23"></div>
</div>
<td style="text-align: right;">{{player.summonerName}}</td>
<td style="text-align: right;">{{ player.summonerName }}</td>
</tr>
</table>
</div>
</div>
</div>
<md-button class="aof md-raised md-primary md-button md-default-theme" style="bottom: 3px;" disabled="true" ng-disabled="!hasReplay || !leagueClientFound" ng-click="playReplay()">Play replay</md-button>
<md-button class="aof md-raised md-primary md-button md-default-theme" style="bottom: 3px;" disabled="true" ng-disabled="replay == null || !lolClientFound" ng-click="playReplay()">Play replay</md-button>
</md-content>
</div>
161 changes: 113 additions & 48 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ let lolClient = require(__dirname + "/modules/lol-client.js");

let replay = null;
let mainWindow = null;
let settings = {};
let staticData = {
checked: false,
extended: false,
regions: [
{"Id":5,"Name":"Brazil","ShortName":"BR"},
Expand All @@ -32,63 +32,96 @@ let staticData = {
]
};


// Log operating system
console.log("We are running on " + process.platform);


// Quit when all windows are closed.
app.on("window-all-closed", function() {
if (process.platform != "darwin") {
app.quit();
}
});

// Get static data from api
fs.readFile(app.getPath("userCache") + "/.static", function(err, data) {
if (!err) {
console.log("Reading static data from local cache");
staticData = JSON.parse(data);
staticData.extended = true;
}

console.log("Retrieving static data from server");
request({ url: "http://api.aof.gg/static", json: true }, function(err, response, body) {
if (!err && response && response.statusCode == 200 && !body.err && body.data) {
staticData = body.data;
staticData.extended = true;
fs.writeFileSync(app.getPath("userCache") + "/.static", JSON.stringify(staticData));
} else {
console.log("Error while retrieving static data: " + err + " " + JSON.stringify(response));
// User settings
function loadUserSettings(callback) {
console.log("Loading user settings");
fs.readFile(app.getPath("userCache") + "/settings", function(err, data) {
if (!err) {
settings = JSON.parse(data);
}

staticData.checked = true;
if (mainWindow)
mainWindow.webContents.send("staticData", true);
callback();
});
});
}
function saveUserSettings() {
console.log("Saving user settings");
settings.lolClientPath = lolClient.leaguePath();
fs.writeFileSync(app.getPath("userCache") + "/settings", JSON.stringify(settings, null, 2));
}


// Check for updates
console.log("Checking for updates");
let version = { currVersion: JSON.parse(fs.readFileSync(__dirname + "/package.json")).version, newVersion: null, msg: null };
request({ url: "http://api.aof.gg/version", json: true }, function(err, response, body) {
if (!err && response && response.statusCode == 200) {
if (version.currVersion != body.version) {
version.newVersion = body.version;
version.msg = body.msg;
function checkForUpdates(callback) {
console.log("Checking for application updates");
let version = { currVersion: JSON.parse(fs.readFileSync(__dirname + "/package.json")).version, newVersion: null, msg: null };
let timeout = setTimeout(function() {
req.abort();
console.log("Could not check for updates, request timed out");
callback();
}, 10000);
let req = request({ url: "http://api.aof.gg/version", json: true }, function(err, response, body) {
clearTimeout(timeout);
if (!err && response && response.statusCode == 200) {
// Set the new version info if there is one
if (version.currVersion != body.version) {
version.newVersion = body.version;
version.msg = body.msg;
}
mainWindow.webContents.send("aofUpdate", version);
} else {
console.log("Error while retrieving version: " + err + " " + JSON.stringify(response));
}
if (mainWindow)
mainWindow.webContents.send("update", version);
} else {
console.log("Error while retrieving version: " + err + " " + JSON.stringify(response));
}
});

callback();
});
}

// Start our replay server
replayServer.startServer();

// Try and find the league client
lolClient.find();
// Get static data from api
function getStaticData(callback) {
console.log("Loading static data");
fs.readFile(app.getPath("userCache") + "/static", function(err, data) {
if (!err) {
console.log("Reading static data from local cache");
staticData = JSON.parse(data);
staticData.extended = true;
}

console.log("Retrieving static data from server");
let timeout = setTimeout(function() {
req.abort();
console.log("Could not retreive static data, request timed out");
callback();
}, 10000)
let req = request({ url: "http://api.aof.gg/static", json: true }, function(err, response, body) {
if (!err && response && response.statusCode == 200 && !body.err && body.data) {
staticData = body.data;
staticData.extended = true;
fs.writeFileSync(app.getPath("userCache") + "/static", JSON.stringify(staticData));
} else {
console.log("Error while retrieving static data: " + err + " " + JSON.stringify(response));
}

callback();
});
});
}

let extendReplayMetadata = function(meta) {

// Extend the metadata of a replay with additional information
function extendReplayMetadata(meta) {
meta.region = _.find(staticData.regions, function(region) { return region.Id == meta.regionId }).ShortName;

if (staticData.extended) {
Expand All @@ -109,27 +142,55 @@ let extendReplayMetadata = function(meta) {
}
}
return meta;
};
}

// Listen for renderer messages

// Called when the renderer is ready to display things
ipc.on("ready", function(event, args) {
if (staticData.checked)
event.sender.send("staticData", true);
if (version)
event.sender.send("update", version);
event.sender.send("clientInfo", { found: lolClient.isFound(), version: lolClient.version() });

mainWindow.webContents.send("loading", { loading: true, msg: "Loading user settings..." });
loadUserSettings(function() {

mainWindow.webContents.send("loading", { loading: true, msg: "Checking for updates..." });
checkForUpdates(function() {

mainWindow.webContents.send("loading", { loading: true, msg: "Retreiving static data..." });
getStaticData(function() {

mainWindow.webContents.send("loading", { loading: true, msg: "Searching for league client..." });
lolClient.find(settings.lolClientPath, function(found) {

mainWindow.webContents.send("loading", { loading: true, msg: "Starting local replay server..." });
replayServer.startServer();

mainWindow.webContents.send("clientInfo", { found: lolClient.isFound(), version: lolClient.version() });
mainWindow.webContents.send("loading", { loading: false, msg: "" });

saveUserSettings();
});
});
});
});
});


// Called when the user wants to select the league client manually
ipc.on("selectClient", function(event, args) {
var files = dialog.showOpenDialog({
filters: [{ name: 'League of Legends Client', extensions: ['app', 'exe'] }],
properties: [ "openFile" ]
});

if (files && files.length == 1) {
lolClient.extractPath(files[0]);
event.sender.send("clientInfo", { found: lolClient.isFound(), version: lolClient.version() });
lolClient.extractPath(files[0], function() {
event.sender.send("clientInfo", { found: lolClient.isFound(), version: lolClient.version() });
saveUserSettings();
});
}
});


// Called when the user wants to open a replay
ipc.on("openReplay", function(event, args) {
let files = dialog.showOpenDialog({
filters: [{ name: 'Replay File', extensions: ['aof'] }],
Expand All @@ -148,6 +209,9 @@ ipc.on("openReplay", function(event, args) {
});
}
});


// Called when the user wants to play a replay
ipc.on("play", function(event, args) {
replayServer.resetReplay();

Expand All @@ -162,6 +226,7 @@ ipc.on("play", function(event, args) {
}
});


// Setup windows
app.on("ready", function() {
mainWindow = new BrowserWindow({
Expand Down
Loading

0 comments on commit c3e9c7f

Please sign in to comment.