Add CharX-Jpeg
This commit is contained in:
@@ -489,7 +489,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{:else}
|
{:else}
|
||||||
<span class="text-textcolor2 text-sm">{language.ccv3Desc}</span>
|
<span class="text-textcolor2 text-sm">{language.ccv3Desc}</span>
|
||||||
{#if cardExportType2 !== 'charx' && isCharacterHasAssets(DBState.db.characters[$selectedCharID])}
|
{#if cardExportType2 !== 'charx' && cardExportType2 !== 'charxJpeg' && isCharacterHasAssets(DBState.db.characters[$selectedCharID])}
|
||||||
<span class="text-red-500 text-sm">{language.notCharxWarn}</span>
|
<span class="text-red-500 text-sm">{language.notCharxWarn}</span>
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
@@ -512,7 +512,7 @@
|
|||||||
<button class="bg-bgcolor px-2 py-4 rounded-lg flex-1" class:ring-1={cardExportType === 'realm'} onclick={() => {cardExportType = 'realm'}}>RisuRealm</button>
|
<button class="bg-bgcolor px-2 py-4 rounded-lg flex-1" class:ring-1={cardExportType === 'realm'} onclick={() => {cardExportType = 'realm'}}>RisuRealm</button>
|
||||||
<button class="bg-bgcolor px-2 py-4 rounded-lg ml-2 flex-1" class:ring-1={cardExportType === ''} onclick={() => {
|
<button class="bg-bgcolor px-2 py-4 rounded-lg ml-2 flex-1" class:ring-1={cardExportType === ''} onclick={() => {
|
||||||
cardExportType = ''
|
cardExportType = ''
|
||||||
cardExportType2 = isCharacterHasAssets(DBState.db.characters[$selectedCharID]) ? 'charx' : ''
|
cardExportType2 = 'charxJpeg'
|
||||||
}}>Character Card V3</button>
|
}}>Character Card V3</button>
|
||||||
<button class="bg-bgcolor px-2 py-4 rounded-lg ml-2 flex-1" class:ring-1={cardExportType === 'ccv2'} onclick={() => {cardExportType = 'ccv2'}}>Character Card V2</button>
|
<button class="bg-bgcolor px-2 py-4 rounded-lg ml-2 flex-1" class:ring-1={cardExportType === 'ccv2'} onclick={() => {cardExportType = 'ccv2'}}>Character Card V2</button>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -520,9 +520,10 @@
|
|||||||
{#if $alertStore.submsg === '' && cardExportType === ''}
|
{#if $alertStore.submsg === '' && cardExportType === ''}
|
||||||
<span class="text-textcolor mt-4">{language.format}</span>
|
<span class="text-textcolor mt-4">{language.format}</span>
|
||||||
<SelectInput bind:value={cardExportType2} className="mt-2">
|
<SelectInput bind:value={cardExportType2} className="mt-2">
|
||||||
|
<OptionInput value="charx">CHARX</OptionInput>
|
||||||
|
<OptionInput value="charxJpeg">CHARX-JPEG</OptionInput>
|
||||||
<OptionInput value="">PNG</OptionInput>
|
<OptionInput value="">PNG</OptionInput>
|
||||||
<OptionInput value="json">JSON</OptionInput>
|
<OptionInput value="json">JSON</OptionInput>
|
||||||
<OptionInput value="charx">CHARX</OptionInput>
|
|
||||||
</SelectInput>
|
</SelectInput>
|
||||||
{/if}
|
{/if}
|
||||||
<Button className="mt-4" onclick={() => {
|
<Button className="mt-4" onclick={() => {
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export async function importCharacterProcess(f:{
|
|||||||
let db = getDatabase()
|
let db = getDatabase()
|
||||||
db.statics.imports += 1
|
db.statics.imports += 1
|
||||||
|
|
||||||
if(f.name.endsWith('charx')){
|
if(f.name.endsWith('charx') || f.name.endsWith('jpg') || f.name.endsWith('jpeg')){
|
||||||
console.log('reading charx')
|
console.log('reading charx')
|
||||||
alertStore.set({
|
alertStore.set({
|
||||||
type: 'wait',
|
type: 'wait',
|
||||||
@@ -474,7 +474,7 @@ export async function characterURLImport() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function importFile(name:string, data:Uint8Array) {
|
async function importFile(name:string, data:Uint8Array) {
|
||||||
if(name.endsWith('.charx') || name.endsWith('.png')){
|
if(name.endsWith('.charx') || name.endsWith('.jpg') || name.endsWith('.jpeg') || name.endsWith('.png')){
|
||||||
await importCharacterProcess({
|
await importCharacterProcess({
|
||||||
name: name,
|
name: name,
|
||||||
data: data
|
data: data
|
||||||
@@ -609,7 +609,7 @@ export async function exportChar(charaID:number):Promise<string> {
|
|||||||
|
|
||||||
const option = await alertCardExport()
|
const option = await alertCardExport()
|
||||||
if(option.type === ''){
|
if(option.type === ''){
|
||||||
exportCharacterCard(char, option.type2 === 'json' ? 'json' : (option.type2 === 'charx' ? 'charx' : 'png'), {spec: 'v3'})
|
exportCharacterCard(char, option.type2 === 'json' ? 'json' : (option.type2 === 'charx' ? 'charx' : option.type2 === 'charxJpeg' ? 'charxJpeg' : 'png'), {spec: 'v3'})
|
||||||
}
|
}
|
||||||
else if(option.type === 'ccv2'){
|
else if(option.type === 'ccv2'){
|
||||||
exportCharacterCard(char,'png', {spec: 'v2'})
|
exportCharacterCard(char,'png', {spec: 'v2'})
|
||||||
@@ -1131,7 +1131,7 @@ async function createBaseV2(char:character) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function exportCharacterCard(char:character, type:'png'|'json'|'charx' = 'png', arg:{
|
export async function exportCharacterCard(char:character, type:'png'|'json'|'charx'|'charxJpeg' = 'png', arg:{
|
||||||
password?:string
|
password?:string
|
||||||
writer?:LocalWriter|VirtualWriter,
|
writer?:LocalWriter|VirtualWriter,
|
||||||
spec?:'v2'|'v3'
|
spec?:'v2'|'v3'
|
||||||
@@ -1146,14 +1146,18 @@ export async function exportCharacterCard(char:character, type:'png'|'json'|'cha
|
|||||||
const nameExt = {
|
const nameExt = {
|
||||||
'png': ['Image File', 'png'],
|
'png': ['Image File', 'png'],
|
||||||
'json': ['JSON File', 'json'],
|
'json': ['JSON File', 'json'],
|
||||||
'charx': ['CharX File', 'charx']
|
'charx': ['CharX File', 'charx'],
|
||||||
|
'charxJpeg': ['CharX Embeded Jpeg', 'jpeg']
|
||||||
}
|
}
|
||||||
const ext = nameExt[type]
|
const ext = nameExt[type]
|
||||||
console.log(ext)
|
console.log(ext)
|
||||||
await (localWriter as LocalWriter).init(ext[0], [ext[1]])
|
await (localWriter as LocalWriter).init(ext[0], [ext[1]])
|
||||||
}
|
}
|
||||||
const writer = type === 'charx' ? (new CharXWriter(localWriter)) : type === 'json' ? (new BlankWriter()) : (new PngChunk.streamWriter(img, localWriter))
|
const writer = (type === 'charx' || type === 'charxJpeg') ? (new CharXWriter(localWriter)) : type === 'json' ? (new BlankWriter()) : (new PngChunk.streamWriter(img, localWriter))
|
||||||
await writer.init()
|
await writer.init()
|
||||||
|
if(writer instanceof CharXWriter && type === 'charxJpeg'){
|
||||||
|
await writer.writeJpeg(img)
|
||||||
|
}
|
||||||
let assetIndex = 0
|
let assetIndex = 0
|
||||||
if(spec === 'v2'){
|
if(spec === 'v2'){
|
||||||
const card = await createBaseV2(char)
|
const card = await createBaseV2(char)
|
||||||
@@ -1347,7 +1351,7 @@ export async function exportCharacterCard(char:character, type:'png'|'json'|'cha
|
|||||||
msg: 'Loading... (Writing)'
|
msg: 'Loading... (Writing)'
|
||||||
})
|
})
|
||||||
|
|
||||||
if(type === 'charx'){
|
if(type === 'charx' || type === 'charxJpeg'){
|
||||||
const md:RisuModule = {
|
const md:RisuModule = {
|
||||||
name: `${char.name} Module`,
|
name: `${char.name} Module`,
|
||||||
description: "Module for " + char.name,
|
description: "Module for " + char.name,
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ export class CharXWriter{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.zip = new fflate.Zip()
|
this.zip = new fflate.Zip()
|
||||||
this.zip.ondata = handlerAsync
|
this.zip.ondata = handlerAsync
|
||||||
}
|
}
|
||||||
@@ -41,6 +40,29 @@ export class CharXWriter{
|
|||||||
//do nothing, just to make compatible with other writer
|
//do nothing, just to make compatible with other writer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async writeJpeg(img:Uint8Array<ArrayBufferLike>){
|
||||||
|
console.log('writeJpeg')
|
||||||
|
const canvas = document.createElement('canvas')
|
||||||
|
const ctx = canvas.getContext('2d')
|
||||||
|
if(!ctx){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const imgBlob = new Blob([img], {type: 'image/jpeg'})
|
||||||
|
const imgURL = URL.createObjectURL(imgBlob)
|
||||||
|
const imgElement = document.createElement('img')
|
||||||
|
imgElement.src = imgURL
|
||||||
|
await imgElement.decode()
|
||||||
|
canvas.width = imgElement.width
|
||||||
|
canvas.height = imgElement.height
|
||||||
|
ctx.drawImage(imgElement, 0, 0)
|
||||||
|
const blob = await (new Promise((res:BlobCallback, rej) => {
|
||||||
|
canvas.toBlob(res, 'image/jpeg')
|
||||||
|
}))
|
||||||
|
const buf = await blob.arrayBuffer()
|
||||||
|
this.apb.append(new Uint8Array(buf))
|
||||||
|
console.log('writeJpeg done')
|
||||||
|
}
|
||||||
|
|
||||||
async write(key:string,data:Uint8Array|string, level?:0|1|2|3|4|5|6|7|8|9){
|
async write(key:string,data:Uint8Array|string, level?:0|1|2|3|4|5|6|7|8|9){
|
||||||
console.log('write',key)
|
console.log('write',key)
|
||||||
let dat:Uint8Array
|
let dat:Uint8Array
|
||||||
|
|||||||
Reference in New Issue
Block a user