Skip to content

Commit

Permalink
Added extensive mode + fixed multible critical bugs + we no longer di…
Browse files Browse the repository at this point in the history
…splay multiple cards when editing or creating a phrase
  • Loading branch information
Madman10K committed Nov 5, 2023
1 parent 10db17c commit 5e946aa
Show file tree
Hide file tree
Showing 10 changed files with 257 additions and 68 deletions.
16 changes: 15 additions & 1 deletion Translations/bg_BG.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ translations:
text: "Профил"
- id: locale
text: "bg_BG/"
- id: extensive-mode-title
text: "Включва т.н. подробен режим. Вместо преглеждане на картите само веднъж, картите се преглеждат няколко пъти, като постепенно се премахват картите с най-високо ниво на познание."
- id: extensive-mode-aria-label
text: "Чекбокс за подробен режим"
- id: extensive-mode-label
text: "Подробен режим"
- id: game_modifiers_header
text: "Настройки за играта"

# Coming soon
- id: coming-soon-header
Expand Down Expand Up @@ -89,6 +97,12 @@ translations:
text: "Фраза"
- id: card_character
text: "Символ"
- id: delete-edit-button
text: "Изтрий"
- id: deck-new-delete-phrase
text: "Сигурни ли сте, че искате да ИЗТРИЕТЕ тази фраза. ИЗТРИТАТА ИНФОРМАЦИЯ НЕ МОЖЕ ДА СЕ ВЪЗСТАНОВЕНА!"
- id: deck-new-delete-card
text: "Сигурни ли сте, че искате да ИЗТРИЕТЕ този символ. ИЗТРИТАТА ИНФОРМАЦИЯ НЕ МОЖЕ ДА БЪДЕ ВЪЗСТАНОВЕНА!"

# deck.html
- id: profile-statistics-header
Expand Down Expand Up @@ -198,7 +212,7 @@ translations:
- id: about_h2
text: "История на разработката"
- id: about_p3_1
text: "През Януари 2023, {} решава да създатае {{ trademark }}, като решение за проблема с липсата за приложения за учене на китайски символи и други писмености. Той не намерил друго съществуващо решение, и следователно разработил собствено. Първоначално създадено, като платформа за учене на китайски символи, {{ trademark }} вече поддържа други писмености, като Хирагана, Катакана, Кирилица, Латинската азбука, Гръцката азбука, и др."
text: "През Януари 2023, {} решава да създаде {{ trademark }}, като решение на проблема с липсата на приложения за учене на китайски символи и други писмености. Той не намерил друго съществуващо решение, и следователно разработил собствено. Първоначално създадено, като платформа за учене на китайски символи, {{ trademark }} вече поддържа други писмености, като Хирагана, Катакана, Кирилица, Латинската азбука, Гръцката азбука, и др."
- id: about_p3_2
text: "Името {{ trademark }} идва от тъпа шега за играта {}, където хората в интернет полудяваха, когато виждаха различни обекти, наподобяващи очертанието на членовете на екипажа от играта. На китайски, името използва 2-та символа \"卣囙\"(произнсят ся, като \"yǒuyīn\" на пинйин), които изглеждат, като членовете от екипажа. Освен това, името на сайта е подобно на следните 3 думи:"
- id: about_p3_li_1
Expand Down
14 changes: 14 additions & 0 deletions Translations/en_US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ translations:
text: "Account"
- id: locale
text: "en_US/"
- id: extensive-mode-title
text: "Turns on extensive mode. Instead of going through all cards only once, extensive mode goes through the deck multiple times, gradually eliminating the cards with the highest knowledge."
- id: extensive-mode-aria-label
text: "Extensive mode checkbox"
- id: extensive-mode-label
text: "Extensive mode"
- id: game_modifiers_header
text: "Game modifiers"

# Coming soon
- id: coming-soon-header
Expand Down Expand Up @@ -89,6 +97,12 @@ translations:
text: "Phrase"
- id: card_character
text: "Character"
- id: delete-edit-button
text: "Delete"
- id: deck-new-delete-phrase
text: "Are you sure you want to DELETE this phrase. THIS CANNOT BE UNDONE!"
- id: deck-new-delete-card
text: "Are you sure you want to DELETE this character. THIS CANNOT BE UNDONE!"

# deck.html
- id: profile-statistics-header
Expand Down
1 change: 1 addition & 0 deletions deck-edit-card.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ <h1 class="centered">{{ _ phrase-preview-section-header }}</h1>
</section>
<section id="navigation-footer">
<button id="finish-edit-button" class="card-button-edit">{{ _ finish-edit-button }}</button>
<button id="delete-edit-button" class="card-button-edit" style="display:none">{{ _ delete-edit-button }}</button>
<button id="cancel-edit-button" class="card-button-edit">{{ _ cancel-edit-button }}</button>
</section>
</main>
Expand Down
98 changes: 60 additions & 38 deletions deck-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ function pinyinify(string) {
*/
function constructPreviewCardGeneric(index, it, owner)
{
let root = addElement("div", "", `character-preview-${index}`, "card centered", "", owner);

let lit = it;
// Local it variable because phrases will require finding the card
if (it === null || it["phrase"])
Expand All @@ -95,13 +93,8 @@ function constructPreviewCardGeneric(index, it, owner)
}

for (let i in window.previewCards)
{
if (window.previewCards[i].character === it.phrase[index])
{
lit = window.previewCards[i];
break;
}
}
return window.previewCards[i];
}

