feat: SodiumPet 小钠桌宠 v0.1.0(Live2D 桌宠 / 经济任务 / 音乐 / 成就 / 编辑器 / MOD)

This commit is contained in:
Tian_XiaRi
2026-12-01 16:41:07 +08:00
commit d25e726ef7
261 changed files with 33676 additions and 0 deletions
+374
View File
@@ -0,0 +1,374 @@
/** 元素周期表:等级 1~118 对应元素的基态电子排布 */
const SUBSHELLS: Array<[number, string, number]> = [
[1, 's', 2],
[2, 's', 2],
[2, 'p', 6],
[3, 's', 2],
[3, 'p', 6],
[4, 's', 2],
[3, 'd', 10],
[4, 'p', 6],
[5, 's', 2],
[4, 'd', 10],
[5, 'p', 6],
[6, 's', 2],
[4, 'f', 14],
[5, 'd', 10],
[6, 'p', 6],
[7, 's', 2],
[5, 'f', 14],
[6, 'd', 10],
[7, 'p', 6]
]
const NOBLE: Array<[number, string]> = [
[2, 'He'],
[10, 'Ne'],
[18, 'Ar'],
[36, 'Kr'],
[54, 'Xe'],
[86, 'Rn']
]
const SYMBOLS =
'H He Li Be B C N O F Ne Na Mg Al Si P S Cl Ar K Ca Sc Ti V Cr Mn Fe Co Ni Cu Zn Ga Ge As Se Br Kr Rb Sr Y Zr Nb Mo Tc Ru Rh Pd Ag Cd In Sn Sb Te I Xe Cs Ba La Ce Pr Nd Pm Sm Eu Gd Tb Dy Ho Er Tm Yb Lu Hf Ta W Re Os Ir Pt Au Hg Tl Pb Bi Po At Rn Fr Ra Ac Th Pa U Np Pu Am Cm Bk Cf Es Fm Md No Lr Rf Db Sg Bh Hs Mt Ds Rg Cn Nh Fl Mc Lv Ts Og'.split(
' '
)
/** 常见反常排布,直接写死 */
const EXCEPTIONS: Record<number, string> = {
24: '[Ar]3d5 4s1',
29: '[Ar]3d10 4s1',
41: '[Kr]4d4 5s1',
42: '[Kr]4d5 5s1',
44: '[Kr]4d7 5s1',
45: '[Kr]4d8 5s1',
46: '[Kr]4d10',
47: '[Kr]4d10 5s1',
57: '[Xe]5d1 6s2',
58: '[Xe]4f1 5d1 6s2',
64: '[Xe]4f7 5d1 6s2',
78: '[Xe]4f14 5d9 6s1',
79: '[Xe]4f14 5d10 6s1',
89: '[Rn]6d1 7s2',
90: '[Rn]6d2 7s2',
91: '[Rn]5f2 6d1 7s2',
92: '[Rn]5f3 6d1 7s2',
93: '[Rn]5f4 6d1 7s2',
96: '[Rn]5f7 6d1 7s2'
}
function fill(z: number): Array<{ n: number; l: string; e: number }> {
const out: Array<{ n: number; l: string; e: number }> = []
let left = z
for (const [n, l, cap] of SUBSHELLS) {
if (left <= 0) break
const e = Math.min(cap, left)
out.push({ n, l, e })
left -= e
}
return out
}
function configOf(z: number): string {
if (EXCEPTIONS[z]) return EXCEPTIONS[z]
let coreZ = 0
let coreSym = ''
for (const [zc, sym] of NOBLE) {
if (zc < z) {
coreZ = zc
coreSym = sym
}
}
const full = fill(z)
const core = fill(coreZ)
const parts: string[] = []
for (let i = 0; i < full.length; i++) {
const e = full[i].e - (core[i]?.e ?? 0)
if (e > 0) parts.push(`${full[i].n}${full[i].l}${e}`)
}
return coreSym ? `[${coreSym}]${parts.join(' ')}` : parts.join(' ')
}
const SUP = '⁰¹²³⁴⁵⁶⁷⁸⁹'
function sup(n: string): string {
return n
.split('')
.map((d) => SUP[Number(d)] ?? d)
.join('')
}
/** 把 4s1 写成 4s¹(只把电子数变上标) */
function superscriptConfig(cfg: string): string {
return cfg.replace(/(\d)([spdf])(\d+)/g, (_m, n: string, l: string, e: string) => `${n}${l}${sup(e)}`)
}
const BLOCK_COLOR: Record<string, string> = {
s: '#ffd54a',
p: '#6fc8ff',
d: '#8ef0b0',
f: '#cf9bff'
}
function blockOf(cfg: string): 's' | 'p' | 'd' | 'f' {
const coreOnly = /^\[[A-Za-z]{1,2}\]$/.test(cfg)
if (coreOnly) return cfg === '[He]' ? 's' : 'p'
const m = cfg.match(/(\d)([spdf])(\d+)(?![\s\S]*\d[spdf]\d)/)
const l = m?.[2]
return (l === 's' || l === 'p' || l === 'd' || l === 'f' ? l : 's') as 's' | 'p' | 'd' | 'f'
}
export interface ElementInfo {
z: number
symbol: string
config: string
configSuper: string
block: 's' | 'p' | 'd' | 'f'
color: string
}
export const ELEMENTS: ElementInfo[] = Array.from({ length: 118 }, (_, i) => {
const z = i + 1
const config = configOf(z)
const block = blockOf(config)
return {
z,
symbol: SYMBOLS[i] ?? '?',
config,
configSuper: superscriptConfig(config),
block,
color: BLOCK_COLOR[block]
}
})
export const MAX_LEVEL = ELEMENTS.length
export function elementOf(level: number): ElementInfo {
const idx = Math.min(Math.max(level, 1), MAX_LEVEL) - 1
return ELEMENTS[idx]
}
/** 卡片里的一行显示:K [Ar]4s¹ */
export function levelLabel(level: number): string {
const el = elementOf(level)
return `${el.symbol} ${el.configSuper}`
}
/** 元素中文名(按原子序数) */
export const ELEMENT_NAMES: string[] = [
'氢','氦','锂','铍','硼','碳','氮','氧','氟','氖',
'钠','镁','铝','硅','磷','硫','氯','氩','钾','钙',
'钪','钛','钒','铬','锰','铁','钴','镍','铜','锌',
'镓','锗','砷','硒','溴','氪','铷','锶','钇','锆',
'铌','钼','锝','钌','铑','钯','银','镉','铟','锡',
'锑','碲','碘','氙','铯','钡','镧','铈','镨','钕',
'钷','钐','铕','钆','铽','镝','钬','铒','铥','镱',
'镥','铪','钽','钨','铼','锇','铱','铂','金','汞',
'铊','铅','铋','钋','砹','氡','钫','镭','锕','钍',
'镤','铀','镎','钚','镅','锔','锫','锎','锿','镄',
'钔','锘','铹','𬬻','𬭊','𬭳','𬭛','𬭶','鿏','𫟼',
'𬬭','鿔','鿭','𫓧','镆','𫟷','鿬','鿫'
]
export function elementName(level: number): string {
return ELEMENT_NAMES[elementOf(level).z - 1] ?? ''
}
export interface WrappedLevelLabel {
prefix: string
symbol: string
name: string
config: string
z: number
}
/**
* 超 118 级后的循环显示:前缀带上上个周期的最大符号(118 Uuo),
* 再接 1H 1s¹ 这样的循环元素。
*/
export function levelLabelWrapped(level: number): WrappedLevelLabel {
const cycles = Math.floor((Math.max(1, level) - 1) / MAX_LEVEL)
const z = ((Math.max(1, level) - 1) % MAX_LEVEL) + 1
const el = elementOf(z)
return {
prefix: cycles > 0 ? '118 Uuo' : '',
symbol: el.symbol,
name: ELEMENT_NAMES[z - 1] ?? '',
config: el.configSuper,
z
}
}
export type ElementCategory =
| 'alkali'
| 'alkaline'
| 'transition'
| 'postmetal'
| 'metalloid'
| 'nonmetal'
| 'halogen'
| 'noble'
| 'lanthanide'
| 'actinide'
export const ELEMENT_CATEGORY_LABEL: Record<ElementCategory, string> = {
alkali: '碱金属',
alkaline: '碱土金属',
transition: '过渡金属',
postmetal: '主族金属',
metalloid: '类金属',
nonmetal: '非金属',
halogen: '卤素',
noble: '稀有气体',
lanthanide: '镧系',
actinide: '锕系'
}
export const CATEGORY_COLORS: Record<ElementCategory, string> = {
alkali: '#ff9d76',
alkaline: '#ffcf6b',
transition: '#8ee6c8',
postmetal: '#7fc7ff',
metalloid: '#b9e07a',
nonmetal: '#8fe1b0',
halogen: '#ffcf8a',
noble: '#c9a8ff',
lanthanide: '#ffb0d0',
actinide: '#f4a6a6'
}
const CATEGORY_SETS: Array<[ElementCategory, number[]]> = [
['alkali', [3, 11, 19, 37, 55, 87]],
['alkaline', [4, 12, 20, 38, 56, 88]],
['transition', [
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
72, 73, 74, 75, 76, 77, 78, 79, 80,
104, 105, 106, 107, 108, 109, 110, 111, 112
]],
['postmetal', [13, 31, 49, 50, 81, 82, 83, 84, 113, 114, 115, 116]],
['metalloid', [5, 14, 32, 33, 51, 52]],
['nonmetal', [1, 6, 7, 8, 15, 16, 34]],
['halogen', [9, 17, 35, 53, 85, 117]],
['noble', [2, 10, 18, 36, 54, 86, 118]],
['lanthanide', [57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71]],
['actinide', [89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103]]
]
export function categoryOf(z: number): ElementCategory {
for (const [cat, list] of CATEGORY_SETS) {
if (list.includes(z)) return cat
}
return 'transition'
}
/** 周期表配色方案:block = 按能级块,category = 按元素分类 */
export type PeriodicScheme = 'block' | 'category'
export interface PeriodicStyle {
scheme: PeriodicScheme
/** 自定义颜色覆盖:block 用 s/p/d/f,category 用分类 key */
colors?: Record<string, string>
/** 底图背景色 */
bg?: string
}
export const DEFAULT_PERIODIC_STYLE: PeriodicStyle = {
scheme: 'block',
colors: {},
bg: '#0e1420'
}
export function periodicCellColor(
el: { z: number; block: string },
style: PeriodicStyle
): string {
const custom = style.colors ?? {}
if (style.scheme === 'category') {
const cat = categoryOf(el.z)
return custom[cat] ?? CATEGORY_COLORS[cat]
}
return custom[el.block] ?? BLOCK_COLOR[el.block] ?? '#8b98ad'
}
export interface PeriodicPreset {
id: string
name: string
scheme: PeriodicScheme
colors: Record<string, string>
}
const SOFT_CATEGORY: Record<string, string> = {
alkali: '#ffc9b3',
alkaline: '#ffe3a3',
transition: '#d9f2e6',
postmetal: '#cfe7ff',
metalloid: '#e2f0c4',
nonmetal: '#d3f0dd',
halogen: '#ffe3bd',
noble: '#ead9ff',
lanthanide: '#ffd6e6',
actinide: '#f9d2d2'
}
export const PERIODIC_PRESETS: PeriodicPreset[] = [
{
id: 'spdf',
name: '能级块 · 标准',
scheme: 'block',
colors: { s: '#ffd54a', p: '#6fc8ff', d: '#8ef0b0', f: '#cf9bff' }
},
{
id: 'spdf-soft',
name: '能级块 · 柔和',
scheme: 'block',
colors: { s: '#ffe9a8', p: '#bfe4ff', d: '#cdf3dd', f: '#e6cbff' }
},
{
id: 'category',
name: '元素分类 · 标准',
scheme: 'category',
colors: { ...CATEGORY_COLORS }
},
{
id: 'category-soft',
name: '元素分类 · 柔和',
scheme: 'category',
colors: SOFT_CATEGORY
}
]
/** 周期表格子的 (行, 列) 位置:镧系/锕系单独成行 */
export const ELEMENT_GRID_POS: Array<[number, number]> = (() => {
const pos: Array<[number, number]> = []
const set = (z: number, row: number, col: number): void => {
pos[z - 1] = [row, col]
}
set(1, 1, 1)
set(2, 1, 18)
for (let i = 0; i < 8; i++) {
set(3 + i, 2, i < 2 ? i + 1 : i + 11)
set(11 + i, 3, i < 2 ? i + 1 : i + 11)
}
for (let i = 0; i < 18; i++) {
set(19 + i, 4, i + 1)
set(37 + i, 5, i + 1)
}
set(55, 6, 1)
set(56, 6, 2)
for (let i = 0; i < 15; i++) set(57 + i, 8, 3 + i)
for (let i = 0; i < 15; i++) set(72 + i, 6, 4 + i)
set(87, 7, 1)
set(88, 7, 2)
for (let i = 0; i < 15; i++) set(89 + i, 9, 3 + i)
for (let i = 0; i < 15; i++) set(104 + i, 7, 4 + i)
return pos
})()