Skip to content

Commit

Permalink
Adapt to KRCG API V3
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel-panhaleux committed Sep 15, 2024
1 parent 2d144c5 commit 2189778
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 122 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
75 changes: 21 additions & 54 deletions codex_of_the_damned/static/js/card-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 += `<a target="_blank" href="${link}">${non_breaking_ref}</a >`
rulings_map[non_breaking_ref] = link
const non_breaking_ref = reference.label.replace(" ", " ").replace(/([^-]*)-/g, "$1‑")
ruling_text = ruling_text.replace(
reference.text,
`<a target="_blank" href="${reference.url}">[${non_breaking_ref}]</a >`
)
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")
Expand Down Expand Up @@ -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 = "<p>Please wait...</p>"
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 = `<p>Ruling submitted: you can consult it <a target="_blank", href="${data["html_url"]}">on GitHub</a>.`
elements["explanation"].value = ""
elements["url"].value = ""
} catch (error) {
elements["result"].innerHTML = `<p>${error.message}</p>`
}
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") {
Expand Down
73 changes: 5 additions & 68 deletions codex_of_the_damned/templates/card-search.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,76 +41,13 @@ <h3>{{ _('Rulings') }}</h3>
</div>
<div class="insert tip" id="submit-ruling">
<h3> {{ _('Submit a new ruling or a ruling correction') }}</h3>
<form id="ruling-form">
<p>
{% trans trimmed %}
Help improve the Codex: provide an explanation and a link to a message
from a Rules Director.
{% endtrans %}
</p>
<input type="text" class="long-input" name="explanation" id="ruling-form-explanation"
placeholder="Explanation">
<input type="text" class="long-input" name="url" id="ruling-form-url"
placeholder="http://www.vekn.net/forum/rules-questions/...">
<input type="submit" name="submit" value="Submit">
<output name="result" for="ruling-form-explanation ruling-form-url"></output>
</form>
<p>
{% trans trimmed %}
<strong>Proposed rulings will not be included automatically.</strong>
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 %}
</p>
<p>
{{ _('The Rules Directors have been:') }}
<ul>
<li>{{ _('From 2016-12-04 onward,') }}
<a target="_blank"
href="http://www.vekn.net/forum/news-and-announcements/75402-new-inner-circle-vekn-board-of-directors#79470">
Vincent Ripoll (ANK)
</a>
</li>
<li>{{ _('From 2011-07-06 onward,') }}
<a target="_blank"
href="https://groups.google.com/d/msg/rec.games.trading-cards.jyhad/VzRGZO_Iuto/BjJGRVvJ5Z8J">
Pascal Bertrand (PIB)
</a>
</li>
<li>{{ _('From 1998-06-22 onward,') }}
<a target="_blank"
href="https://groups.google.com/d/msg/rec.games.trading-cards.jyhad/RIX1tLgOFjg/xKikfSarfd8J">
L. Scott Johnson (LSJ)
</a>
</li>
<li>{{ _('From 1994-12-15 onward,') }}
<a target="_blank"
href="https://groups.google.com/d/msg/rec.games.trading-cards.jyhad/Dm_gIP3YvUs/qTyKyq2NWv4J">
Thomas R Wylie (TOM)
</a>
</li>
</ul>
</p>
<p>
{{ _('The official boards for rulings have been:') }}
<ul>
<li>{{ _('From 2011-07-06 onward,') }}
<a target="_blank" href="http://www.vekn.net/forum/rules-questions">
{{ _('The VEKN Forum') }}
</a>
</li>
<li>{{ _('From 2010-12-30 onward,') }}
<a target="_blank" href="https://www.boardgamegeek.com/forum/31522/vampire-eternal-struggle/rules">
{{ _('The Boardgame Geek Forum') }}
</a>
</li>
<li>{{ _('From 1994-12-15 onward,') }}
<a target="_blank" href="https://groups.google.com/forum/#!forum/rec.games.trading-cards.jyhad">
{{ _('The rec.games.trading-cards.jyhad Google Group') }}
</a>
</li>
</ul>
</p>
</div>
</div>
{% endblock %}
{% endblock %}

0 comments on commit 2189778

Please sign in to comment.