Skip to content

Commit

Permalink
Selection Limit
Browse files Browse the repository at this point in the history
  • Loading branch information
ltouroumov committed Sep 3, 2023
1 parent 4dbfa8e commit 95994fe
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/viewer/ViewScoreStatus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class="d-flex flex-row gap-2"
>
<span v-if="score.beforeText">{{ score.beforeText }}</span>
<span>{{ value }}</span>
<span>{{ -value }}</span>
<span v-if="score.afterText">{{ score.afterText }}</span>
</span>
</div>
Expand Down
1 change: 1 addition & 0 deletions composables/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type ProjectRow = HasId &
objectWidth: string;

resultGroupId: string;
allowedChoices: number;

objects: ProjectObj[];
};
Expand Down
24 changes: 22 additions & 2 deletions composables/store/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,26 @@ export const useProjectStore = defineStore('project', () => {

const setSelected = (id: string, isSelected: boolean) => {
if (isSelected) {
selected.value = R.append(id, selected.value);
const rowId = getObjectRow.value(id);
const row = getRow.value(rowId);
if (row.allowedChoices > 0) {
const selectedRowObjects = R.intersection(
selected.value,
R.map(R.prop('id'), row.objects),
);

if (selectedRowObjects.length >= row.allowedChoices) {
const toDeselect = selectedRowObjects[0];
selected.value = R.pipe(
R.without([toDeselect]),
R.append(id),
)(selected.value);
} else {
selected.value = R.append(id, selected.value);
}
} else {
selected.value = R.append(id, selected.value);
}
} else {
selected.value = R.without([id], selected.value);
}
Expand All @@ -106,7 +125,7 @@ export const useProjectStore = defineStore('project', () => {
}),
R.map(({ id, value }: Score): [string, number] => [
id,
-Number.parseInt(value),
Number.parseInt(value),
]),
)(scores);
}),
Expand All @@ -115,6 +134,7 @@ export const useProjectStore = defineStore('project', () => {
0,
([id, _]) => id,
),
R.mergeWith(R.add, startingSums),
)(_selected);
});

Expand Down
2 changes: 1 addition & 1 deletion pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div v-if="isLoaded" id="container">
<div v-if="!isLoaded" id="container">
<div id="dialog">
<LoadProject />
</div>
Expand Down
8 changes: 8 additions & 0 deletions pages/viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
Worm V6 (Lt's Fork)
</a>
</li>
<li class="list-group-item">
<a
href="https://raw.githubusercontent.com/ltouroumov/worm-cyoa-v6-fork/master/xenon.json"
@click.prevent="loadRemoteFile"
>
Xenon (WIP)
</a>
</li>
</ul>

<div
Expand Down

0 comments on commit 95994fe

Please sign in to comment.