Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find custom set symbols by set code #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions js/creator-23.js
Original file line number Diff line number Diff line change
Expand Up @@ -4263,6 +4263,28 @@ function uploadSetSymbol(imageSource, otherParams) {
};
}
}
async function uploadLocalSetSymbol(imageName, otherParams) {
// Try different paths for local set symbols, prioritizing custom over official and svgs over pngs.
if (otherParams && otherParams == 'resetSetSymbol') {
setSymbol.onload = function() {
resetSetSymbol();
setSymbol.onload = setSymbolEdited;
};
}
const variations = [
`/img/setSymbols/custom/${imageName}.svg`,
`/img/setSymbols/custom/${imageName}.png`,
`/img/setSymbols/official/${imageName}.svg`,
`/img/setSymbols/official/${imageName}.png`,
]
for (url of variations) {
response = await fetch(url, {method: "HEAD"});
if (response.ok) {
setSymbol.src = url;
break;
}
}
}
function setSymbolEdited() {
card.setSymbolSource = setSymbol.src;
if (document.querySelector('#lockSetSymbolURL').checked) {
Expand Down Expand Up @@ -4306,22 +4328,18 @@ function fetchSetSymbol() {
}
var setRarity = document.querySelector('#set-symbol-rarity').value.toLowerCase().replace('uncommon', 'u').replace('common', 'c').replace('rare', 'r').replace('mythic', 'm') || 'c';
if (['sld', 'a22', 'a23', 'j22'].includes(setCode.toLowerCase())) {
uploadSetSymbol(fixUri(`/img/setSymbols/custom/${setCode.toLowerCase()}-${setRarity}.png`), 'resetSetSymbol');
uploadLocalSetSymbol(`${setCode.toLowerCase()}-${setRarity}`, 'resetSetSymbol');
} else if (['cc', 'logan', 'joe'].includes(setCode.toLowerCase())) {
uploadSetSymbol(fixUri(`/img/setSymbols/custom/${setCode.toLowerCase()}-${setRarity}.svg`), 'resetSetSymbol');
uploadLocalSetSymbol(`${setCode.toLowerCase()}-${setRarity}`, 'resetSetSymbol');
} else if (document.querySelector("#set-symbol-source").value == 'gatherer') {
if (setSymbolAliases.has(setCode.toLowerCase())) setCode = setSymbolAliases.get(setCode.toLowerCase());
uploadSetSymbol('http://gatherer.wizards.com/Handlers/Image.ashx?type=symbol&set=' + setCode + '&size=large&rarity=' + setRarity, 'resetSetSymbol');
} else if (document.querySelector("#set-symbol-source").value == 'hexproof') {
if (setSymbolAliases.has(setCode.toLowerCase())) setCode = setSymbolAliases.get(setCode.toLowerCase());
uploadSetSymbol('https://api.hexproof.io/symbols/set/' + setCode + '/' + setRarity, 'resetSetSymbol');
} else {
var extension = 'svg';
if (['moc', 'ltr', 'ltc', 'cmm', 'who', 'scd', 'woe', 'wot', 'woc', 'lci', 'lcc', 'mkm', 'mkc', 'otj', 'otc'].includes(setCode.toLowerCase())) {
extension = 'png';
}
if (setSymbolAliases.has(setCode.toLowerCase())) setCode = setSymbolAliases.get(setCode.toLowerCase());
uploadSetSymbol(fixUri(`/img/setSymbols/official/${setCode.toLowerCase()}-${setRarity}.` + extension), 'resetSetSymbol');
uploadLocalSetSymbol(`${setCode.toLowerCase()}-${setRarity}`, 'resetSetSymbol');
}
}
function lockSetSymbolCode() {
Expand Down