diff --git a/lol-events-sample-app/icon.png b/lol-events-sample-app/icon.png new file mode 100644 index 0000000..4edf709 Binary files /dev/null and b/lol-events-sample-app/icon.png differ diff --git a/lol-events-sample-app/icon_gray.png b/lol-events-sample-app/icon_gray.png new file mode 100644 index 0000000..d677881 Binary files /dev/null and b/lol-events-sample-app/icon_gray.png differ diff --git a/lol-events-sample-app/index.html b/lol-events-sample-app/index.html new file mode 100644 index 0000000..332666b --- /dev/null +++ b/lol-events-sample-app/index.html @@ -0,0 +1,11 @@ + + + Overwolf LoL Sample App + + + + + +
+ + \ No newline at end of file diff --git a/lol-events-sample-app/main.js b/lol-events-sample-app/main.js new file mode 100644 index 0000000..a60b660 --- /dev/null +++ b/lol-events-sample-app/main.js @@ -0,0 +1,123 @@ +// this a subset of the features that LoL events provides - however, +// when writing an app that consumes events - it is best if you request +// only those features that you want to handle. +// +// NOTE: in the future we'll have a wildcard option to allow retreiving all +// features +var g_interestedInFeatures = [ + 'summoner_info', + 'gameMode', + 'teams', + 'matchState', + 'kill', + 'death', + 'respawn', + 'assist', + 'minions', + 'level', + 'abilities', + 'announcer', + 'counters', + 'match_info' + // 'gold' +]; + +function registerEvents() { + // general events errors + overwolf.games.events.onError.addListener(function(info) { + console.log("Error: " + JSON.stringify(info)); + }); + + // "static" data changed (total kills, username, steam-id) + // This will also be triggered the first time we register + // for events and will contain all the current information + overwolf.games.events.onInfoUpdates2.addListener(function(info) { + console.log("Info UPDATE: " + JSON.stringify(info)); + }); + + // an event triggerd + overwolf.games.events.onNewEvents.addListener(function(info) { + console.log("EVENT FIRED: " + JSON.stringify(info)); + }); +} + +function gameLaunched(gameInfoResult) { + if (!gameInfoResult) { + return false; + } + + if (!gameInfoResult.gameInfo) { + return false; + } + + if (!gameInfoResult.runningChanged && !gameInfoResult.gameChanged) { + return false; + } + + if (!gameInfoResult.gameInfo.isRunning) { + return false; + } + + // NOTE: we divide by 10 to get the game class id without it's sequence number + if (Math.floor(gameInfoResult.gameInfo.id/10) != 5426) { + return false; + } + + console.log("LoL Launched"); + return true; + +} + +function gameRunning(gameInfo) { + + if (!gameInfo) { + return false; + } + + if (!gameInfo.isRunning) { + return false; + } + + // NOTE: we divide by 10 to get the game class id without it's sequence number + if (Math.floor(gameInfo.id/10) != 5426) { + return false; + } + + console.log("LoL running"); + return true; + +} + + +function setFeatures() { + overwolf.games.events.setRequiredFeatures(g_interestedInFeatures, function(info) { + if (info.status == "error") + { + //console.log("Could not set required features: " + info.reason); + //console.log("Trying in 2 seconds"); + window.setTimeout(setFeatures, 2000); + return; + } + + console.log("Set required features:"); + console.log(JSON.stringify(info)); + }); +} + + +// Start here +overwolf.games.onGameInfoUpdated.addListener(function (res) { + if (gameLaunched(res)) { + registerEvents(); + setTimeout(setFeatures, 1000); + } + console.log("onGameInfoUpdated: " + JSON.stringify(res)); +}); + +overwolf.games.getRunningGameInfo(function (res) { + if (gameRunning(res)) { + registerEvents(); + setTimeout(setFeatures, 1000); + } + console.log("getRunningGameInfo: " + JSON.stringify(res)); +}); diff --git a/lol-events-sample-app/manifest.json b/lol-events-sample-app/manifest.json new file mode 100644 index 0000000..d9f562f --- /dev/null +++ b/lol-events-sample-app/manifest.json @@ -0,0 +1,48 @@ +{ + "manifest_version": "1", + "type": "WebApp", + "meta": { + "name": "LoL Game Events Consumer Sample", + "version": "0.0.1", + "minimum-overwolf-version": "0.92.300.0", + "author": "Overwolf", + "icon": "icon.png", + "icon_gray": "icon_gray.png", + "description": "Game Events Consumer Sample" + }, + "data": { + "start_window": "index", + "game_targeting": { + "type": "dedicated", + "game_ids": [5426] + }, + "windows": { + "index": { + "file": "index.html", + "transparent": true, + "clickthrough": true, + "resizable": false, + "show_in_taskbar": true, + "size": { + "width": 1150, + "height": 535 + }, + "start_position": { + "Top": 10, + "Left": 10 + } + } + }, + "game_events": [5426], + "launch_events": [ + { + "event": "GameLaunch", + "event_data": { + "game_ids": [ + 5426 + ] + }, + "start_minimized": false + }] +} +}