You've already forked AstralRinth
forked from didirus/AstralRinth
* chore: typo fix and formatting tidyups * refactor(theseus): extend auth subsystem to fetch complete user profiles * chore: fix new `prettier` lints * chore: document differences between similar `Credentials` methods * chore: remove dead `profile_run_credentials` plugin command * feat(app): skin selector backend * enh(app/skin-selector): better DB intension through deferred FKs, further PNG validations * chore: fix comment typo spotted by Copilot * fix: less racy auth token refresh logic This may help with issues reported by users where the access token is invalid and can't be used to join servers over long periods of time. * tweak(app-lib): improve consistency of skin field serialization case * fix(app-lib/minecraft_skins): fix custom skin removal from DB not working * Begin skins frontend * Cape preview * feat: start on SkinPreviewRenderer * feat: setting for nametag * feat: hide nametag setting (sql) * fix: positioning of meshes * fix: lighting * fix: allow dragging off-bounds * fix: better color mapping * feat: hide nametag setting (impl) * feat: Start on edit modal + cape button cleanup + renderer fixes * feat: Finish new skin modal * feat: finish cape modal * feat: skin rendering on load * fix: logic for Skins.vue * fix: types * fix: types (for modal + renderer) * feat: Editing? * fix: renderer not updating variant * fix: mojang username not modrinth username * feat: batched skin rendering - remove vzge references (apart from capes, wip) * feat: fix sizing on SkinButton and SkinLikeButton, also implement bust positioning * feat: capes in preview renderer & baked renders * fix: lint fixes * refactor: Start on cleanup and polish * fix: hide error notification when logged out * revert: .gltf formatting * chore(app-frontend): fix typos * fix(app-lib): delay account skin data deletion to next reboot This gives users an opportunity to not unexpectedly lose skin data in case they log off on accident. * fix: login button & provide/inject AccountsCard * polish: skin buttons * fix: imports * polish: use figma values * polish: tweak underneath shadow * polish: cursor grab * polish: remove green bg from CapeLikeTextButton when selected. * polish: modal tweaks * polish: grid tweaks + start on upload skin modal * polish: drag and drop file flow * polish: button positioning in SkinButton * fix: lint issues * polish: deduplicate model+cape stuff and fix layout * fix: lint issues * fix: camel case requirement for make-default * polish: use indexed db to persist skin previews * fix: lint issues * polish: add skin icon sizing * polish: theme fixes * feat: animation system for skin preview renderer * feat(app/minecraft_skins): save current custom external skin when equipping skins * fix: cape button & dynamic nametag sizing * feat(theseus): add `normalize_skin_texture` Tauri command This command lets the app frontend opt in to normalizing the texture of any skin, which may be in either the legacy 64x32 or newer 64x64 format, to the newer 64x64 format for display purposes. * chore: Rust build fixes * feat: start impl of skin normalization on frontend * feat(theseus): change parameter type of `normalize_skin_texture` Tauri command * fix: normalization * fix(theseus): make new `normalize_skin_texture` command usable * feat: finish normalization impl * fix: vueuse issue * fix: use optimistic approach when changing skins/capes. * fix: nametag cleanup + scroll fix * fix: edit modal computedAsync not fast enough for skin preview renderer * feat: classic player model animations * chore: fix new Clippy lint * fix(app-lib): actually delete custom skins with no cape overrides * fix(app-lib): handle repeated addition of the same skin properly * refactor(app-lib): simplify DB connection logic a little * fix: various improvements * feat: slim animations * fix: z-fighting on models * fix: shading + lighting improvements * fix: shadows * fix: polish * fix: polish * fix: accounts card not having the right head * fix: lint issues * fix: build issue * feat: drag and drop func * fix: temp disable drag and drop in the modal * Revert "fix: temp disable drag and drop in the modal" This reverts commit 33500c564e3f85e6c0a2e83dd9700deda892004d. * fix: drag and drop working * fix: lint * fix: better media queries * feat(app/skins): revert current custom external skin storing on equip This reverts commit 0155262ddd081c8677654619a09e814088fdd8b0. * regen pnpm lock * pnpm fix * Make default capes a little more clear * Lint --------- Co-authored-by: Alejandro González <me@alegon.dev> Co-authored-by: Prospector <prospectordev@gmail.com>
164 lines
4.4 KiB
TypeScript
164 lines
4.4 KiB
TypeScript
import { invoke } from '@tauri-apps/api/core'
|
|
import { handleError } from '@/store/notifications'
|
|
import { arrayBufferToBase64 } from '@modrinth/utils'
|
|
|
|
export interface Cape {
|
|
id: string
|
|
name: string
|
|
texture: string
|
|
is_default: boolean
|
|
is_equipped: boolean
|
|
}
|
|
|
|
export type SkinModel = 'CLASSIC' | 'SLIM' | 'UNKNOWN'
|
|
export type SkinSource = 'default' | 'custom_external' | 'custom'
|
|
|
|
export interface Skin {
|
|
texture_key: string
|
|
name?: string
|
|
variant: SkinModel
|
|
cape_id?: string
|
|
texture: string
|
|
source: SkinSource
|
|
is_equipped: boolean
|
|
}
|
|
|
|
export const DEFAULT_MODEL_SORTING = ['Steve', 'Alex'] as string[]
|
|
|
|
export const DEFAULT_MODELS: Record<string, SkinModel> = {
|
|
Steve: 'CLASSIC',
|
|
Alex: 'SLIM',
|
|
Zuri: 'CLASSIC',
|
|
Sunny: 'CLASSIC',
|
|
Noor: 'SLIM',
|
|
Makena: 'SLIM',
|
|
Kai: 'CLASSIC',
|
|
Efe: 'SLIM',
|
|
Ari: 'CLASSIC',
|
|
}
|
|
|
|
export function filterSavedSkins(list: Skin[]) {
|
|
const customSkins = list.filter((s) => s.source !== 'default')
|
|
fixUnknownSkins(customSkins).catch(handleError)
|
|
return customSkins
|
|
}
|
|
|
|
export async function determineModelType(texture: string): Promise<'SLIM' | 'CLASSIC'> {
|
|
return new Promise((resolve, reject) => {
|
|
const canvas = document.createElement('canvas')
|
|
const context = canvas.getContext('2d')
|
|
|
|
if (!context) {
|
|
return reject(new Error('Failed to create canvas rendering context.'))
|
|
}
|
|
|
|
const image = new Image()
|
|
image.crossOrigin = 'anonymous'
|
|
image.src = texture
|
|
|
|
image.onload = () => {
|
|
canvas.width = image.width
|
|
canvas.height = image.height
|
|
|
|
context.drawImage(image, 0, 0)
|
|
|
|
const armX = 44
|
|
const armY = 16
|
|
const armWidth = 4
|
|
const armHeight = 12
|
|
|
|
const imageData = context.getImageData(armX, armY, armWidth, armHeight).data
|
|
|
|
for (let y = 0; y < armHeight; y++) {
|
|
const alphaIndex = (3 + y * armWidth) * 4 + 3
|
|
if (imageData[alphaIndex] !== 0) {
|
|
resolve('CLASSIC')
|
|
return
|
|
}
|
|
}
|
|
|
|
canvas.remove()
|
|
resolve('SLIM')
|
|
}
|
|
|
|
image.onerror = () => {
|
|
canvas.remove()
|
|
reject(new Error('Failed to load the image.'))
|
|
}
|
|
})
|
|
}
|
|
|
|
export async function fixUnknownSkins(list: Skin[]) {
|
|
const unknownSkins = list.filter((s) => s.variant === 'UNKNOWN')
|
|
for (const unknownSkin of unknownSkins) {
|
|
unknownSkin.variant = await determineModelType(unknownSkin.texture)
|
|
}
|
|
}
|
|
|
|
export function filterDefaultSkins(list: Skin[]) {
|
|
return list
|
|
.filter((s) => s.source === 'default' && (!s.name || s.variant === DEFAULT_MODELS[s.name]))
|
|
.sort((a, b) => {
|
|
const aIndex = a.name ? DEFAULT_MODEL_SORTING.indexOf(a.name) : -1
|
|
const bIndex = b.name ? DEFAULT_MODEL_SORTING.indexOf(b.name) : -1
|
|
return (aIndex === -1 ? Infinity : aIndex) - (bIndex === -1 ? Infinity : bIndex)
|
|
})
|
|
}
|
|
|
|
export async function get_available_capes(): Promise<Cape[]> {
|
|
return invoke('plugin:minecraft-skins|get_available_capes', {})
|
|
}
|
|
|
|
export async function get_available_skins(): Promise<Skin[]> {
|
|
return invoke('plugin:minecraft-skins|get_available_skins', {})
|
|
}
|
|
|
|
export async function add_and_equip_custom_skin(
|
|
textureBlob: Uint8Array,
|
|
variant: SkinModel,
|
|
capeOverride?: Cape,
|
|
): Promise<void> {
|
|
await invoke('plugin:minecraft-skins|add_and_equip_custom_skin', {
|
|
textureBlob,
|
|
variant,
|
|
capeOverride,
|
|
})
|
|
}
|
|
|
|
export async function set_default_cape(cape?: Cape): Promise<void> {
|
|
await invoke('plugin:minecraft-skins|set_default_cape', {
|
|
cape,
|
|
})
|
|
}
|
|
|
|
export async function equip_skin(skin: Skin): Promise<void> {
|
|
await invoke('plugin:minecraft-skins|equip_skin', {
|
|
skin,
|
|
})
|
|
}
|
|
|
|
export async function remove_custom_skin(skin: Skin): Promise<void> {
|
|
await invoke('plugin:minecraft-skins|remove_custom_skin', {
|
|
skin,
|
|
})
|
|
}
|
|
|
|
export async function get_normalized_skin_texture(skin: Skin): Promise<string> {
|
|
const data = await normalize_skin_texture(skin.texture)
|
|
const base64 = arrayBufferToBase64(data)
|
|
return `data:image/png;base64,${base64}`
|
|
}
|
|
|
|
export async function normalize_skin_texture(texture: Uint8Array | string): Promise<Uint8Array> {
|
|
return await invoke('plugin:minecraft-skins|normalize_skin_texture', { texture })
|
|
}
|
|
|
|
export async function unequip_skin(): Promise<void> {
|
|
await invoke('plugin:minecraft-skins|unequip_skin')
|
|
}
|
|
|
|
export async function get_dragged_skin_data(path: string): Promise<Uint8Array> {
|
|
const data = await invoke('plugin:minecraft-skins|get_dragged_skin_data', { path })
|
|
return new Uint8Array(data)
|
|
}
|