Skip to content

Commit

Permalink
Cleaned up code a bit. Function checkEntries() still sucks though.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matriks404 committed Jan 26, 2024
1 parent 1ecdd60 commit 66ac5a6
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 98 deletions.
3 changes: 1 addition & 2 deletions scss/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ $color-migratable: #006c00;
$color-obtainable-by-block-transmutation: #0047ab;
$color-obtainable-by-notch: #eaee57;
$color-obtainable-in-winter-mode: #00f3f3;
$color-removed: #006c00;

// High contrast style variables
$high-contrast-background-color: white;
$high-contrast-ui-elements-color: black;

$color-unobtainable-hc: red;
$color-removed-hc: #009700;
$color-migratable-hc: #009700;
18 changes: 4 additions & 14 deletions scss/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ p {
color: $color-default-message;
}

#info-removed {
display: none;

color: $color-removed;
}

#info-obtainable-by-block-transmutation {
display: none;

Expand Down Expand Up @@ -275,10 +269,6 @@ p {
color: $color-obtainable-in-winter-mode;
}

.id-removed {
color: $color-removed;
}

.id-unobtainable {
color: $color-unobtainable;
}
Expand Down Expand Up @@ -342,8 +332,8 @@ p {
color: $high-contrast-ui-elements-color;
}

#info-removed {
color: $color-removed-hc;
#info-migratable {
color: $color-migratable-hc;
}

#info-unobtainable {
Expand All @@ -354,8 +344,8 @@ p {
border: 2px solid $high-contrast-ui-elements-color;
}

