Compare commits

...

18 Commits

Author SHA1 Message Date
badcold
bfab9abcb6 auto-updating gh pages 2024-06-10 18:53:57 +02:00
badcold
b7f87fc49b trying to unignore index.js in the gh-pages 2024-06-10 18:53:42 +02:00
badcold
bc481f7798 ignoring regenerate-gh-pages.sh 2024-06-10 17:55:09 +02:00
badcold
b3c3094e5c Update static.yml 2024-06-10 17:52:21 +02:00
badcold
ad9a3ae25f Create static.yml 2024-06-10 17:46:25 +02:00
badcold
5c945efeb5 ignore update script 2024-05-11 10:02:47 +02:00
badcold
d34c13dfa6 fixup contract #33 2024-05-11 10:00:10 +02:00
badcold
e32cf5b817 fixup contract #20 2024-05-11 09:57:48 +02:00
badcold
877304a19e fixup rewards for contract #29 2024-05-11 09:51:17 +02:00
badcold
9d2cf4c264 fixup contract reward name + spacing between filters 2024-04-21 10:48:35 +02:00
badcold
fea9007a01 better counts for excluded contracts 2024-04-21 10:22:43 +02:00
badcold
81313adf4c fixup data for contract #17 2024-04-21 10:22:43 +02:00
badcold
1e7ae85866 split rewards into exports and bonuses 2024-04-21 10:22:43 +02:00
badcold
f9b1507911 counting resources 2024-04-21 10:22:43 +02:00
badcold
fb1442b270 refactor header 2024-04-21 10:22:43 +02:00
badcold
e7fecb58cd allow to exclude discarded contracts from selection 2024-04-21 10:22:43 +02:00
badcold
3d14936a99 convert to ts 2024-04-21 10:22:43 +02:00
badcold
ba5973bd96 extract css and js to separated files 2024-04-21 10:22:43 +02:00
10 changed files with 1098 additions and 147 deletions

43
.github/workflows/static.yml vendored Normal file
View File

@@ -0,0 +1,43 @@
# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["gh-pages"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload entire repository
path: '.'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

5
.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
.idea
index.js
update.sh
regenerate-gh-pages.sh
!gh-pages/

View File

