diff --git a/estusshots/choices.py b/estusshots/choices.py index 5fe954b..6b99f6b 100644 --- a/estusshots/choices.py +++ b/estusshots/choices.py @@ -1,4 +1,4 @@ -from estusshots.orm import new_session, EventType, Season, Player, Drink, Enemy +from estusshots.orm import new_session, EventType, Season, Player, Drink, Enemy, Episode def event_choices(): @@ -26,6 +26,13 @@ def player_choice(): return [(p.id, p.name) for p in players] +def player_choice_for_episode(episode: Episode): + """ + Create a list of ids and names for players of this episode + """ + return [(p.id, p.name) for p in episode.players] + + def drink_choice(): """ Query database for a list of all available drinks to select from diff --git a/estusshots/estus-shots.ts b/estusshots/estus-shots.ts deleted file mode 100644 index 55d3840..0000000 --- a/estusshots/estus-shots.ts +++ /dev/null @@ -1,17 +0,0 @@ -class EditorModule{ - - setCurrentTime = (elemId: string) => { - const elem = document.getElementById(elemId) as HTMLInputElement; - if (!elem) return; - elem.value = this.currentTimeHHMM() - }; - - currentTimeHHMM = () => { - const d = new Date(); - const hours = (d.getHours()<10 ? '0' : '') + d.getHours(); - const minutes = (d.getMinutes()<10 ? '0' : '') + d.getMinutes(); - return `${hours}:${minutes}`; - }; -} - -const editorModule = new EditorModule(); diff --git a/estusshots/static/js/estus-shots.js b/estusshots/static/js/estus-shots.js index 078b191..595db45 100644 --- a/estusshots/static/js/estus-shots.js +++ b/estusshots/static/js/estus-shots.js @@ -17,4 +17,42 @@ var EditorModule = (function () { return EditorModule; }()); var editorModule = new EditorModule(); +HTMLElement.prototype.addClass = function (cssClass) { + if (!this.classList.contains(cssClass)) { + this.classList.add(cssClass); + } +}; +HTMLElement.prototype.removeClass = function (cssClass) { + if (this.classList.contains(cssClass)) { + console.log(this.classList); + this.classList.remove(cssClass); + } +}; +var EventEditor; +(function (EventEditor) { + EventEditor.updateControls = function () { + var typeSelect = document.getElementById("event_type"); + var selectedType = typeSelect.options[typeSelect.selectedIndex].value; + var penalties = document.querySelector(".penalty-container"); + var player = document.getElementById("player_row"); + var enemy = document.getElementById("enemy_row"); + switch (selectedType) { + case "0": + penalties.addClass("d-none"); + player.addClass("d-none"); + enemy.addClass("d-none"); + break; + case "1": + penalties.removeClass("d-none"); + player.removeClass("d-none"); + enemy.removeClass("d-none"); + break; + case "2": + penalties.addClass("d-none"); + player.removeClass("d-none"); + enemy.removeClass("d-none"); + break; + } + }; +})(EventEditor || (EventEditor = {})); //# sourceMappingURL=estus-shots.js.map \ No newline at end of file diff --git a/estusshots/static/js/estus-shots.js.map b/estusshots/static/js/estus-shots.js.map index c273638..b047306 100644 --- a/estusshots/static/js/estus-shots.js.map +++ b/estusshots/static/js/estus-shots.js.map @@ -1 +1 @@ -{"version":3,"file":"estus-shots.js","sourceRoot":"","sources":["../../estus-shots.ts"],"names":[],"mappings":"AAAA;IAAA;QAAA,iBAcC;QAZC,mBAAc,GAAG,UAAC,MAAc;YAC9B,IAAM,IAAI,GAAG,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAqB,CAAC;YACjE,IAAI,CAAC,IAAI;gBAAE,OAAO;YAClB,IAAI,CAAC,KAAK,GAAG,KAAI,CAAC,eAAe,EAAE,CAAA;QACrC,CAAC,CAAC;QAEF,oBAAe,GAAG;YAChB,IAAM,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;YACrB,IAAM,KAAK,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,GAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC1D,IAAM,OAAO,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,GAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,CAAC;YAChE,OAAU,KAAK,SAAI,OAAS,CAAC;QAC/B,CAAC,CAAC;IACJ,CAAC;IAAD,mBAAC;AAAD,CAAC,AAdD,IAcC;AAED,IAAM,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC"} \ No newline at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static/js/estus-shots.ts new file mode 100644 index 0000000..e3b63b1 --- /dev/null +++ b/estusshots/static/js/estus-shots.ts @@ -0,0 +1,68 @@ +class EditorModule{ + + setCurrentTime = (elemId: string) => { + const elem = document.getElementById(elemId) as HTMLInputElement; + if (!elem) return; + elem.value = this.currentTimeHHMM() + }; + + currentTimeHHMM = () => { + const d = new Date(); + const hours = (d.getHours()<10 ? '0' : '') + d.getHours(); + const minutes = (d.getMinutes()<10 ? '0' : '') + d.getMinutes(); + return `${hours}:${minutes}`; + }; +} + +const editorModule = new EditorModule(); + +interface HTMLElement { + addClass(cssClass: string): void; + removeClass(cssClass: string): void; +} + +HTMLElement.prototype.addClass = function(cssClass: string): void { + if (!this.classList.contains(cssClass)){ + this.classList.add(cssClass); + } +}; +HTMLElement.prototype.removeClass = function(cssClass: string): void { + if (this.classList.contains(cssClass)){ + console.log(this.classList); + this.classList.remove(cssClass); + } +}; + +namespace EventEditor { + + export let updateControls = () => { + const typeSelect = document.getElementById("event_type") as HTMLSelectElement; + const selectedType = typeSelect.options[typeSelect.selectedIndex].value; + + const penalties = document.querySelector(".penalty-container") as HTMLDivElement; + const player = document.getElementById("player_row") as HTMLDivElement; + const enemy = document.getElementById("enemy_row") as HTMLDivElement; + + switch (selectedType) { + // Pause + case "0": + penalties.addClass("d-none"); + player.addClass("d-none"); + enemy.addClass("d-none"); + break; + // Death + case "1": + penalties.removeClass("d-none"); + player.removeClass("d-none"); + enemy.removeClass("d-none"); + break; + // Victory + case "2": + penalties.addClass("d-none"); + player.removeClass("d-none"); + enemy.removeClass("d-none"); + break; + } + } + +} diff --git a/estusshots/templates/event_editor.html b/estusshots/templates/event_editor.html index 82d4c0a..98ce5c1 100644 --- a/estusshots/templates/event_editor.html +++ b/estusshots/templates/event_editor.html @@ -4,6 +4,12 @@ {% block title %}{{ model.page_title }} {{ super() }}{% endblock %} {% block page %} + +