| 1 | |
| 2 | |
| 3 | import type { Plugin } from 'vite'; |
| 4 | |
| 5 | export function upstreamFixes(): Plugin { |
| 6 | return { |
| 7 | name: 'shoal-sanguosha-rules-fixes', |
| 8 | enforce: 'pre', |
| 9 | transform(code, id) { |
| 10 | if (id.endsWith('/src/engine/rules/身份局.ts')) { |
| 11 | const before = 'if (aliveRenegade) return { gameOver: true, winner: aliveRenegade.index };'; |
| 12 | if (!code.includes(before)) throw new Error('The pinned identity rule changed; review the Shoal rule fix.'); |
| 13 | return code.replace(before, 'if (aliveRenegade && state.players.filter((p) => p.alive).length === 1) return { gameOver: true, winner: aliveRenegade.index };'); |
| 14 | } |
| 15 | if (id.endsWith('/src/engine/core/skill.ts')) { |
| 16 | const before = ' if (state.pendingSlots.size === 1) {'; |
| 17 | if (!code.includes(before)) throw new Error('The pinned pending-slot lookup changed; review the extra-phase fix.'); |
| 18 | |
| 19 | |
| 20 | return code.replace(before, ' if (direct && !direct.isPaused && !direct.isBlocking) return direct;\n' + before); |
| 21 | } |
| 22 | if (id.endsWith('/src/engine/view/buildView.ts')) { |
| 23 | const before = 'atom: slot.atom,\n prompt: { type: \'confirm\', title: \'等待回应\', cancelLabel: \'\' },'; |
| 24 | if (!code.includes(before)) throw new Error('The pinned observer view changed; review the private-prompt fix.'); |
| 25 | code = code.replace(before, "atom: { type: slot.atom.type, target, ...('requestType' in slot.atom ? { requestType: slot.atom.requestType } : {}) },\n prompt: { type: 'confirm', title: '等待回应', cancelLabel: '' },"); |
| 26 | const priority = 'const ownOrBroadcastSlot = ownSlot && !ownSlot.isPaused ? ownSlot : broadcastSlot;'; |
| 27 | if (!code.includes(priority)) throw new Error('The pinned pending priority changed; review the broadcast fix.'); |
| 28 | |
| 29 | |
| 30 | |
| 31 | return code.replace(priority, 'const ownOrBroadcastSlot = ownSlot && !ownSlot.isPaused && ownSlot.isBlocking ? ownSlot : broadcastSlot ?? (ownSlot && !ownSlot.isPaused ? ownSlot : undefined);'); |
| 32 | } |
| 33 | return null; |
| 34 | }, |
| 35 | }; |
| 36 | } |