@@ -224,7 +224,7 @@
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 0,
"cheese": 2,
"cow": 2,
"sheep": 0,
"whisky": 0,
@@ -265,12 +265,12 @@
"sugarCane": 0,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 0,
{"costs": {"bread": 2,
"cheese": 0,
"cow": 0,
"sheep": 3,
"whisky": 0,
"wool": 2},
"wool": 0},
"id": 20,
"rewards": {"cotton": 0,
"expansion": 0,
@@ -402,8 +402,8 @@
"expansion": 0,
"gold": 5,
"hops": 2,
"sugarCane": 4,
"tobacco": 0,
"sugarCane": 0,
"tobacco": 4,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 0,
@@ -447,9 +447,9 @@
"sugarCane": 0,
"tobacco": 4,
"upgrade": 0}},
{"costs": {"bread": 0,
{"costs": {"bread": 3,
"cheese": 0,
"cow": 3,
"cow": 0,
"sheep": 1,
"whisky": 0,
"wool": 0},

702
gh-pages/contracts.json Normal file
View File

@@ -0,0 +1,702 @@
[{"costs": {"bread": 0,
"cheese": 0,
"cow": 0,
"sheep": 0,
"whisky": 0,
"wool": 4},
"id": 1,
"rewards": {"cotton": 2,
"expansion": 1,
"gold": 0,
"hops": 1,
"sugarCane": 0,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 0,
"cow": 0,
"sheep": 0,
"whisky": 0,
"wool": 6},
"id": 2,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 0,
"hops": 2,
"sugarCane": 0,
"tobacco": 3,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 0,
"cow": 2,
"sheep": 0,
"whisky": 0,
"wool": 0},
"id": 3,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 10,
"hops": 1,
"sugarCane": 2,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 0,
"cow": 3,
"sheep": 0,
"whisky": 0,
"wool": 0},
"id": 4,
"rewards": {"cotton": 3,
"expansion": 0,
"gold": 0,
"hops": 3,
"sugarCane": 0,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 0,
"cow": 0,
"sheep": 2,
"whisky": 0,
"wool": 0},
"id": 5,
"rewards": {"cotton": 0,
"expansion": 1,
"gold": 0,
"hops": 1,
"sugarCane": 0,
"tobacco": 2,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 0,
"cow": 0,
"sheep": 0,
"whisky": 0,
"wool": 3},
"id": 6,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 0,
"hops": 1,
"sugarCane": 1,
"tobacco": 0,
"upgrade": 1}},
{"costs": {"bread": 2,
"cheese": 0,
"cow": 0,
"sheep": 0,
"whisky": 0,
"wool": 0},
"id": 7,
"rewards": {"cotton": 2,
"expansion": 1,
"gold": 10,
"hops": 0,
"sugarCane": 0,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 4,
"cheese": 0,
"cow": 0,
"sheep": 0,
"whisky": 0,
"wool": 0},
"id": 8,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 5,
"hops": 1,
"sugarCane": 0,
"tobacco": 4,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 2,
"cow": 0,
"sheep": 0,
"whisky": 0,
"wool": 0},
"id": 9,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 8,
"hops": 5,
"sugarCane": 1,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 4,
"cow": 0,
"sheep": 0,
"whisky": 0,
"wool": 0},
"id": 10,
"rewards": {"cotton": 4,
"expansion": 0,
"gold": 10,
"hops": 0,
"sugarCane": 0,
"tobacco": 0,
"upgrade": 2}},
{"costs": {"bread": 0,
"cheese": 0,
"cow": 0,
"sheep": 0,
"whisky": 2,
"wool": 0},
"id": 11,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 10,
"hops": 1,
"sugarCane": 0,
"tobacco": 2,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 0,
"cow": 0,
"sheep": 0,
"whisky": 4,
"wool": 0},
"id": 12,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 0,
"hops": 3,
"sugarCane": 4,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 3,
"cow": 0,
"sheep": 0,
"whisky": 0,
"wool": 1},
"id": 13,
"rewards": {"cotton": 3,
"expansion": 0,
"gold": 0,
"hops": 3,
"sugarCane": 0,
"tobacco": 0,
"upgrade": 1}},
{"costs": {"bread": 0,
"cheese": 0,
"cow": 0,
"sheep": 1,
"whisky": 0,
"wool": 1},
"id": 14,
"rewards": {"cotton": 0,
"expansion": 1,
"gold": 0,
"hops": 3,
"sugarCane": 0,
"tobacco": 1,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 0,
"cow": 0,
"sheep": 0,
"whisky": 4,
"wool": 1},
"id": 15,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 15,
"hops": 3,
"sugarCane": 4,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 0,
"cow": 1,
"sheep": 0,
"whisky": 0,
"wool": 1},
"id": 16,
"rewards": {"cotton": 2,
"expansion": 0,
"gold": 0,
"hops": 0,
"sugarCane": 0,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 2,
"cow": 2,
"sheep": 0,
"whisky": 0,
"wool": 0},
"id": 17,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 0,
"hops": 2,
"sugarCane": 0,
"tobacco": 4,
"upgrade": 0}},
{"costs": {"bread": 1,
"cheese": 0,
"cow": 3,
"sheep": 0,
"whisky": 0,
"wool": 0},
"id": 18,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 10,
"hops": 0,
"sugarCane": 4,
"tobacco": 0,
"upgrade": 2}},
{"costs": {"bread": 0,
"cheese": 1,
"cow": 0,
"sheep": 1,
"whisky": 0,
"wool": 0},
"id": 19,
"rewards": {"cotton": 2,
"expansion": 1,
"gold": 10,
"hops": 0,
"sugarCane": 0,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 2,
"cheese": 0,
"cow": 0,
"sheep": 3,
"whisky": 0,
"wool": 0},
"id": 20,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 0,
"hops": 5,
"sugarCane": 0,
"tobacco": 4,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 0,
"cow": 0,
"sheep": 2,
"whisky": 1,
"wool": 0},
"id": 21,
"rewards": {"cotton": 0,
"expansion": 1,
"gold": 0,
"hops": 1,
"sugarCane": 3,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 3,
"cheese": 1,
"cow": 0,
"sheep": 0,
"whisky": 0,
"wool": 0},
"id": 22,
"rewards": {"cotton": 4,
"expansion": 0,
"gold": 5,
"hops": 1,
"sugarCane": 0,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 1,
"cheese": 0,
"cow": 0,
"sheep": 0,
"whisky": 1,
"wool": 0},
"id": 23,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 15,
"hops": 8,
"sugarCane": 0,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 2,
"cheese": 0,
"cow": 0,
"sheep": 0,
"whisky": 0,
"wool": 1},
"id": 24,
"rewards": {"cotton": 0,
"expansion": 1,
"gold": 0,
"hops": 3,
"sugarCane": 2,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 2,
"cheese": 1,
"cow": 0,
"sheep": 0,
"whisky": 0,
"wool": 0},
"id": 25,
"rewards": {"cotton": 3,
"expansion": 1,
"gold": 0,
"hops": 1,
"sugarCane": 0,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 2,
"cow": 0,
"sheep": 2,
"whisky": 0,
"wool": 0},
"id": 26,
"rewards": {"cotton": 0,
"expansion": 1,
"gold": 0,
"hops": 9,
"sugarCane": 0,
"tobacco": 2,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 2,
"cow": 0,
"sheep": 1,
"whisky": 0,
"wool": 0},
"id": 27,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 0,
"hops": 1,
"sugarCane": 3,
"tobacco": 0,
"upgrade": 1}},
{"costs": {"bread": 2,
"cheese": 0,
"cow": 0,
"sheep": 0,
"whisky": 1,
"wool": 0},
"id": 28,
"rewards": {"cotton": 3,
"expansion": 0,
"gold": 0,
"hops": 2,
"sugarCane": 0,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 1,
"cow": 0,
"sheep": 0,
"whisky": 3,
"wool": 0},
"id": 29,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 5,
"hops": 2,
"sugarCane": 0,
"tobacco": 4,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 0,
"cow": 0,
"sheep": 0,
"whisky": 2,
"wool": 1},
"id": 30,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 3,
"hops": 4,
"sugarCane": 2,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 3,
"cow": 0,
"sheep": 0,
"whisky": 0,
"wool": 3},
"id": 31,
"rewards": {"cotton": 4,
"expansion": 0,
"gold": 15,
"hops": 2,
"sugarCane": 0,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 0,
"cow": 2,
"sheep": 0,
"whisky": 2,
"wool": 0},
"id": 32,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 5,
"hops": 2,
"sugarCane": 0,
"tobacco": 4,
"upgrade": 0}},
{"costs": {"bread": 3,
"cheese": 0,
"cow": 0,
"sheep": 1,
"whisky": 0,
"wool": 0},
"id": 33,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 0,
"hops": 2,
"sugarCane": 4,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 1,
"cheese": 3,
"cow": 0,
"sheep": 0,
"whisky": 0,
"wool": 0},
"id": 34,
"rewards": {"cotton": 4,
"expansion": 0,
"gold": 0,
"hops": 2,
"sugarCane": 0,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 0,
"cow": 0,
"sheep": 0,
"whisky": 1,
"wool": 3},
"id": 35,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 0,
"hops": 0,
"sugarCane": 0,
"tobacco": 3,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 1,
"cow": 1,
"sheep": 0,
"whisky": 2,
"wool": 0},
"id": 36,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 5,
"hops": 2,
"sugarCane": 4,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 2,
"cheese": 1,
"cow": 1,
"sheep": 0,
"whisky": 0,
"wool": 0},
"id": 37,
"rewards": {"cotton": 4,
"expansion": 1,
"gold": 0,
"hops": 2,
"sugarCane": 0,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 3,
"cheese": 0,
"cow": 1,
"sheep": 0,
"whisky": 0,
"wool": 1},
"id": 38,
"rewards": {"cotton": 0,
"expansion": 1,
"gold": 0,
"hops": 3,
"sugarCane": 0,
"tobacco": 4,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 1,
"cow": 0,
"sheep": 0,
"whisky": 1,
"wool": 2},
"id": 39,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 10,
"hops": 1,
"sugarCane": 3,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 0,
"cow": 0,
"sheep": 1,
"whisky": 3,
"wool": 1},
"id": 40,
"rewards": {"cotton": 4,
"expansion": 0,
"gold": 0,
"hops": 5,
"sugarCane": 0,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 0,
"cow": 0,
"sheep": 1,
"whisky": 2,
"wool": 1},
"id": 41,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 3,
"hops": 0,
"sugarCane": 0,
"tobacco": 4,
"upgrade": 0}},
{"costs": {"bread": 0,
"cheese": 1,
"cow": 0,
"sheep": 0,
"whisky": 1,
"wool": 2},
"id": 42,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 0,
"hops": 7,
"sugarCane": 2,
"tobacco": 0,
"upgrade": 1}},
{"costs": {"bread": 1,
"cheese": 0,
"cow": 1,
"sheep": 0,
"whisky": 1,
"wool": 0},
"id": 43,
"rewards": {"cotton": 3,
"expansion": 0,
"gold": 0,
"hops": 3,
"sugarCane": 0,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 1,
"cheese": 0,
"cow": 0,
"sheep": 0,
"whisky": 1,
"wool": 1},
"id": 44,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 0,
"hops": 4,
"sugarCane": 0,
"tobacco": 2,
"upgrade": 0}},
{"costs": {"bread": 1,
"cheese": 1,
"cow": 0,
"sheep": 0,
"whisky": 0,
"wool": 2},
"id": 45,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 10,
"hops": 0,
"sugarCane": 3,
"tobacco": 0,
"upgrade": 1}},
{"costs": {"bread": 0,
"cheese": 0,
"cow": 1,
"sheep": 1,
"whisky": 0,
"wool": 2},
"id": 46,
"rewards": {"cotton": 3,
"expansion": 0,
"gold": 0,
"hops": 1,
"sugarCane": 0,
"tobacco": 0,
"upgrade": 1}},
{"costs": {"bread": 0,
"cheese": 1,
"cow": 0,
"sheep": 1,
"whisky": 0,
"wool": 2},
"id": 47,
"rewards": {"cotton": 0,
"expansion": 1,
"gold": 0,
"hops": 1,
"sugarCane": 0,
"tobacco": 3,
"upgrade": 0}},
{"costs": {"bread": 1,
"cheese": 1,
"cow": 0,
"sheep": 0,
"whisky": 0,
"wool": 1},
"id": 48,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 0,
"hops": 0,
"sugarCane": 3,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 2,
"cheese": 0,
"cow": 0,
"sheep": 1,
"whisky": 1,
"wool": 0},
"id": 49,
"rewards": {"cotton": 3,
"expansion": 1,
"gold": 0,
"hops": 5,
"sugarCane": 0,
"tobacco": 0,
"upgrade": 0}},
{"costs": {"bread": 1,
"cheese": 1,
"cow": 0,
"sheep": 0,
"whisky": 1,
"wool": 0},
"id": 50,
"rewards": {"cotton": 0,
"expansion": 0,
"gold": 10,
"hops": 0,
"sugarCane": 0,
"tobacco": 3,
"upgrade": 2}}]

