character rule book store

This commit is contained in:
Sirttas
2026-06-11 19:42:56 +02:00
parent 9cd0d5fb5e
commit f3cb4798d5
5 changed files with 540 additions and 55 deletions
+6 -6
View File
@@ -4,9 +4,8 @@ import {useRoute} from "vue-router";
import {computed, ref, watch, watchEffect} from "vue";
import log from "loglevel";
import {
findCharacterRuleBookByCharacterId,
RuleBook,
setCharacterRuleBookForCharacter,
useCharacterRuleBooksStore,
useRuleBooksStore
} from "@/rules";
import {storeToRefs} from "pinia";
@@ -17,6 +16,7 @@ type Bindings = { [key: string]: Ledger; };
const ruleBookStore = useRuleBooksStore();
const {findById: findRuleBookById} = ruleBookStore;
const {ruleBooks} = storeToRefs(ruleBookStore);
const {findByCharacterId, setForCharacter} = useCharacterRuleBooksStore();
const {findById: findCharacterById} = useCharactersStore();
const {ledgers} = storeToRefs(useLedgersStore());
@@ -31,11 +31,11 @@ watchEffect(async () => {
const characterId = character.value?.characterId;
if (characterId) {
const characterRuleBook = await findCharacterRuleBookByCharacterId(characterId);
const characterRuleBook = findByCharacterId(characterId);
ruleBook.value = findRuleBookById(characterRuleBook.ruleBookId);
ruleBook.value = findRuleBookById(characterRuleBook?.ruleBook.ruleBookId ?? '');
bindings.value = Object.fromEntries(
Object.entries(characterRuleBook.bindings)
Object.entries(characterRuleBook?.bindings ?? {})
.map(([key, id]) => [key, ledgersToUse.value.find(l => l.ledgerId === id) ?? systemLedger])
);
}
@@ -46,7 +46,7 @@ const save = () => {
const ruleBookId = ruleBook.value?.ruleBookId;
if (characterId && ruleBookId) {
setCharacterRuleBookForCharacter(characterId, {
setForCharacter(characterId, {
ruleBookId,
bindings: Object.fromEntries(
Object.entries(bindings.value)