if (it === null || lit === it)
Expand All @@ -117,6 +110,8 @@ function constructPreviewCardGeneric(index, it, owner)
}
}

let root = addElement("div", "", `character-preview-${index}`, "card centered", "", owner);

addElement("h3", lit.name, `card-preview-name-${index}`, "", "", root);
let writerArea = addElement("div", "", `card-character-target-div-preview-${index}`, "", "", root);
addElement("p", `${lc.deck_definitions}`, "", "", "", root);
Expand All @@ -143,7 +138,7 @@ function constructPreviewCardGeneric(index, it, owner)

/**
* Constructs an input element
* @param {HTMLElement} container - The parent HTML element to attach to
* @param { HTMLElement } container - The parent HTML element to attach to
* @param { string } id - ID for the input element
* @param { string } classT - Class for the input element
* @param { string } type - Type attribute of the input element
Expand Down Expand Up @@ -311,14 +306,8 @@ function constructEditCard(index, it, root, bPhrase)
bReadOnly = false;

for (let f = index - 1; f >= 0; --f)
{
if (it.phrase[f] === it.phrase[index])
{
bReadOnly = true;
bAllowChangingCharacter = false;
break;
}
}
return;
break;
}
}
Expand All @@ -329,7 +318,7 @@ function constructEditCard(index, it, root, bPhrase)
bReadOnly = false;

let container = addElement("div", "", `edit-phrase-${index}`, "card centered", "", root);
container.setAttribute("yy-readonly", bReadOnly);
container.setAttribute("yy-readonly", bReadOnly.toString());

addElement("h3", `${lc.card_name}: ` + (bReadOnly
? lit.name
Expand Down Expand Up @@ -359,26 +348,36 @@ function constructEditCard(index, it, root, bPhrase)
characterInput.value = lit !== null ? (lit["character"] ? lit.character : lit.phrase) : "";
}

if (lit !== null && lit["phrase"] && characterInput !== null)
if (lit !== null && characterInput !== null)
{
characterInput.addEventListener("change", (event) => {
let phrasePreviewContainer = $("phrase-preview-section-container");
let cardEditSection = $("card-edit-section");

// Clear children and reconstruct previews
phrasePreviewContainer.replaceChildren();
cardEditSection.replaceChildren();
lit.phrase = event.target.value;

window.previewCards = [];
constructPhraseEditCardPreview(lit, phrasePreviewContainer);
constructEditCard("phrase", lit, cardEditSection, true);
for (let i in lit.phrase)
{
constructPreviewCardGeneric(i, lit, phrasePreviewContainer);
constructEditCard(i, lit, cardEditSection, false);
}
});
if (lit["phrase"])
{
characterInput.addEventListener("change", (event) => {
let phrasePreviewContainer = $("phrase-preview-section-container");
let cardEditSection = $("card-edit-section");

// Clear children and reconstruct previews
phrasePreviewContainer.replaceChildren();
cardEditSection.replaceChildren();
lit.phrase = event.target.value === "" ? window.CARD_DEFAULT_CHARACTER : event.target.value;

window.previewCards = [];
constructPhraseEditCardPreview(lit, phrasePreviewContainer);
constructEditCard("phrase", lit, cardEditSection, true);
for (let i in lit.phrase)
{
constructPreviewCardGeneric(i, lit, phrasePreviewContainer);
constructEditCard(i, lit, cardEditSection, false);
}
});
}
else if (lit["character"])
{
characterInput.addEventListener("change", (e) => {
$(`card-character-target-div-preview-${index}`).writer.setCharacter(e.target.value + lit.variant);
lit.character = e.target.value;
})
}
}

if (!bPhrase && !bReadOnly)
Expand Down Expand Up @@ -415,16 +414,39 @@ function constructListElements()
let dataContainer = null;
let index = null;

let deleteButton = $("delete-edit-button");
if (urlParams.has("edit"))
{
dataContainer = window.localStorageData.cards;
index = urlParams.get("edit");
deleteButton.style.display = "inline-block";

deleteButton.cardIndex = index;
runEventAfterAnimation(deleteButton, "click", (e) => {
if (confirm(lc.deck_new_delete_card))
{
window.localStorageData.cards.splice(e.target.cardIndex, 1);
saveToLocalStorage(window.localStorageData);
location.href = "./deck.html";
}
});
}
else if (urlParams.has("phrase-edit"))
{
dataContainer = window.localStorageData.phrases;
index = urlParams.get("phrase-edit");
$("phrase-preview-section").style.display = "block";
deleteButton.style.display = "inline-block";

deleteButton.cardIndex = index;
runEventAfterAnimation(deleteButton, "click", (e) => {
if (confirm(lc.deck_new_delete_phrase))
{
window.localStorageData.phrases.splice(e.target.cardIndex, 1);
saveToLocalStorage(window.localStorageData);
location.href = "./deck.html";
}
});
}

let cardEditSection = $("card-edit-section");
Expand Down Expand Up @@ -460,8 +482,8 @@ function constructListElements()
}
else
{
let lit = constructPreviewCardGeneric(0, null, cardEditSection);
constructEditCard(0, lit, cardEditSection, false);
constructPreviewCardGeneric(0, null, cardEditSection);
constructEditCard(0, window.previewCards[0], cardEditSection, false);

// Reverse children of $("card-edit-section") because we display the preview before the edit widget
for (let i = 0; i < cardEditSection.childNodes.length; i++)
Expand Down
5 changes: 5 additions & 0 deletions deck.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ <h3>{{ _ profile-statistics-header }}</h3>
<p id="average-knowledge-level-field">{{ _ average-knowledge-level-field }}: </p>
<p id="average-session-length-field">{{ _ average-session-length-field }}: </p>
<p id="time-spent-in-sessions-field">{{ _ time-spent-in-sessions-field }}: </p>
<h3>{{ _ game_modifiers_header }}</h3>
<label title="{{ _ extensive-mode-title }}">
<input type="checkbox" id="extensive-mode-checkbox" name="{{ _ extensive-mode-aria-label }}" aria-label="{{ _ extensive-mode-aria-label }}"/>
{{ _ extensive-mode-label }}
</label>
</div>
<div id="new-card" class="card centered">
<h1 id="new-card-header">+</h1>
Expand Down
18 changes: 15 additions & 3 deletions deck.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ function setProfileCardData()
/**
* Constructs a card HTML element
* @param { Object } it - Struct for the card data
* @param { int } index - Used to create UUIDs. For normal cards, it's offset by the number of phrases
* @param { number } index - Used to create UUIDs. For normal cards, it's offset by the number of phrases
* @param { HTMLElement } container - HTML element to attach to
* @param { int } localIndex - non-unique index
* @param { number } localIndex - non-unique index
*/
function constructCard(it, index, container, localIndex)
{
Expand Down Expand Up @@ -209,12 +209,24 @@ function constructCard(it, index, container, localIndex)
}
}

