Refactor character affiliations to singular form
- Updated character data structure to replace 'affiliations' and 'frAffiliations' with 'affiliation' and 'frAffiliation'. - Modified related functions and components to accommodate the new structure. - Adjusted database schema and server-side logic to reflect the changes in character affiliation handling. - Ensured all references in the UI components and data import/export scripts are updated accordingly.
This commit is contained in:
8
drizzle/0003_mixed_ben_grimm.sql
Normal file
8
drizzle/0003_mixed_ben_grimm.sql
Normal file
@@ -0,0 +1,8 @@
|
||||
ALTER TABLE `character` ADD `affiliation` text;--> statement-breakpoint
|
||||
ALTER TABLE `character` ADD `fr_affiliation` text;--> statement-breakpoint
|
||||
ALTER TABLE `character` DROP COLUMN `affiliations`;--> statement-breakpoint
|
||||
ALTER TABLE `character` DROP COLUMN `fr_affiliations`;--> statement-breakpoint
|
||||
ALTER TABLE `character_scrape_validation` ADD `affiliation` text;--> statement-breakpoint
|
||||
ALTER TABLE `character_scrape_validation` ADD `fr_affiliation` text;--> statement-breakpoint
|
||||
ALTER TABLE `character_scrape_validation` DROP COLUMN `affiliations`;--> statement-breakpoint
|
||||
ALTER TABLE `character_scrape_validation` DROP COLUMN `fr_affiliations`;
|
||||
1185
drizzle/meta/0003_snapshot.json
Normal file
1185
drizzle/meta/0003_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -22,6 +22,13 @@
|
||||
"when": 1775950314114,
|
||||
"tag": "0002_old_earthquake",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 3,
|
||||
"version": "6",
|
||||
"when": 1776195681488,
|
||||
"tag": "0003_mixed_ben_grimm",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -28,8 +28,8 @@ type CharacterRecord = {
|
||||
frName?: string | null;
|
||||
gender?: string | null;
|
||||
age?: number | null;
|
||||
affiliations?: string[] | string | null;
|
||||
frAffiliations?: string[] | string | null;
|
||||
affiliation?: string | null;
|
||||
frAffiliation?: string | null;
|
||||
devilFruitId?: string | null;
|
||||
hakiObservation?: boolean;
|
||||
hakiArmament?: boolean;
|
||||
@@ -123,8 +123,8 @@ function transformCharacterData(item: CharacterRecord) {
|
||||
frName: toNullable(item.frName),
|
||||
gender: toNullable(item.gender),
|
||||
age: toNullable(item.age),
|
||||
affiliations: toJsonArray(item.affiliations),
|
||||
frAffiliations: toJsonArray(item.frAffiliations),
|
||||
affiliation: toNullable(item.affiliation),
|
||||
frAffiliation: toNullable(item.frAffiliation),
|
||||
devilFruitId: toNullable(item.devilFruitId),
|
||||
hakiObservation: !!item.hakiObservation,
|
||||
hakiArmament: !!item.hakiArmament,
|
||||
@@ -369,8 +369,8 @@ async function importFromJson(): Promise<void> {
|
||||
frName: row.frName,
|
||||
gender: row.gender,
|
||||
age: row.age,
|
||||
affiliations: row.affiliations,
|
||||
frAffiliations: row.frAffiliations,
|
||||
affiliation: row.affiliation,
|
||||
frAffiliation: row.frAffiliation,
|
||||
devilFruitId: row.devilFruitId,
|
||||
hakiObservation: row.hakiObservation,
|
||||
hakiArmament: row.hakiArmament,
|
||||
|
||||
@@ -23,8 +23,8 @@ interface Character {
|
||||
frOrigin: string | null;
|
||||
devilFruitId: string | null;
|
||||
devilFruitUrl: string | null;
|
||||
affiliations: string[];
|
||||
frAffiliations: string[] | null;
|
||||
affiliation: string | null;
|
||||
frAffiliation: string | null;
|
||||
bounty: number | null;
|
||||
hakiObservation: boolean;
|
||||
hakiArmament: boolean;
|
||||
@@ -370,7 +370,7 @@ async function fetchAllCharacters(arcsList: Arc[]): Promise<Character[]> {
|
||||
Age: data.age,
|
||||
Status: data.status,
|
||||
Epithets: data.epithets.join(', '),
|
||||
Affiliations: data.affiliations.join(', '),
|
||||
Affiliation: data.affiliation,
|
||||
DevilFruitId: data.devilFruitId,
|
||||
DevilFruitUrl: data.devilFruitUrl,
|
||||
HakiObservation: data.hakiObservation ? 'Yes' : 'No',
|
||||
@@ -453,8 +453,8 @@ async function fetchCharacter(
|
||||
// Extract age
|
||||
const age = extractAge($);
|
||||
|
||||
// Extract affiliations
|
||||
const affiliations = await extractAffiliations($, 'en');
|
||||
// Extract affiliation
|
||||
const affiliation = await extractAffiliations($, 'en');
|
||||
|
||||
// Extract epithets
|
||||
const epithets = extractEpithets($);
|
||||
@@ -513,7 +513,7 @@ async function fetchCharacter(
|
||||
|
||||
let frName = frjsonData?.parse?.title || null;
|
||||
|
||||
const frAffiliations = frjsonData
|
||||
const frAffiliation = frjsonData
|
||||
? await extractAffiliations(cheerio.load(frjsonData.parse?.text?.['*'] || ''), 'fr')
|
||||
: null;
|
||||
|
||||
@@ -542,8 +542,8 @@ async function fetchCharacter(
|
||||
frOrigin,
|
||||
devilFruitId,
|
||||
devilFruitUrl,
|
||||
affiliations,
|
||||
frAffiliations,
|
||||
affiliation,
|
||||
frAffiliation,
|
||||
bounty,
|
||||
hakiObservation,
|
||||
hakiArmament,
|
||||
@@ -591,15 +591,15 @@ function extractAge($: cheerio.CheerioAPI): number | null {
|
||||
/**
|
||||
* Extract affiliations from infobox
|
||||
*/
|
||||
async function extractAffiliations($: cheerio.CheerioAPI, lang: string): Promise<string[]> {
|
||||
async function extractAffiliations($: cheerio.CheerioAPI, lang: string): Promise<string | null> {
|
||||
const div = $('[data-source="affiliation"] .pi-data-value');
|
||||
if (div.length === 0) return [];
|
||||
if (div.length === 0) return null;
|
||||
|
||||
const cleanedDiv = div.clone();
|
||||
cleanedDiv.find('sup').remove();
|
||||
|
||||
const text = cleanedDiv.html();
|
||||
if (!text) return [];
|
||||
if (!text) return null;
|
||||
|
||||
// Resolve affiliations from linked page titles.
|
||||
const links = cleanedDiv.find('a').toArray();
|
||||
@@ -624,14 +624,14 @@ async function extractAffiliations($: cheerio.CheerioAPI, lang: string): Promise
|
||||
|
||||
const uniqueLinks = Array.from(new Set(linkValues.filter(Boolean)));
|
||||
if (uniqueLinks.length > 0) {
|
||||
return uniqueLinks;
|
||||
return uniqueLinks[0];
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to parsing text
|
||||
const cleanText = text.replace(/<[^>]*>/g, '').trim();
|
||||
const parts = cleanText.split(/\s*\n\s*|\s*;\s*|\s*,\s*/).filter(Boolean);
|
||||
return parts.length > 0 ? parts : [];
|
||||
return parts.length > 0 ? parts[0] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -869,9 +869,8 @@ async function saveToCSV(characters: Character[]): Promise<void> {
|
||||
status: c.status || '',
|
||||
epithets: Array.isArray(c.epithets) ? c.epithets.join(', ') : c.epithets || '',
|
||||
devilFruitId: c.devilFruitId || '',
|
||||
affiliations: Array.isArray(c.affiliations)
|
||||
? c.affiliations.join(', ')
|
||||
: c.affiliations || '',
|
||||
affiliation: c.affiliation || '',
|
||||
frAffiliation: c.frAffiliation || '',
|
||||
bounty: c.bounty ?? 0,
|
||||
hakiObservation: c.hakiObservation ? 1 : 0,
|
||||
hakiArmament: c.hakiArmament ? 1 : 0,
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
export let columnVisibility: {
|
||||
status?: boolean;
|
||||
gender?: boolean;
|
||||
affiliations?: boolean;
|
||||
affiliation?: boolean;
|
||||
devilFruitType?: boolean;
|
||||
haki?: boolean;
|
||||
bounty?: boolean;
|
||||
@@ -18,52 +18,6 @@
|
||||
arc?: boolean;
|
||||
};
|
||||
|
||||
function normalizeAffiliations(value: unknown): string[] {
|
||||
if (Array.isArray(value)) {
|
||||
return value
|
||||
.map((entry) => (typeof entry === 'string' ? entry.trim() : ''))
|
||||
.filter((entry) => entry.length > 0);
|
||||
}
|
||||
|
||||
if (typeof value === 'string') {
|
||||
const trimmed = value.trim();
|
||||
if (trimmed.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (trimmed.startsWith('[')) {
|
||||
try {
|
||||
const parsed = JSON.parse(trimmed);
|
||||
if (Array.isArray(parsed)) {
|
||||
return parsed
|
||||
.map((entry) => (typeof entry === 'string' ? entry.trim() : ''))
|
||||
.filter((entry) => entry.length > 0);
|
||||
}
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
return trimmed
|
||||
.split(',')
|
||||
.map((entry) => entry.trim())
|
||||
.filter((entry) => entry.length > 0);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
function firstAffiliation(value: unknown): string | null {
|
||||
const affiliations = normalizeAffiliations(value);
|
||||
return affiliations.length > 0 ? affiliations[0] : null;
|
||||
}
|
||||
|
||||
function hasMatchingPrimaryAffiliation(characterAffiliations: unknown, dailyAffiliations: unknown): boolean {
|
||||
const characterPrimary = firstAffiliation(characterAffiliations);
|
||||
const dailyPrimary = firstAffiliation(dailyAffiliations);
|
||||
return characterPrimary === dailyPrimary;
|
||||
}
|
||||
|
||||
$: isFrench = $language === 'fr';
|
||||
|
||||
function getDisplayName(character: CharacterWithRelations): string {
|
||||
@@ -106,6 +60,14 @@
|
||||
return character.arcName;
|
||||
}
|
||||
|
||||
function getDislayAffiliation(character: CharacterWithRelations): string | null {
|
||||
if (isFrench && typeof character.frAffiliation === 'string' && character.frAffiliation.length > 0) {
|
||||
return character.frAffiliation;
|
||||
}
|
||||
|
||||
return character.affiliation;
|
||||
}
|
||||
|
||||
function hasMatchingArc(characterEntry: CharacterWithRelations, dailyEntry: CharacterWithRelations): boolean {
|
||||
return getDisplayArcName(characterEntry) === getDisplayArcName(dailyEntry);
|
||||
}
|
||||
@@ -156,7 +118,7 @@
|
||||
</p>
|
||||
</div>
|
||||
{/if}
|
||||
{#if columnVisibility.affiliations !== false}
|
||||
{#if columnVisibility.affiliation !== false}
|
||||
<div
|
||||
class="flex w-16 shrink-0 items-center justify-center rounded-lg border border-amber-200/30 bg-amber-900/30 p-1 text-center sm:w-20 sm:p-2 md:w-24"
|
||||
>
|
||||
@@ -319,23 +281,15 @@
|
||||
{/if}
|
||||
|
||||
<!-- Affiliations -->
|
||||
{#if columnVisibility.affiliations !== false}
|
||||
{#if columnVisibility.affiliation !== false}
|
||||
<div
|
||||
class="h-16 w-16 shrink-0 rounded-lg border border-white/10 sm:h-20 sm:w-20 md:h-24 md:w-24 {hasMatchingPrimaryAffiliation(character.affiliations, dailyCharacter.affiliations)
|
||||
class="h-16 w-16 shrink-0 rounded-lg border border-white/10 sm:h-20 sm:w-20 md:h-24 md:w-24 {getDislayAffiliation(character) === getDislayAffiliation(dailyCharacter)
|
||||
? 'bg-emerald-600/90'
|
||||
: 'bg-red-900/60'} flex items-center justify-center overflow-hidden p-1 sm:p-2"
|
||||
: 'bg-red-900/60'} flex items-center justify-center p-1 sm:p-2"
|
||||
>
|
||||
{#if firstAffiliation(character.affiliations)}
|
||||
<p
|
||||
class="w-full text-center text-[10px] leading-tight font-bold wrap-break-word whitespace-normal text-white sm:text-xs md:text-sm"
|
||||
>
|
||||
{firstAffiliation(character.affiliations)}
|
||||
</p>
|
||||
{:else}
|
||||
<p class="text-center text-xs font-bold text-slate-400 sm:text-sm md:text-base">
|
||||
-
|
||||
</p>
|
||||
{/if}
|
||||
<p class="text-center text-[10px] font-bold text-white sm:text-xs md:text-sm">
|
||||
{getDislayAffiliation(character) || $t.game.components.guessHistory.unknown}
|
||||
</p>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
||||
@@ -86,10 +86,7 @@
|
||||
>
|
||||
<p class="text-sm font-medium text-amber-100">{$t.game.components.hints.affiliation}</p>
|
||||
{#if showHintAffiliation}
|
||||
{@const affiliations = typeof dailyCharacter.affiliations === 'string'
|
||||
? ((dailyCharacter.affiliations as string).includes('[') ? JSON.parse(dailyCharacter.affiliations) : (dailyCharacter.affiliations as string).split(',').map((a: string) => a.trim()))
|
||||
: dailyCharacter.affiliations}
|
||||
<p class="mt-2 text-xs text-white font-semibold">{Array.isArray(affiliations) ? affiliations[0] : affiliations || $t.game.components.hints.unknown}</p>
|
||||
<p class="mt-2 text-xs text-white font-semibold">{isFrench && dailyCharacter.frAffiliation ? dailyCharacter.frAffiliation : dailyCharacter.affiliation || $t.game.components.hints.unknown}</p>
|
||||
{:else if Math.max(0, 15 - selectedCharacters.length) > 0}
|
||||
<p class="mt-2 text-xs text-slate-400">{Math.max(0, 15 - selectedCharacters.length)} {$t.game.components.hints.beforeUnlock}</p>
|
||||
{:else}
|
||||
|
||||
@@ -11,8 +11,8 @@ const characterWithRelationsSelect = {
|
||||
frName: character.frName,
|
||||
gender: character.gender,
|
||||
age: character.age,
|
||||
affiliations: character.affiliations,
|
||||
frAffiliations: character.frAffiliations,
|
||||
affiliation: character.affiliation,
|
||||
frAffiliation: character.frAffiliation,
|
||||
devilFruitId: character.devilFruitId,
|
||||
devilFruitName: devilFruit.name,
|
||||
devilFruitType: devilFruit.type,
|
||||
|
||||
@@ -43,8 +43,8 @@ export const character = sqliteTable('character', {
|
||||
frName: text('fr_name'),
|
||||
gender: text('gender'),
|
||||
age: integer('age'),
|
||||
affiliations: text('affiliations', { mode: 'json' }).$type<string[]>(),
|
||||
frAffiliations: text('fr_affiliations', { mode: 'json' }).$type<string[]>(),
|
||||
affiliation: text('affiliation'),
|
||||
frAffiliation: text('fr_affiliation'),
|
||||
devilFruitId: text('devil_fruit_id').references(() => devilFruit.id),
|
||||
hakiObservation: integer('haki_observation', { mode: 'boolean' }).default(false),
|
||||
hakiArmament: integer('haki_armament', { mode: 'boolean' }).default(false),
|
||||
@@ -73,8 +73,8 @@ export const characterScrapeValidation = sqliteTable('character_scrape_validatio
|
||||
frName: text('fr_name'),
|
||||
gender: text('gender'),
|
||||
age: integer('age'),
|
||||
affiliations: text('affiliations', { mode: 'json' }).$type<string[]>(),
|
||||
frAffiliations: text('fr_affiliations', { mode: 'json' }).$type<string[]>(),
|
||||
affiliation: text('affiliation'),
|
||||
frAffiliation: text('fr_affiliation'),
|
||||
devilFruitId: text('devil_fruit_id').references(() => devilFruit.id, { onDelete: 'set null' }),
|
||||
hakiObservation: integer('haki_observation', { mode: 'boolean' }).default(false),
|
||||
hakiArmament: integer('haki_armament', { mode: 'boolean' }).default(false),
|
||||
|
||||
@@ -34,7 +34,8 @@ async function applyCharacterChangeFromScrapeValidation(characterId: string): Pr
|
||||
frName: scraped.frName,
|
||||
gender: scraped.gender,
|
||||
age: scraped.age,
|
||||
affiliations: scraped.affiliations,
|
||||
affiliation: scraped.affiliation,
|
||||
frAffiliation: scraped.frAffiliation,
|
||||
devilFruitId: scraped.devilFruitId,
|
||||
hakiObservation: scraped.hakiObservation,
|
||||
hakiArmament: scraped.hakiArmament,
|
||||
@@ -59,7 +60,8 @@ async function applyCharacterChangeFromScrapeValidation(characterId: string): Pr
|
||||
frName: scraped.frName,
|
||||
gender: scraped.gender,
|
||||
age: scraped.age,
|
||||
affiliations: scraped.affiliations,
|
||||
affiliation: scraped.affiliation,
|
||||
frAffiliation: scraped.frAffiliation,
|
||||
devilFruitId: scraped.devilFruitId,
|
||||
hakiObservation: scraped.hakiObservation,
|
||||
hakiArmament: scraped.hakiArmament,
|
||||
@@ -129,7 +131,8 @@ export async function load() {
|
||||
'frName',
|
||||
'gender',
|
||||
'age',
|
||||
'affiliations',
|
||||
'affiliation',
|
||||
'frAffiliation',
|
||||
'devilFruitId',
|
||||
'hakiObservation',
|
||||
'hakiArmament',
|
||||
|
||||
@@ -26,7 +26,7 @@ export const load: PageServerLoad = async () => {
|
||||
name: character.name,
|
||||
gender: character.gender,
|
||||
age: character.age,
|
||||
affiliations: normalizeArray(character.affiliations),
|
||||
affiliation: character.affiliation,
|
||||
devilFruitId: character.devilFruitId,
|
||||
hakiObservation: character.hakiObservation,
|
||||
hakiArmament: character.hakiArmament,
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
bounty: 0,
|
||||
height: 0,
|
||||
origin: '',
|
||||
affiliations: '',
|
||||
affiliation: '',
|
||||
epithets: '',
|
||||
pictureUrl: '',
|
||||
url: '',
|
||||
@@ -101,7 +101,7 @@
|
||||
bounty: override.bounty ?? null,
|
||||
height: override.height ?? null,
|
||||
origin: override.origin ?? '',
|
||||
affiliations: override.affiliations ?? '',
|
||||
affiliation: override.affiliation ?? '',
|
||||
epithets: override.epithets ?? '',
|
||||
pictureUrl: override.pictureUrl ?? '',
|
||||
url: override.url ?? '',
|
||||
@@ -127,7 +127,7 @@
|
||||
bounty: 0,
|
||||
height: 0,
|
||||
origin: '',
|
||||
affiliations: '',
|
||||
affiliation: '',
|
||||
epithets: '',
|
||||
pictureUrl: '',
|
||||
url: '',
|
||||
@@ -341,12 +341,8 @@
|
||||
<td class="px-4 py-4 text-sm text-gray-400">{char.gender || '-'}</td>
|
||||
<!-- Affiliations -->
|
||||
<td class="px-4 py-4 text-sm text-gray-400">
|
||||
{#if char.affiliations}
|
||||
{#if Array.isArray(char.affiliations) && char.affiliations.length > 0}
|
||||
<span class="inline-block" title={char.affiliations.join(', ')}>{char.affiliations[0]}</span>
|
||||
{:else}
|
||||
{char.affiliations}
|
||||
{/if}
|
||||
{#if char.affiliation}
|
||||
{char.affiliation}
|
||||
{:else}
|
||||
-
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user