diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b95cdc5..e61bbdb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 1.77 (2024-09-15) + +- Adapt to KRCG V3 API + +## 1.76 (2024-08-22) + +- 30th anniversary, update buying guide + ## 1.75 (2024-05-04) - Fix Unnamed archetype diff --git a/codex_of_the_damned/static/js/card-search.js b/codex_of_the_damned/static/js/card-search.js index 16c88b82..7675153b 100644 --- a/codex_of_the_damned/static/js/card-search.js +++ b/codex_of_the_damned/static/js/card-search.js @@ -19,11 +19,9 @@ class CardSearch { this.card_title = document.getElementById("card-title") this.card_text = document.getElementById("card-text") this.rulings = document.getElementById("rulings") - this.ruling_form = document.getElementById("ruling-form") this.completion = new Completion(document.getElementById("card-name"), completeCardName, this.result_message) this.state = new UrlState(async (data) => this.displayCard(data)) this.form.addEventListener("submit", async (ev) => await this.submit(ev)) - this.ruling_form.addEventListener("submit", async (ev) => await this.submitRuling(ev)) } async submit(ev) { ev.preventDefault() @@ -188,23 +186,33 @@ class CardSearch { this.card_sets.appendChild(set_info) } let rulings_map = {} - if (data.rulings && data.rulings.text) { + console.log(data) + if (data.rulings.length > 0) { let rulings_list = document.createElement("ul") rulings_list.setAttribute("class", "rulings-list") this.rulings.appendChild(rulings_list) - for (const ruling of data.rulings.text) { - const reference_re = /\[[a-zA-Z0-9]+\s[0-9-]+\]/g + for (const ruling of data.rulings) { let ruling_item = document.createElement("li") - ruling_item.dataset.markdown = ruling.replace(reference_re, (x) => `${x}(${data.rulings.links[x]})`) - ruling_item.innerHTML = formatText(ruling.replace(reference_re, "")) - const references = [...ruling.matchAll(reference_re)] - for (const reference of references) { + let ruling_markdown = ruling.text + for (const reference of ruling.references) { + ruling_markdown = ruling_markdown.replaceAll( + reference.text, + `[[${reference.label}]](${reference.url})` + ) + } + ruling_item.dataset.markdown = ruling_markdown + let ruling_text = ruling.text + for (const reference of ruling.references) { // use non-breaking spaces and hyphens - const non_breaking_ref = reference[0].replace(" ", " ").replace(/([^-]*)-/g, "$1‑") - const link = data.rulings.links[reference[0]] - ruling_item.innerHTML += `${non_breaking_ref}` - rulings_map[non_breaking_ref] = link + const non_breaking_ref = reference.label.replace(" ", " ").replace(/([^-]*)-/g, "$1‑") + ruling_text = ruling_text.replace( + reference.text, + `[${non_breaking_ref}]` + ) + rulings_map[`[${non_breaking_ref}]`] = reference.url } + console.log(ruling_text) + ruling_item.innerHTML = formatText(ruling_text) addCardEvents(ruling_item) let copy_button = document.createElement("span") copy_button.classList.add("icon") @@ -309,49 +317,8 @@ class CardSearch { this.card_text.appendChild(pelem) } } - async submitRuling(ev) { - ev.preventDefault() - let elements = ev.target.elements - if (elements["submit"].disabled) { - return - } - elements["submit"].disabled = true - elements["result"].innerHTML = "
Please wait...
" - try { - const response = await fetch( - encodeURI(`https://api.krcg.org/submit-ruling/${encodeUrlParam(this.state.state.card)}`), - { - method: "POST", - body: JSON.stringify({ text: elements["explanation"].value, link: elements["url"].value }), - headers: { - "Content-Type": "application/json", - Accept: "application/json", - }, - } - ) - if (!response.ok) { - if (response.status >= 500 && response.status < 600) { - throw Error("KRCG bootstrapping, please try again in a minute.") - } else if (response.status == 400) { - throw Error("You must provide a valid ruling link.") - } else { - throw Error(response.statusText) - } - } - let data = await response.json() - elements[ - "result" - ].innerHTML = `Ruling submitted: you can consult it on GitHub.` - elements["explanation"].value = "" - elements["url"].value = "" - } catch (error) { - elements["result"].innerHTML = `
${error.message}
` - } - elements["submit"].disabled = false - } } function isInPrint(setInfo) { - console.log(setInfo) for (detail of setInfo[1]) { if ("release_date" in detail && detail.release_date >= "2017-05-01" && !setInfo[0].match(/(P|p)romo/g)) { if ("precon" in detail && detail.precon == "EC Berlin Edition") { diff --git a/codex_of_the_damned/templates/card-search.html b/codex_of_the_damned/templates/card-search.html index c6bf29d9..7577c3c0 100644 --- a/codex_of_the_damned/templates/card-search.html +++ b/codex_of_the_damned/templates/card-search.html @@ -41,76 +41,13 @@- {% trans trimmed %} - Proposed rulings will not be included automatically. - Once submited, your ruling will be reviewed by the Codex and KRCG team, - and included in the next release. + {% trans trimmed + rulings_website=external("https://rulings.krcg.org/index.html", "rulings website") + %} + Login with your VEKN account on the {{ rulings_website }} and submit a change proposal there. {% endtrans %}
-- {{ _('The Rules Directors have been:') }} -
- {{ _('The official boards for rulings have been:') }} -