Skip to content

Commit 901bd8c

Browse files
committed
Fix build state recognition
1 parent b37adb1 commit 901bd8c

File tree

2 files changed

+71
-19
lines changed

2 files changed

+71
-19
lines changed

src/presets/artifact-builds/[GGArtifact] 全角色配装 AllCharacterBuilds.json

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"version": 5,
3-
"id": "export-1772547607436",
3+
"id": "export-1772547805080",
44
"author": "GGArtifact",
55
"description": "全角色配装 AllCharacterBuilds",
66
"builds": {
@@ -3445,6 +3445,39 @@
34453445
"roles": ["support"],
34463446
"source": "preset"
34473447
},
3448+
"37JY26m": {
3449+
"id": "37JY26m",
3450+
"name": "",
3451+
"visible": false,
3452+
"composition": "4pc",
3453+
"sands": ["em"],
3454+
"goblet": ["em"],
3455+
"circlet": ["em", "cr"],
3456+
"substats": [
3457+
{
3458+
"stat": "em",
3459+
"weight": 100
3460+
},
3461+
{
3462+
"stat": "cr",
3463+
"weight": 100
3464+
},
3465+
{
3466+
"stat": "cd",
3467+
"weight": 100
3468+
},
3469+
{
3470+
"stat": "er",
3471+
"weight": 50
3472+
}
3473+
],
3474+
"artifactSet": "viridescent_venerer",
3475+
"characterId": "kaedehara_kazuha",
3476+
"styles": ["on-field"],
3477+
"roles": ["dps"],
3478+
"source": "preset",
3479+
"minCons": 6
3480+
},
34483481
"xcrqdu": {
34493482
"id": "xcrqdu",
34503483
"name": "",
@@ -4830,7 +4863,7 @@
48304863
"yun_jin": ["e-eIXm", "dnM9om", "e-gCcG"],
48314864
"yoimiya": ["2FRItMu", "2FRCOKO"],
48324865
"kamisato_ayaka": ["4aRtNc0", "4aRxcbm"],
4833-
"kaedehara_kazuha": ["37JY4fG"],
4866+
"kaedehara_kazuha": ["37JY4fG", "37JY26m"],
48344867
"eula": ["xcrqdu"],
48354868
"diona": ["6KCVIaG"],
48364869
"yanfei": ["3PxdDeO"],

src/stores/useBuildsStore.ts

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -252,28 +252,13 @@ export const useBuildsStore = create<BuildsState>()(
252252
setBuild: (buildId: string, patch: Partial<Build>, baseBuild?: Build) => {
253253
set((state) => {
254254
let targetBuild = state.builds[buildId];
255+
let isNew = false;
255256

256257
if (!targetBuild) {
257258
if (baseBuild) {
258259
// Copy-on-Write: Initialize with baseBuild + patch
259260
targetBuild = { ...baseBuild, ...patch };
260-
261-
// Ensure it's tracked in the character list (Union survival)
262-
const charId = targetBuild.characterId;
263-
if (!state.characterToBuildIds[charId]) {
264-
// Initialize from preset ordering so other builds aren't lost
265-
const preset = getCachedPreset(state.activePresetId);
266-
const presetIds = preset?.characterBuilds?.[charId];
267-
state.characterToBuildIds[charId] = presetIds
268-
? [...presetIds]
269-
: [];
270-
}
271-
if (!state.characterToBuildIds[charId].includes(buildId)) {
272-
state.characterToBuildIds[charId].push(buildId);
273-
}
274-
275-
// Proceed to register it
276-
state.builds[buildId] = targetBuild;
261+
isNew = true;
277262
} else {
278263
console.warn(
279264
`Build ${buildId} not found and no baseBuild provided`
@@ -298,6 +283,40 @@ export const useBuildsStore = create<BuildsState>()(
298283
// Ensure id and characterId cannot be changed
299284
targetBuild.id = buildId; // Enforce ID consistency
300285

286+
// Check if the result still matches the preset version (no-op guard).
287+
// This prevents marking a build as "modified" when no actual data changed
288+
// (e.g. clicking the name input without typing, or editing back to original).
289+
const preset = getCachedPreset(state.activePresetId);
290+
const presetBuild = preset?.builds[buildId];
291+
if (presetBuild && areBuildsEqual(targetBuild, presetBuild)) {
292+
if (isNew) {
293+
// No actual change from preset — skip copy-on-write entirely
294+
return;
295+
}
296+
// User reverted all changes — auto-revert by removing local override
297+
delete state.builds[buildId];
298+
delete state.validationErrors[buildId];
299+
return;
300+
}
301+
302+
if (isNew) {
303+
// Ensure it's tracked in the character list (Union survival)
304+
const charId = targetBuild.characterId;
305+
if (!state.characterToBuildIds[charId]) {
306+
// Initialize from preset ordering so other builds aren't lost
307+
const presetIds = preset?.characterBuilds?.[charId];
308+
state.characterToBuildIds[charId] = presetIds
309+
? [...presetIds]
310+
: [];
311+
}
312+
if (!state.characterToBuildIds[charId].includes(buildId)) {
313+
state.characterToBuildIds[charId].push(buildId);
314+
}
315+
316+
// Register the new local override
317+
state.builds[buildId] = targetBuild;
318+
}
319+
301320
// Re-validate
302321
state.validationErrors[buildId] =
303322
getBuildValidationErrors(targetBuild);

0 commit comments

Comments
 (0)