BIN
gh-pages/contracts.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 KiB

26
gh-pages/index.html Normal file
View File

@@ -0,0 +1,26 @@
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<title>ClansOfContracts</title>
<link rel="stylesheet" href="style.css">
</head>
<body onload="init()">
<script src="index.js"></script>
<div id="header"></div>
<div id="included">
</div>
<hr style="clear: left;height:5px;border-width:0;color:gray;background-color:darkgoldenrod"/>
<div id="excluded">
</div>
<script>
</script>
</body>
</html>

36
gh-pages/style.css Normal file
View File

@@ -0,0 +1,36 @@
.filters {
font-size: x-large;
input {
width: 20px;
height: 20px;
}
}
.filterElement {
margin: 15px;
}
.contract {
margin: 5px;
float: left;
color: red;
font-size: 14em;
line-height: 194px;
text-align: center;
user-select: none;
width: 194px;
height: 194px;
background-image: url('contracts.webp');
background-size: 9894px 194px;
}
html {
color: #222;
font-size: 1em;
line-height: 1.4;
background-color: palegoldenrod;
}

View File

@@ -4,143 +4,13 @@
<head>
<meta charset="utf-8">
<title>ClansOfContracts</title>
<style>
.filters {
font-size: x-large;
input {
width: 20px;
height: 20px;
}
}
.contract {
margin: 5px;
float: left;
color: red;
font-size: 14em;
line-height: 194px;
text-align: center;
user-select: none;
width: 194px;
height: 194px;
background-image: url('contracts.webp');
background-size: 9894px 194px;
}
html {
color: #222;
font-size: 1em;
line-height: 1.4;
background-color: palegoldenrod;
}
</style>
<link rel="stylesheet" href="style.css">
</head>
<body onload="init()">
<script>
let contracts;
<script src="index.js"></script>
let costs=["sheep", "cow", "wool", "bread", "cheese", "whisky"]
let rewards=["cotton", "tobacco", "sugarCane", "upgrade", "expansion", "gold", "hops"]
function init() {
fetch('contracts.json')
.then(response => response.json())
.then(json => {
contracts = json;
for (contract of contracts) {
contract.discarded = false;
}
update();
})
.catch(error => console.error('Error:', error));
for (cost of costs) {
checkBox = document.getElementById(cost);
checkBox.addEventListener('change', function() {
update();
});
}
for (reward of rewards) {
checkBox = document.getElementById(reward);
checkBox.addEventListener('change', function() {
update();
});
}
}
function update() {
let includedContracts = "";
let excludedContracts = "";
for (contract of contracts) {
if (isIncluded(contract)) {
includedContracts += generateContractHtml(contract);
} else {
excludedContracts += generateContractHtml(contract);
}
}
document.getElementById("included").innerHTML = includedContracts;
document.getElementById("excluded").innerHTML = excludedContracts;
}
function isIncluded(contract) {
let included = true;
for (cost of costs) {
checkBox = document.getElementById(cost);
if (!checkBox.checked && (contract.costs[cost] > 0)) {
included = false;
}
}
for (reward of rewards) {
checkBox = document.getElementById(reward);
if (!checkBox.checked && (contract.rewards[reward] > 0)) {
included = false;
}
}
return included;
}
function generateContractHtml(contract) {
let position = -(contract.id * 194);
if (contract.discarded) {
return "<div id=\"" + contract.id + "\" onclick=\"toggleDiscard(" + contract.id + ")\" class=\"contract\" style=\"background-position: "+position+"px 194px;\">X</div>";
} else {
return "<div id=\"" + contract.id + "\" onclick=\"toggleDiscard(" + contract.id + ")\" class=\"contract\" style=\"background-position: "+position+"px 194px;\"> </div>";
}
}
function toggleDiscard(id) {
for (contract of contracts) {
if (contract.id === id) {
contract.discarded = !contract.discarded;
}
}
update();
}
</script>
<div id="costs" class="filters">
<span>Costs:</span>
<input id="sheep" type="checkbox" checked="checked"/><label for="sheep">Sheep</label>
<input id="cow" type="checkbox" checked="checked"/><label for="cow">Cow</label>
<input id="wool" type="checkbox" checked="checked"/><label for="wool">Wool</label>
<input id="bread" type="checkbox" checked="checked"/><label for="bread">Bread</label>
<input id="cheese" type="checkbox" checked="checked"/><label for="cheese">Cheese</label>
<input id="whisky" type="checkbox" checked="checked"/><label for="whisky">Whisky</label>
</div>
<div id="rewards" class="filters">
<span>Rewards:</span>
<input id="cotton" type="checkbox" checked="checked"/><label for="cotton">Cotton</label>
<input id="tobacco" type="checkbox" checked="checked"/><label for="tobacco">Tobacco</label>
<input id="sugarCane" type="checkbox" checked="checked"/><label for="sugarCane">Sugar cane</label>
<input id="upgrade" type="checkbox" checked="checked"/><label for="upgrade">Upgrade</label>
<input id="expansion" type="checkbox" checked="checked"/><label for="expansion">Expansion</label>
<input id="gold" type="checkbox" checked="checked"/><label for="gold">Gold</label>
<input id="hops" type="checkbox" checked="checked"/><label for="hops">Hops</label>
</div>
<div id="header"></div>
<div id="included">
</div>

