From 1e78d2be8977e3479885be3f1203b41385303fb9 Mon Sep 17 00:00:00 2001 From: JBM Date: Fri, 29 May 2020 11:00:09 +0200 Subject: [PATCH 1/1] Make the trolling optional --- PLAN.org | 5 ++- src/main/java/com/codingame/game/View.java | 4 +-- src/main/resources/view/config.js | 39 +++++++++++++++++----- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/PLAN.org b/PLAN.org index 20cee16..d8d1402 100644 --- a/PLAN.org +++ b/PLAN.org @@ -43,6 +43,9 @@ That one's probably never going to be DONE ^^' Trolls are only counterfeits, made by the Enemy in the Great Darkness, in mockery of Ents, as Orcs were of Elves. J. R. R. Tolkien, The Two Towers (1954), Book III, Chapter 4: "Treebeard" * TODO View settings +- [ ] troll pants colors * TODO Troll quotes - pain au chocolat ou chocolatine - +* TODO initial model parametrization +* TODO view parameterization? +* TODO troll races diff --git a/src/main/java/com/codingame/game/View.java b/src/main/java/com/codingame/game/View.java index 857f527..9ef1d6b 100644 --- a/src/main/java/com/codingame/game/View.java +++ b/src/main/java/com/codingame/game/View.java @@ -27,8 +27,7 @@ class View { STILL("stands still.", 1), RIGHT("walks right.", 2); - String movement; - int index; + String movement; int index; Dir(String mvt, int i) { movement = mvt; index = i; } } @@ -375,6 +374,7 @@ class View { .setStrokeColor(0xFFFF00) .setFillColor(0xFFFF00) .setFontSize(40); + toggleModule.displayOnToggleState(trollMessage, "verboseTrolling", true); } private void moveTroll() { diff --git a/src/main/resources/view/config.js b/src/main/resources/view/config.js index 164519f..3ac3c9a 100644 --- a/src/main/resources/view/config.js +++ b/src/main/resources/view/config.js @@ -13,14 +13,35 @@ export const modules = [ , ToggleModule ]; +function trollCase(string) { + return string.split('') + .map(c => c < 64 ? c : String.fromCharCode(c.charCodeAt(0) ^ (32 * (Math.floor(2*Math.random()))))) + .join(''); +} + +function trollToggle(toggle, title, def) { + var obj = {}; + obj['toggle'] = toggle; + obj['title'] = trollCase(title); + obj['values'] = {}; + for (var i = 3; i < arguments.length; i += 2) { + obj['values'][trollCase(arguments[i])] = arguments[i+1]; + } + obj['default'] = def; + if (def == undefined) { + if (values.length > 2) { + obj['default'] = values.length * Math.floor(2 * Math.random()); + } + else { + obj['default'] = Math.random() < 0.5; + } + } + return ToggleModule.defineToggle(obj); +} + export const options = [ - ToggleModule.defineToggle({ - toggle: 'debug', - title: 'Debug Mode', - values: { - 'on': true, - 'off': false - }, - default: false - }) + trollToggle('verboseTrolling', 'Verbose Trolling', true, + 'on', true, 'off', false), + trollToggle('debug', 'Detroll Mode', false, + 'on', true, 'off', false) ]; -- 2.30.2