From 0f5e668c102fbc243931b741301b6c51147e0f2c Mon Sep 17 00:00:00 2001 From: Juan Ignacio Catalano Date: Mon, 6 Dec 2021 20:12:15 -0300 Subject: [PATCH] Adding CongaCelebration --- audio/input.js | 4 +- server/setups/program-presets/default.json | 38 +++++++++++++++++++ server/src/LightController.js | 1 + .../light-programs/conga-utils/GlobalGame.js | 18 +++++++++ .../programs/congaCelebration.js | 36 ++++++++++++++++++ .../light-programs/programs/congaShooting2.js | 12 +----- 6 files changed, 97 insertions(+), 12 deletions(-) create mode 100644 server/src/light-programs/programs/congaCelebration.js diff --git a/audio/input.js b/audio/input.js index 8cd6c672..ccf74635 100644 --- a/audio/input.js +++ b/audio/input.js @@ -13,7 +13,7 @@ class AudioInput extends EventEmitter { constructor(options) { super(); // this._sampleRate = options._sampleRate || 48000; - const deviceIndex = options.deviceIndex || null; + const deviceIndex = options.deviceIndex ?? null; const profile = options.profile || null; this._args = [ '-u' ]; if (!profile) { @@ -22,7 +22,7 @@ class AudioInput extends EventEmitter { const profilePath = options.profilePath || 'audioprofile.pstats'; this._args.push('-m', 'cProfile', '-o', profilePath, mainScript); } - if (deviceIndex) { + if(deviceIndex !== undefined ){ this._args.push('-d', deviceIndex.toString()); } this._subprocess = null; diff --git a/server/setups/program-presets/default.json b/server/setups/program-presets/default.json index c3993f6d..9162ace9 100644 --- a/server/setups/program-presets/default.json +++ b/server/setups/program-presets/default.json @@ -392,6 +392,44 @@ } } ] + }, + "ShootingArcCelebration": { + "programs": [ + { + "programName": "congaShooting2", + "shape": "fullArc", + "config": { + "fireThreshold": 0.31 + } + }, + { + "programName": "congaScore", + "shape": "highestSide", + "config": { + "playerNumber": 1, + "globalBrightness": 0.47, + "reverse": true, + "colorHue": 0.7, + "colorSat": 0.7 + } + }, + { + "programName": "congaScore", + "shape": "lowestSide", + "config": { + "globalBrightness": 1, + "reverse": true, + "playerNumber": "0", + "colorHue": 0.71, + "colorSat": 0.84 + } + }, + { + "programName": "congaCelebration", + "shape": "head" + } + ], + "fps": 60 } }, "sound-waves": { diff --git a/server/src/LightController.js b/server/src/LightController.js index 9feb8319..8650a43b 100644 --- a/server/src/LightController.js +++ b/server/src/LightController.js @@ -18,6 +18,7 @@ const programNames = [ "mix", "congaShooting2", "congaScore", + "congaCelebration", "congaShooting", "congaRope", "PROGRAM_Main_fuego2019", diff --git a/server/src/light-programs/conga-utils/GlobalGame.js b/server/src/light-programs/conga-utils/GlobalGame.js index 208f8b63..5dcefe1c 100644 --- a/server/src/light-programs/conga-utils/GlobalGame.js +++ b/server/src/light-programs/conga-utils/GlobalGame.js @@ -1,6 +1,10 @@ +const ColorUtils = require("./../utils/ColorUtils"); + class Game { constructor() { this.score = [0,0]; + this.player1Color = ColorUtils.HSVtoRGB(400, 1, 1); + this.player2Color = ColorUtils.HSVtoRGB(400+0.33, 1, 1); } addPoint(playerIndex, points = 1) { @@ -14,6 +18,20 @@ class Game { restart() { this.score = [0,0]; } + + winner(){ + let winner = false; + if (this.score[0] == this.max()){ + winner = 1; + } + else if(this.score[1] == this.max()){ + winner = 2; + } + if(winner){ + this.restart(); + } + return winner; + } } module.exports = { diff --git a/server/src/light-programs/programs/congaCelebration.js b/server/src/light-programs/programs/congaCelebration.js new file mode 100644 index 00000000..5ea1a011 --- /dev/null +++ b/server/src/light-programs/programs/congaCelebration.js @@ -0,0 +1,36 @@ +const LightProgram = require("./../base-programs/LightProgram"); +const ColorUtils = require("./../utils/ColorUtils"); +const GlobalGame = require("./../conga-utils/GlobalGame"); + +module.exports = class CongaCelebratiton extends LightProgram { + constructor(config, geometry) { + super(config, geometry); + this.celebrate = 0; + this.winner = false; + this.colors = new Array(this.numberOfLeds).fill(ColorUtils.HSVtoRGB(0, 0, this.config.brillo)); + } + + drawFrame(draw) { + let winner = GlobalGame.game.winner(); + if (winner && (this.celebrate == 0 || winner != this.winner)){ + this.winner = winner; + this.celebrate = this.config.celebrationDurationInFrames; + } + + if (this.celebrate > 0){ + let winnerColor = this.winner == 1 ? GlobalGame.game.player1Color : GlobalGame.game.player2Color; + this.colors = new Array(this.numberOfLeds).fill(winnerColor); + this.celebrate--; + } + draw(this.colors); + } + + // Override and extend config Schema + static configSchema() { + let res = super.configSchema(); + res.brillo = { type: Number, min: 0, max: 1, step: 0.01, default: 0.5 }; + res.celebrationDurationInFrames = { type: Number, min: 0, max: 200, step: 5, default: 1000 }; + res.program = {type: 'programs', default: [{programName: 'all-off'}]}; + return res; + } +}; diff --git a/server/src/light-programs/programs/congaShooting2.js b/server/src/light-programs/programs/congaShooting2.js index 03d562c2..169fcad5 100644 --- a/server/src/light-programs/programs/congaShooting2.js +++ b/server/src/light-programs/programs/congaShooting2.js @@ -41,10 +41,6 @@ module.exports = class CongaShooting extends LightProgram { if(b.pos < 0 || b.pos > this.numberOfLeds) { this.bulletsA = _.without(this.bulletsA, b); GlobalGame.game.addPoint(0); - - if(GlobalGame.game.score[0] === 10) { - GlobalGame.game.restart() - } } } @@ -54,10 +50,6 @@ module.exports = class CongaShooting extends LightProgram { if(b.pos < 0 || b.pos > this.numberOfLeds) { this.bulletsB = _.without(this.bulletsB, b); GlobalGame.game.addPoint(1); - - if(GlobalGame.game.score[1] === 10) { - GlobalGame.game.restart() - } } } @@ -97,12 +89,12 @@ module.exports = class CongaShooting extends LightProgram { this.colors[i] = baseColor; for(const b of this.bulletsA){ if (Math.abs(b.pos - i) < this.config.speed){ - this.colors[i] = ColorUtils.HSVtoRGB(b.size/400, 1, 1); + this.colors[i] = GlobalGame.game.player1Color; } } for(const b of this.bulletsB){ if (Math.abs(b.pos - i) < this.config.speed){ - this.colors[i] = ColorUtils.HSVtoRGB(b.size/400+0.33, 1, 1); + this.colors[i] = GlobalGame.game.player2Color; } } }