233
index.ts Normal file
View File

@@ -0,0 +1,233 @@
let contracts;
let costs = ["sheep", "cow", "wool", "bread", "cheese", "whisky"]
let rewards = ["cotton", "tobacco", "sugarCane", "upgrade", "expansion", "gold", "hops"]
let imports = ["cotton", "tobacco", "sugarCane"]
let bonuses = ["upgrade", "expansion", "gold", "hops"]
function init() {
buildHeader();
fetch('contracts.json')
.then(response => response.json())
.then(json => {
contracts = json;
for (const contract of contracts) {
contract.discarded = false;
}
update();
})
.catch(error => console.error('Error:', error));
for (const cost of costs) {
let checkBox = document.getElementById(cost);
checkBox.addEventListener('change', function () {
update();
});
}
for (const reward of rewards) {
let checkBox = document.getElementById(reward);
checkBox.addEventListener('change', function () {
update();
});
}
let otherCheckBox = document.getElementById("discarded");
otherCheckBox.addEventListener('change', function () {
update();
});
}
function buildHeader() {
document.getElementById("header").innerHTML = `
<div id="costs" class="filters">
<button type="button" id="costsNone" onclick="setAllCostsCheckboxes(false)">None</button>
<button type="button" id="costsAll" onclick="setAllCostsCheckboxes(true)">All</button>
<span>Costs:</span>
${buildCheckBoxes(costs)}
</div>
<div id="imports" class="filters">
<button type="button" id="rewardsNone" onclick="setAllImportsCheckboxes(false)">None</button>
<button type="button" id="rewardsAll" onclick="setAllImportsCheckboxes(true)">All</button>
<span>Imports:</span>
${buildCheckBoxes(imports)}
</div>
<div id="bonuses" class="filters">
<button type="button" id="bonusesNone" onclick="setAllBonusesCheckboxes(false)">None</button>
<button type="button" id="bonusesAll" onclick="setAllBonusesCheckboxes(true)">All</button>
<span>Bonus:</span>
${buildCheckBoxes(bonuses)}
</div>
<div id="other" class="filters">
<span>Other:</span>
${buildCheckBoxes(["discarded"])}
</div>
`;
}
function setAllCostsCheckboxes(value: boolean) {
for (const filter of costs) {
let checkBox = document.getElementById(filter) as HTMLInputElement;
checkBox.checked = value;
}
update();
}
function setAllImportsCheckboxes(value: boolean) {
for (const filter of imports) {
let checkBox = document.getElementById(filter) as HTMLInputElement;
checkBox.checked = value;
}
update();
}
function setAllBonusesCheckboxes(value: boolean) {
for (const filter of bonuses) {
let checkBox = document.getElementById(filter) as HTMLInputElement;
checkBox.checked = value;
}
update();
}
function buildCheckBoxes(filters: string[]): string {
let result = "";
for (const filter of filters) {
result += buildCheckBox(filter);
}
return result;
}
function buildCheckBox(filterKey: string): string {
let capitalized = filterKey[0].toUpperCase() + filterKey.slice(1);
return `<span class="filterElement"><input id="${filterKey}" type="checkbox" checked="checked"/>
<label for="${filterKey}">${capitalized}</label>
<span id="${filterKey}Count"></span></span>`;
}
function update() {
let includedContracts = [];
let excludedContracts = [];
for (const contract of contracts) {
if (isIncluded(contract, "")) {
includedContracts.push(contract);
} else {
excludedContracts.push(contract);
}
}
for (const filter of costs) {
let checkBox = document.getElementById(filter) as HTMLInputElement;
if (checkBox.checked) {
setIncludedFilterCounts(includedContracts, "costs", filter);
} else {
setExcludedFilterCounts(excludedContracts, "costs", filter);
}
}
for (const filter of rewards) {
let checkBox = document.getElementById(filter) as HTMLInputElement;
if (checkBox.checked) {
setIncludedFilterCounts(includedContracts, "rewards", filter);
} else {
setExcludedFilterCounts(excludedContracts, "rewards", filter);
}
}
setDirectFilterCounts(contracts, "discarded");
let includedContractsHtml = "";
for (const included of includedContracts) {
includedContractsHtml += generateContractHtml(included);
}
document.getElementById("included").innerHTML = includedContractsHtml;
let excludedContractsHtml = "";
for (const excluded of excludedContracts) {
excludedContractsHtml += generateContractHtml(excluded);
}
document.getElementById("excluded").innerHTML = excludedContractsHtml;
}
function setIncludedFilterCounts(contracts: any[], subcategory: string, filterKey: string) {
let count: number = 0;
let sum: number = 0;
for (const contract of contracts) {
let value = contract[subcategory][filterKey];
sum += value
if (value > 0) {
count += 1
}
}
document.getElementById(filterKey + "Count").innerHTML = `(${sum} on ${count})`;
}
function setExcludedFilterCounts(contracts: any[], subcategory: string, filterKey: string) {
let count: number = 0;
let sum: number = 0;
for (const contract of contracts) {
if (isIncluded(contract, filterKey)) {
let value = contract[subcategory][filterKey];
sum += value
if (value > 0) {
count += 1
}
}
}
document.getElementById(filterKey + "Count").innerHTML = `(+${sum} on ${count})`;
}
function setDirectFilterCounts(contracts, filter: string) {
let count: number = 0;
for (const contract of contracts) {
if (contract[filter]) {
count += 1;
}
}
document.getElementById("discardedCount").innerHTML = `(${count})`;
}
function isIncluded(contract, ignoredCriteria: string) {
let included = true;
for (const cost of costs) {
if (cost == ignoredCriteria) {
continue;
}
let checkBox = document.getElementById(cost) as HTMLInputElement;
if (!checkBox.checked && (contract.costs[cost] > 0)) {
included = false;
}
}
for (const reward of rewards) {
if (reward == ignoredCriteria) {
continue;
}
let checkBox = document.getElementById(reward) as HTMLInputElement;
if (!checkBox.checked && (contract.rewards[reward] > 0)) {
included = false;
}
}
if ("discarded" != ignoredCriteria
&& !(document.getElementById("discarded") as HTMLInputElement).checked
&& contract.discarded) {
included = false;
}
return included;
}
function generateContractHtml(contract) {
let position = -(contract.id * 194);
if (contract.discarded) {
return "<div id=\"" + contract.id + "\" onclick=\"toggleDiscard(" + contract.id + ")\" class=\"contract\" style=\"background-position: " + position + "px 194px;\">X</div>";
} else {
return "<div id=\"" + contract.id + "\" onclick=\"toggleDiscard(" + contract.id + ")\" class=\"contract\" style=\"background-position: " + position + "px 194px;\"> </div>";
}
}
function toggleDiscard(id) {
for (const contract of contracts) {
if (contract.id === id) {
contract.discarded = !contract.discarded;
}
}
update();
}

36
style.css Normal file
View File

@@ -0,0 +1,36 @@
.filters {
font-size: x-large;
input {
width: 20px;
height: 20px;
}
}
.filterElement {
margin: 15px;
}
.contract {
margin: 5px;
float: left;
color: red;
font-size: 14em;
line-height: 194px;
text-align: center;
user-select: none;
width: 194px;
height: 194px;
background-image: url('contracts.webp');
background-size: 9894px 194px;
}
html {
color: #222;
font-size: 1em;
line-height: 1.4;
background-color: palegoldenrod;
}