Skip to content

Commit

Permalink
[coc-card] 修复成功率模式显示 bug,并且保存切换结果
Browse files Browse the repository at this point in the history
  • Loading branch information
masquevil committed May 17, 2024
1 parent f0d87cc commit 91dc38b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
13 changes: 11 additions & 2 deletions src/pages/coc-card/AppView.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { reactive, provide, ref } from 'vue';
import { reactive, provide, ref, watch } from 'vue';
import qs from 'qs';
import { createPC } from './models/character';
Expand All @@ -12,20 +12,29 @@ import type { PageData } from './types/pageData';
import useDerives from './hooks/useDerives';
import useSuggestion from './hooks/useSuggestion';
import useAutoSave from './hooks/useAutoSave';
import useAppLs from './hooks/useAppLs';
import ControlSection from './sections/ControlSection.vue';
import PaperFront from './PaperFront.vue';
import PaperBack from './PaperBack.vue';
const qsObject = qs.parse(location.search.slice(1));
const pcRef = ref<COCPlayerCharacter>(createPC());
const ls = useAppLs();
const viewData = reactive<COCCardViewData>(createViewData(qsObject));
const pageData = reactive<PageData>({
printing: qsObject.debug === 'true',
showTotalSeparation: qsObject.sep === 'true',
showTotalSeparation: qsObject.sep === 'true' || ls.getItem('showTotalSeparation') || false,
});
const paperInFront = ref(qsObject.turn === 'back' ? false : true);
watch(
() => pageData.showTotalSeparation,
(value) => {
ls.setItem('showTotalSeparation', value);
},
);
useDerives(pcRef);
const suggestion = useSuggestion(pcRef, viewData);
Expand Down
45 changes: 18 additions & 27 deletions src/pages/coc-card/components/SkillTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ interface TableRowData {
}
function getTableData(data: SkillGroups, suggestion?: Suggestion) {
const tableData = data.reduce<TableRowData[]>(
(result: any, skillGroup: SkillGroup) => {
const rows: TableRowData[] = skillGroup.groupSkills.reduce<
TableRowData[]
>((rows, skill, index) => {
const tableData = data.reduce<TableRowData[]>((result: any, skillGroup: SkillGroup) => {
const rows: TableRowData[] = skillGroup.groupSkills.reduce<TableRowData[]>(
(rows, skill, index) => {
const isSpecialGroup = skillGroup.groupName === '特殊';
let init = skill.init;
if (pc && skill.name in dynamicInitFormulas) {
Expand All @@ -62,8 +60,7 @@ function getTableData(data: SkillGroups, suggestion?: Suggestion) {
const points = skillPoint?.[1] || {};
// 信用评级范围
const [w0, w1] = suggestion?.wealth ?? [-1, -1];
const comments =
skillKey === '信用评级' && w0 >= 0 && w1 >= 0 ? `(${w0}~${w1})` : '';
const comments = skillKey === '信用评级' && w0 >= 0 && w1 >= 0 ? `(${w0}~${w1})` : '';
const total = getTotal(points, init);
let rowData: TableRowData = {
key: skill.name,
Expand All @@ -89,25 +86,18 @@ function getTableData(data: SkillGroups, suggestion?: Suggestion) {
// multi skill rows
if (skill.group) {
const length = skill.group.show.length;
const groupRow =
resultRows.find((row) => row.isGroupStart) || rowData;
const groupRow = resultRows.find((row) => row.isGroupStart) || rowData;
// increase groupSize
groupRow.groupSize! += length - 1;
added = skill.group.show.map((placeName, childIndex) => {
const childSkillName =
viewData?.showingChildSkills.get(skill.name)?.[childIndex] ??
placeName;
const childSkill = skill.group?.skills.find(
({ name }) => name === childSkillName,
);
viewData?.showingChildSkills.get(skill.name)?.[childIndex] ?? placeName;
const childSkill = skill.group?.skills.find(({ name }) => name === childSkillName);
let init = childSkill?.init ?? rowData.init;
const skillKey: COCPCSkill = [
skill.name,
childSkillName,
childIndex,
];
const skillKey: COCPCSkill = [skill.name, childSkillName, childIndex];
const skillPoint = findSkillPoints(skillKey);
const points = skillPoint?.[1] || {};
const total = getTotal(points, init);
if (pc && !skill.name) {
init = points.b || 0;
}
Expand All @@ -120,7 +110,8 @@ function getTableData(data: SkillGroups, suggestion?: Suggestion) {
skillKey,
init,
points,
total: getTotal(points, init),
total,
totalSeparation: [total, ~~(total / 2), ~~(total / 5)],
// child skill info
childSkillData: {
name: childSkillName,
Expand All @@ -131,15 +122,16 @@ function getTableData(data: SkillGroups, suggestion?: Suggestion) {
});
}
return [...resultRows, ...added];
}, []);
return [...result, ...rows];
},
[],
);
},
[],
);
return [...result, ...rows];
}, []);
return tableData;
}
const tableData = computed(() => getTableData(props.data, props.suggestion));
console.log('xxx tableData', tableData);
function findSkillPoints(skillInfo: COCPCSkill) {
if (!pc) return;
Expand All @@ -162,8 +154,7 @@ function updateSkillPoint(
if (!pc) return;
let skillPoint = findSkillPoints(skillKey);
if (!skillPoint) {
const key =
typeof skillKey === 'string' ? skillKey : ([...skillKey] as COCPCSkill);
const key = typeof skillKey === 'string' ? skillKey : ([...skillKey] as COCPCSkill);
skillPoint = [key, {}];
pc.value.skillPoints.push(skillPoint);
}
Expand Down
1 change: 1 addition & 0 deletions src/pages/coc-card/hooks/useAppLs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { LSApp } from '@/types/ls';
import type { COCPlayerCharacter } from '../types/character';

interface Store {
showTotalSeparation?: boolean;
autoSaved?: {
pc: COCPlayerCharacter;
lastModified: number; // number of date
Expand Down

0 comments on commit 91dc38b

Please sign in to comment.