.id-removed {
color: $color-removed-hc;
.id-migratable {
color: $color-migratable-hc;
}

.id-unobtainable {
Expand Down
5 changes: 0 additions & 5 deletions site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@
<p>Data values colored in light blue cannot be legitimately obtained,</p>
<p>unless player plays on "Winter Mode" map type.</p>
</div>

<div id="info-removed">
<p>Data values colored in green are removed from the game,</p>
<p>but still available with cheats/server commands.</p>
</div>
</div>
</div>

Expand Down
152 changes: 75 additions & 77 deletions site/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ var loadedVersionGroupId = "";
var loadedVersionId = "";
var areSettingsUpdated = false;

var excludeCheckboxes = [
'exclude-migratable',
'exclude-obtainable-by-block-transmutation',
'exclude-obtainable-by-notch',
'exclude-obtainable-in-winter-mode',
];

function fetchJSONData(filename) {
return fetch(filename)
.then(function (res) {
Expand Down Expand Up @@ -168,8 +175,6 @@ function loadEntries(entries, el, entriesName, hasUnknownIds) {
idElement.className += ' id-obtainable-by-notch';
} else if (entry.isObtainableInWinterMode) {
idElement.className += ' id-obtainable-in-winter-mode';
} else if (entry.isRemoved) {
idElement.className += ' id-removed';
}

var idString;
Expand Down Expand Up @@ -262,12 +267,39 @@ function doEntriesContainEntryType(entries, type) {
});
}

function checkEntries(entries, el, type) {
if (doEntriesContainEntryType(entries, type)) {
el.style.display = "block";
} else {
el.style.display = "none";
}
function checkEntries(blocks, items) {
var entries = [blocks, items];

var checks = [
{id: 'unobtainable', property: 'isUnobtainable'},
{id: 'migratable', property: 'isObtainableByMigration'},
{id: 'obtainable-by-block-transmutation', property: 'isObtainableByBlockTransmutation'},
{id: 'obtainable-by-notch', property: 'isObtainableByNotch'},
{id: 'obtainable-in-winter-mode', property: 'isObtainableInWinterMode'}
];

checks.forEach(function (check) {
check.infoEl = document.getElementById('info-' + check.id);
check.infoEl.style.display = "none";

check.excludeEl = document.getElementById('exclude-' + check.id);
});

entries.forEach(function (entries) {
checks.forEach(function (check) {
if (check.infoEl.style.display == "block") {
return;
}

var checked = check.excludeEl.checked;

if (doEntriesContainEntryType(entries, check.property)) {
check.infoEl.style.display = "block";
} else {
check.infoEl.style.display = "none";
}
});
});
}

function loadCurrentVersion() {
Expand Down Expand Up @@ -312,12 +344,18 @@ function loadCurrentVersion() {
var info = document.getElementById('info');
info.style.display = "flex";

checkVersionProperty('info-needs-testing', version, 'needsTesting');
checkVersionProperty('info-early-classic', version, 'isEarlyClassic');
checkVersionProperty('info-no-official-tooltip-names', version, 'hasNoOfficialTooltipNames')
checkVersionProperty('info-unknown-renders', version, 'hasUnknownRenders');
checkVersionProperty('info-unknown-block-ids', version, 'hasUnknownBlockIds');
checkVersionProperty('info-unknown-item-ids', version, 'hasUnknownItemIds');
var properties = [
['info-needs-testing', 'needsTesting'],
['info-early-classic', 'isEarlyClassic'],
['info-no-official-tooltip-names', 'hasNoOfficialTooltipNames'],
['info-unknown-renders', 'hasUnknownRenders'],
['info-unknown-block-ids', 'hasUnknownBlockIds'],
['info-unknown-item-ids', 'hasUnknownItemIds']
];

properties.forEach(function (property) {
checkVersionProperty(property[0], version, property[1]);
});

var containerElement = document.getElementById('container');
var oldMainElement = document.getElementsByTagName('main')[0];
Expand All @@ -341,20 +379,6 @@ function loadCurrentVersion() {
blocksElement.appendChild(blocksContentElement);
blocksContentElement.className = 'fieldset-content';

var infoUnobtainableElement = document.getElementById('info-unobtainable');
var infoMigratableElement = document.getElementById('info-migratable');
var infoObtainableByBlockTransmutationElement = document.getElementById('info-obtainable-by-block-transmutation');
var infoObtainableByNotchElement = document.getElementById('info-obtainable-by-notch');
var infoObtainableInWinterModeElement = document.getElementById('info-obtainable-in-winter-mode');
var infoRemovedElement = document.getElementById('info-removed');

checkEntries(blocks, infoUnobtainableElement, "isUnobtainable");
checkEntries(blocks, infoMigratableElement, "isObtainableByMigration");
checkEntries(blocks, infoObtainableByBlockTransmutationElement, "isObtainableByBlockTransmutation");
checkEntries(blocks, infoObtainableByNotchElement, "isObtainableByNotch");
checkEntries(blocks, infoObtainableInWinterModeElement, "isObtainableInWinterMode");
checkEntries(blocks, infoRemovedElement, "isRemoved");

loadEntries(blocks, blocksContentElement, "blocks", version.hasUnknownBlockIds);

var items = version.items;
Expand All @@ -372,26 +396,6 @@ function loadCurrentVersion() {
itemsElement.appendChild(itemsContentElement);
itemsContentElement.className = 'fieldset-content';

if (infoUnobtainableElement.style.display == "none") {
checkEntries(items, infoUnobtainableElement, "isUnobtainable");
}

if (infoMigratableElement.style.display == "none") {
checkEntries(items, infoMigratableElement, "isObtainableByMigration");
}

if (infoObtainableByNotchElement.style.display == "none") {
checkEntries(items, infoObtainableByNotchElement, "isObtainableByNotch");
}

if (infoObtainableInWinterModeElement.style.display == "none") {
checkEntries(items, infoObtainableInWinterModeElement, "isObtainableInWinterMode");
}

if (infoRemovedElement.style.display == "none") {
checkEntries(items, infoRemovedElement, "isRemoved");
}

loadEntries(items, itemsContentElement, "items", version.hasUnknownItemIds);
}

Expand Down Expand Up @@ -420,6 +424,8 @@ function loadCurrentVersion() {
tooltip.style.top = y;
});
});

checkEntries(version.blocks, version.items);
}

function reloadCheckboxes() {
Expand Down Expand Up @@ -487,44 +493,36 @@ document.addEventListener('DOMContentLoaded', function () {
document.getElementById('version-groups').addEventListener('change', loadVersionList);
document.getElementById('ok').addEventListener('click', loadCurrentVersion);

var displayAirBlockCheckbox = document.getElementById('display-air-block');

document.getElementById('exclude-unobtainable').addEventListener('change', function () {
updateSettingsStatus();

var excludeUnobtainable = document.getElementById('exclude-unobtainable').checked;
var excludeMigratableCheckbox = document.getElementById('exclude-migratable');
var excludeObtainableByBlockTransmutationCheckbox = document.getElementById('exclude-obtainable-by-block-transmutation');
var excludeObtainableByNotchCheckbox = document.getElementById('exclude-obtainable-by-notch');
var excludeObtainableInWinterModeCheckbox = document.getElementById('exclude-obtainable-in-winter-mode');
var displayAirCheckbox = document.getElementById('display-air-block');
var excludeUnobtainable = this.checked;

if (excludeUnobtainable) {
excludeMigratableCheckbox.disabled = "";
excludeObtainableByBlockTransmutationCheckbox.disabled = "";
excludeObtainableByNotchCheckbox.disabled = "";
excludeObtainableInWinterModeCheckbox.disabled = "";
excludeCheckboxes.forEach(function (checkboxId) {
var checkbox = document.getElementById(checkboxId);

displayAirCheckbox.checked = false;
displayAirCheckbox.disabled = "disabled";
} else {
excludeMigratableCheckbox.checked = false;
excludeMigratableCheckbox.disabled = "disabled";
checkbox.disabled = !excludeUnobtainable;

excludeObtainableByBlockTransmutationCheckbox.checked = false;
excludeObtainableByBlockTransmutationCheckbox.disabled = "disabled";
if (!excludeUnobtainable) {
checkbox.checked = false;
}
});

excludeObtainableByNotchCheckbox.checked = false;
excludeObtainableByNotchCheckbox.disabled = "disabled";
if (excludeUnobtainable) {
displayAirBlockCheckbox.disabled = "disabled"
displayAirBlockCheckbox.checked = false;
} else {
displayAirBlockCheckbox.disabled = "";
}
});

excludeObtainableInWinterModeCheckbox.checked = false;
excludeObtainableInWinterModeCheckbox.disabled = "disabled";
excludeCheckboxes.forEach(function (checkboxId) {
var checkbox = document.getElementById(checkboxId);

displayAirCheckbox.disabled = "";
}
checkbox.addEventListener('change', updateSettingsStatus);
});

document.getElementById('exclude-migratable').addEventListener('change', updateSettingsStatus);
document.getElementById('exclude-obtainable-by-block-transmutation').addEventListener('change', updateSettingsStatus);
document.getElementById('exclude-obtainable-by-notch').addEventListener('change', updateSettingsStatus);
document.getElementById('exclude-obtainable-in-winter-mode').addEventListener('change', updateSettingsStatus);
document.getElementById('display-air-block').addEventListener('change', updateSettingsStatus);
displayAirBlockCheckbox.addEventListener('change', updateSettingsStatus);
});

0 comments on commit 66ac5a6

Please sign in to comment.