character rule book store
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user