diff --git a/.gitignore b/.gitignore index d958da9..bd40008 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,13 @@ node_modules *.ipr *.iws .idea/ + + +### Typescript/Babel +packages/*/lib/ +.grunt +.baseDir.ts +.tscache +tmp/* +packages/*/typings/* +!packages/*/typings/custom diff --git a/package.json b/package.json index ae0955a..37f5941 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "update-all": "node ./scripts/npm-update-all.js" }, "dependencies": { - "async": "^2.0.0-rc.2", + "async": "^2.0.1", "colors": "^1.1.2" } } diff --git a/packages/maniajs-admin/src/game.js b/packages/maniajs-admin/src/game.js new file mode 100644 index 0000000..845956d --- /dev/null +++ b/packages/maniajs-admin/src/game.js @@ -0,0 +1,65 @@ +/** + * ADMIN COMMANDS - GAME ITSELF + */ +'use strict'; + + +/** + * Game Commands. + * + * @class + */ +module.exports.default = class { + constructor (plugin) { + this.plugin = plugin; + } + + /** + * Register all the player commands. + * + * @param {object} manager + * @param {function} manager.on + */ + register (manager) { + + /** + * /admin players + * Full player list, of the well known players (from database). + */ + manager.on('setmode', { + admin: true, + level: 3, + text: 'Set GameMode, rounds/ta/team/laps/cup/stunts' + }, (player, params) => this._setMode(player, params)); + } + + + /** + * /admin setmode + * + * @param player + * @param params + * @private + */ + _setMode (player, params) { + let mapping = { + rounds: 1, + ta: 2, + team: 3, + laps: 4, + cup: 5, + stunts: 6 + }; + + if (params.length === 0 || ! mapping.hasOwnProperty(params[0])) { + return this.plugin.server.send().chat('$F66Syntax Error:$z $fff$n/admin setmode [rounds/ta/team/laps/cup/stunts]$z', {destination: player.login}).exec(); + } + + return Promise.all([ + this.plugin.server.send() + .custom('SetGameMode', [mapping[params[0]]]).exec(), + this.plugin.server.send() + .chat(`$5A0Next game mode will be ${params[0]} and will be active from next map!`).exec() + ]); + } +}; diff --git a/packages/maniajs-admin/src/map.js b/packages/maniajs-admin/src/map.js index d23dcf7..f98865e 100644 --- a/packages/maniajs-admin/src/map.js +++ b/packages/maniajs-admin/src/map.js @@ -53,6 +53,16 @@ module.exports.default = class { text: 'Replay current map, add to the jukebox.' }, (player, params) => this._replay(player, params)); + /** + * /admin endround + * End Round. + */ + manager.on('endround', { + admin: true, + level: 2, + text: 'End current round.' + }, (player, params) => this._endround(player, params)); + /** * /admin savemaps * Save matchsettings list to disk! @@ -74,6 +84,11 @@ module.exports.default = class { this.server.send().custom('RestartMap').exec(); } + _endround (player, params) { + this.server.send().chat('$fffEnd round...').exec(); + this.server.send().custom('ForceEndRound').exec(); + } + _replay (player, params) { // TODO: Add support for maniajs-jukebox if (this.plugin.maps.current.uid) { diff --git a/packages/maniajs-admin/src/plugin.js b/packages/maniajs-admin/src/plugin.js index 9bbb682..6af2c19 100644 --- a/packages/maniajs-admin/src/plugin.js +++ b/packages/maniajs-admin/src/plugin.js @@ -6,6 +6,7 @@ var Plugin = require('@maniajs/plugin').default; var PlayerCommands = require('./player').default; var MapCommands = require('./map').default; +var GameCommands = require('./game').default; /** * ManiaJS Admin Plugin. @@ -33,7 +34,8 @@ module.exports.default = class extends Plugin { // Plugin Specific Variables this.components = [ new PlayerCommands(this), - new MapCommands(this) + new MapCommands(this), + new GameCommands(this) ]; } diff --git a/packages/maniajs-cpdifference/.gitignore b/packages/maniajs-cpdifference/.gitignore new file mode 100644 index 0000000..0de5731 --- /dev/null +++ b/packages/maniajs-cpdifference/.gitignore @@ -0,0 +1,34 @@ +### OS +.DS_Store +Thumbs.db + +### JetBrains template +*.iml +*.ipr +*.iws +.idea/ +.idea/mongoSettings.xml + +### Node template +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Dependency directory +node_modules + +### App Specific +config.yaml +database.sqlite diff --git a/packages/maniajs-cpdifference/LICENSE b/packages/maniajs-cpdifference/LICENSE new file mode 100644 index 0000000..e5fb4ee --- /dev/null +++ b/packages/maniajs-cpdifference/LICENSE @@ -0,0 +1,13 @@ +Copyright (c) 2016, ManiaJS + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/packages/maniajs-cpdifference/README.md b/packages/maniajs-cpdifference/README.md new file mode 100644 index 0000000..d1d7529 --- /dev/null +++ b/packages/maniajs-cpdifference/README.md @@ -0,0 +1,2 @@ +# maniajs-cpdifference +ManiaJS Plugin - Displays difference between current CP time and CP time of local/dedimania record. diff --git a/packages/maniajs-cpdifference/package.json b/packages/maniajs-cpdifference/package.json new file mode 100644 index 0000000..33b8e7a --- /dev/null +++ b/packages/maniajs-cpdifference/package.json @@ -0,0 +1,25 @@ +{ + "name": "@maniajs/plugin-cpdifference", + "version": "0.0.0", + "main": "src/plugin.js", + "description": "ManiaJS Plugin - CP Difference Plugin, displays difference between current CP time and local/dedimania CP time.", + "keywords": [ + "maniajs", + "maniaplanet", + "trackmania", + "plugin", + "cpdifference" + ], + "bugs": { + "url": "https://github.com/ManiaJS/plugins/issues" + }, + "license": "ISC", + "repository": "https://github.com/ManiaJS/plugins/tree/master/packages/maniajs-cpdifference", + "engines": { + "node": ">=4.0.0" + }, + "dependencies": { + "@maniajs/plugin": "0.*", + "async": "^2.0.1" + } +} diff --git a/packages/maniajs-cpdifference/src/models/.gitkeep b/packages/maniajs-cpdifference/src/models/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/packages/maniajs-cpdifference/src/plugin.js b/packages/maniajs-cpdifference/src/plugin.js new file mode 100644 index 0000000..3a61e6d --- /dev/null +++ b/packages/maniajs-cpdifference/src/plugin.js @@ -0,0 +1,214 @@ +'use strict'; + +var Package = require('./../package.json'); +var path = require('path'); + +var async = require('async'); + +var Plugin = require('@maniajs/plugin').default; + +/** + * LocalRecords Plugin. + */ +module.exports.default = class extends Plugin { + + constructor() { + super(); + + // Set the package stuff into the plugin context. + this.name = Package.name; + this.version = Package.version; + this.directory = __dirname; + this.records = null; + + // Add dependencies, enter module full id's (mostly npm package names) here. + this.dependencies = ['@maniajs/plugin-localrecords']; + this.players = []; + } + + /** + * Init will be run once the plugin can register everything at the core. + * From this point the {this.app} and all other injected variables are available. + * + * @return {Promise} The init should ALWAYS return a promise, the core will wait until the promise has been resolved! + */ + init() { + this.cpWidget = this.app.ui.build(this, 'cpwidget', 1); + this.cpWidget.global({ + manialinkid: 'CPDifference', + widget_x: -3.65, + widget_y: 21 + }); + + this.server.on('trackmania.player.checkpoint', + (params) => this.playerCheckpoint(params)); + + this.server.on('player.connect', (params) => { + let player = this.players.list[params.login]; + this.loadPlayerSetting(player); + }); + + this.server.on('player.disconnect', (params) => { + delete this.players[params.login]; + }); + + Object.keys(this.players.list).forEach((login) => { + let player = this.players.list[login]; + this.loadPlayerSetting(player); + }); + + this.server.command.on('cpdifference', 'Change your CP Difference setting', (player, params) => this.setPlayerSettingCommand(player, params)); + this.server.command.on('cps', 'Change your CP Difference setting', (player, params) => this.setPlayerSettingCommand(player, params)); + + return Promise.resolve(); + } + + /** + * Loads CP Difference setting for player into the local playerlist. + * + * @param player + */ + loadPlayerSetting(player) { + this.settings.get('cpDifference', player.id).then((setting) => { + if(! setting) { + this.setPlayerSetting(player, 'own'); + } else { + this.players[player.login] = setting.value; + } + }); + } + + /** + * Saves CP Difference setting for player. + * + * @param player + * @param setting + */ + setPlayerSetting(player, setting) { + this.players[player.login] = setting; + this.settings.set('cpDifference', player.id, setting); + } + + /** + * Allows player to update their CP Difference setting. + * + * @param player + * @param params + */ + setPlayerSettingCommand(player, params) { + switch(params[0]) { + case 'own': + this.setPlayerSetting(player, 'own'); + this.server.send().chat('$fffSet CP Difference to use own record (or last local in case of no record).', {destination: player.login}).exec(); + break; + case 'local': + this.setPlayerSetting(player, 'local'); + this.server.send().chat('$fffSet CP Difference to use first local record.', {destination: player.login}).exec(); + break; + case 'dedi': + this.setPlayerSetting(player, 'dedi'); + this.server.send().chat('$fffSet CP Difference to use first dedimania record.', {destination: player.login}).exec(); + break; + case 'help': + default: + let ownBold = ''; + let localBold = ''; + let dediBold = ''; + + switch(this.players[player.login]) { + case 'own': + ownBold = '$o'; + break; + case 'local': + localBold = '$o'; + break; + case 'dedi': + dediBold = '$o'; + break; + } + this.server.send().chat('$fffUsage: /cpdifference (or /cps) [$eee' + ownBold + 'own (or last)' + ownBold + ', ' + localBold + 'local' + localBold + ', ' + dediBold + 'dedi' + dediBold + '$fff]', {destination: player.login}).exec(); + break; + } + } + + /** + * Function registers when a player passes a checkpoint and saves this in the current runs. + * playerId: 0, + * login: 1, + * timeOrScore: 2, + * curLap: 3, + * checkpoint: 4 + * + * @param checkpoint + */ + playerCheckpoint(checkpoint) { + let player = this.players.list[checkpoint.login]; + if(this.players[player.login] == 'own') { + this.app.plugins['@maniajs/plugin-localrecords'].getPersonalMapRecord(this.maps.list[this.maps.current.uid], player).then((personalRecord) => { + if(personalRecord.rank != null) { + let checkpoints = personalRecord.checkpoints.split(','); + let currentCheckpoint = checkpoint.timeOrScore; + let recordCheckpoint = checkpoints[checkpoint.checkpoint]; + + this.displayUI(player, 'personal', currentCheckpoint, recordCheckpoint); + } else { + this.playerCheckpointLastRecord(player, checkpoint); + } + }).catch(() => { + this.playerCheckpointLastRecord(player, checkpoint); + }); + } else if(this.players[player.login] == 'local') { + this.app.plugins['@maniajs/plugin-localrecords'].getMapRecord(this.maps.list[this.maps.current.uid]).then((localRecord) => { + let checkpoints = localRecord.checkpoints.split(','); + let currentCheckpoint = checkpoint.timeOrScore; + let recordCheckpoint = checkpoints[checkpoint.checkpoint]; + + this.displayUI(player, 'local', currentCheckpoint, recordCheckpoint); + }); + } + } + + /** + * Function requests last record to be displayed. + * + * @param player + * @param checkpoint + */ + playerCheckpointLastRecord(player, checkpoint) { + this.app.plugins['@maniajs/plugin-localrecords'].getLastMapRecord(this.maps.list[this.maps.current.uid]).then((lastRecord) => { + let checkpoints = lastRecord.checkpoints.split(','); + let currentCheckpoint = checkpoint.timeOrScore; + let recordCheckpoint = checkpoints[checkpoint.checkpoint]; + + this.displayUI(player, 'last', currentCheckpoint, recordCheckpoint); + }); + } + + /** + * Display UI to the player. + * + * @param player + * @param recordType + * @param current + * @param comparison + */ + displayUI(player, recordType, current, comparison) { + let difference = (current - comparison); + let improve = false; + + let text = ''; + if(difference < 0) { + improve = true; + difference *= -1; + + text += '$00C-'; + } else { + text += '$C00+'; + } + + text += this.app.util.times.stringTime(difference); + + this.cpWidget.timeout = 2000; + this.cpWidget.player(player.login, {difference: text, recordType: recordType}).update(); + } +}; diff --git a/packages/maniajs-cpdifference/src/view/cpwidget.hbs b/packages/maniajs-cpdifference/src/view/cpwidget.hbs new file mode 100644 index 0000000..a0bf813 --- /dev/null +++ b/packages/maniajs-cpdifference/src/view/cpwidget.hbs @@ -0,0 +1,4 @@ + +