function setupGameModifiers()
{
const extensiveModeCheckbox = $("extensive-mode-checkbox");
extensiveModeCheckbox.checked = window.gameModifiers.extensive;

extensiveModeCheckbox.addEventListener("change", function(){
window.gameModifiers.extensive = this.checked;
saveGameModifiers();
});
}

/**
* Main function for the deck page
*/
function deckmain()
{
setProfileCardData();
setupGameModifiers();

// Get the elements and load their onclick events, holy shit that's massive! That's what she said!
runEventAfterAnimation($("export-deck-button"), "click", updateExportButton);
Expand Down Expand Up @@ -259,7 +271,7 @@ function deckmain()
for (let val in data.cards)
{
const it = data.cards[val];
constructCard(it, val + data.phrases.length, cardsContainer, val);
constructCard(it, (val + data.phrases.length), cardsContainer, val);
}
}

Expand Down
3 changes: 3 additions & 0 deletions i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ lc.no_cards_link_deck = "{{ _ no_cards_link_deck }}";
lc.no_cards_text = "{{ _ no_cards_text }}";
lc.no_cards_text_postfix = "{{ _ no_cards_text_postfix }}";

lc.deck_new_delete_card = "{{ _ deck-new-delete-card }}"
lc.deck_new_delete_phrase = "{{ _ deck-new-delete-phrase }}"

// marketplace.js
lc.leveled_up_no = "{{ _ leveled_up_no }}";
lc.leveled_up_yes = "{{ _ leveled_up_yes }}";
Expand Down
17 changes: 17 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ window.WRITER_SHOW_HINT_ON_ERRORS_LVL_3 = 1;
// ---------------------------------- CONSTANT BLOCK END ----------------------------------

window.localStorageData = null;
window.gameModifiers = null;

/**
* Troll jQuery developers. Returns the element with the given id
Expand Down Expand Up @@ -89,6 +90,11 @@ function saveToLocalStorage(obj)
window.localStorage.setItem("youyinCardData", JSON.stringify(obj));
}

function saveGameModifiers()
{
window.localStorage.setItem("youyinGameModifiers", JSON.stringify(window.gameModifiers));
}

/**
* Utility function to create an HTML element in a single line
* @param { string } elType - Type of the new element
Expand Down Expand Up @@ -231,6 +237,17 @@ function main()
document.location.reload();
}

window.gameModifiers = JSON.parse(window.localStorage.getItem("youyinGameModifiers"));
if (window.gameModifiers === null)
{
window.gameModifiers = {
extensive: false
}
saveGameModifiers();
document.location.reload();
return;
}

fixLegacyCharacterVariants();

setTitleName();
Expand Down
Loading

0 comments on commit 5e946aa

Please sign in to comment.