Skip to content

Commit

Permalink
fix: type related issues in new API wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
HoraceHuang-ui committed Jan 28, 2024
1 parent 8dd2e8d commit 34ecdd8
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 72 deletions.
34 changes: 20 additions & 14 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import {app, BrowserWindow, ipcMain, Menu, nativeTheme, shell, Tray} from 'electron'
// const {dialog} = require('electron');
import {app, BrowserWindow, dialog, ipcMain, Menu, nativeTheme, shell, Tray} from 'electron'
import axios from 'axios'
import {release} from 'node:os'
// const Store = require('electron-store')
import Store from 'electron-store'
// const child = require('child_process')
import child from 'child_process'
// const {EnkaClient, TextAssets, DynamicTextAssets} = require("enka-network-api");
import {DynamicTextAssets, EnkaClient, TextAssets} from "enka-network-api";

const fs = require('fs').promises
var path = require('path')
import {promises as fs} from 'fs';

// const fs = require('fs').promises
// var path = require('path')
import path from 'path'

const Store = require('electron-store');
const store = new Store();
const child = require('child_process')
const {dialog} = require('electron');
const {EnkaClient, TextAssets, DynamicTextAssets} = require("enka-network-api");

// The built directory structure
//
Expand Down Expand Up @@ -128,14 +134,7 @@ async function createWindow() {
try {
const result = await dialog.showOpenDialog(win, options)
if (!result.canceled && result.filePaths.length > 0) {
try {
await fs.access(imageFolder)
} catch {
await fs.mkdir(imageFolder)
}

const sourcePath = result.filePaths[0];

const dataURL = await fs.readFile(sourcePath, 'base64')
.then(data => `data:image/png;base64,${data}`)

Expand All @@ -158,6 +157,13 @@ async function createWindow() {
if (obj instanceof TextAssets) {
entries.push(["text", obj instanceof DynamicTextAssets ? obj.getNullableReplacedText() : obj.getNullable()]); // convert TextAssets to string
}
if (obj instanceof Array) {
const arr = []
for (const [_, entry] of entries) {
arr.push(entry)
}
return arr
}
return Object.fromEntries(entries);
}

Expand Down
34 changes: 17 additions & 17 deletions src/pages/GenshinPage/Components/GSCharDetailsOverlay.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import {ref} from 'vue'
import {PropType, ref} from 'vue'
import StatIcon from "../../../components/StatIcon.vue";
import DialogListItem from "../../../components/DialogListItem.vue";
import {translate} from "../../../i18n";
Expand All @@ -12,18 +12,18 @@ const props = defineProps({
default: 'Character Details'
},
stats: {
type: Object,
type: Array as PropType<any[]>,
required: true
}
})
const dialogRef = ref<any>(null)
const trimStats = (stats: any) => {
const trimStats = (stats: any[]) => {
const trim = ['HP', 'PERCENT', 'ATTACK', 'DEFENSE', 'BASE_SPEED', 'MASTERY']
const res: Record<string, any> = {}
for (const stat of Object.values(stats)) {
for (const stat of stats) {
let flag = false
for (const t of trim) {
if (stat.fightProp.endsWith(t) || stat.value == 0) {
Expand Down Expand Up @@ -79,12 +79,12 @@ const closeDialog = () => {
<StatIcon game="gs" stat="FIGHT_PROP_HP" fill="#eee" class="w-4 h-4" style="margin-top: 2px;"/>
</template>
<div class="font-gs">
<span>{{ stats['0'].value.toFixed(0) }}</span>
<span>{{ stats[0].value.toFixed(0) }}</span>
<span
v-if="stats['37'].value.toFixed(0) != stats['0'].value.toFixed(0)"
v-if="stats[37].value.toFixed(0) != stats[0].value.toFixed(0)"
class="ml-1 text-blue-400">+{{
stats['37'].value.toFixed(0)
- stats['0'].value.toFixed(0)
stats[37].value.toFixed(0)
- stats[0].value.toFixed(0)
}}</span>
</div>
</DialogListItem>
Expand All @@ -94,12 +94,12 @@ const closeDialog = () => {
style="margin-top: 2px;"/>
</template>
<div class="font-gs">
<span>{{ stats['3'].value.toFixed(0) }}</span>
<span>{{ stats[3].value.toFixed(0) }}</span>
<span
v-if="stats['38'].value.toFixed(0) != stats['3'].value.toFixed(0)"
v-if="stats[38].value.toFixed(0) != stats[3].value.toFixed(0)"
class="ml-1 text-blue-400">+{{
stats['38'].value.toFixed(0) -
stats['3'].value.toFixed(0)
stats[38].value.toFixed(0) -
stats[3].value.toFixed(0)
}}</span>
</div>
</DialogListItem>
Expand All @@ -109,17 +109,17 @@ const closeDialog = () => {
style="margin-top: 2px;"/>
</template>
<div class="font-gs">
<span>{{ stats['6'].value.toFixed(0) }}</span>
<span>{{ stats[6].value.toFixed(0) }}</span>
<span
v-if="stats['39'].value.toFixed(0) != stats['6'].value.toFixed(0)"
v-if="stats[39].value.toFixed(0) != stats[6].value.toFixed(0)"
class="ml-1 text-blue-400">+{{
stats['39'].value.toFixed(0) -
stats['6'].value.toFixed(0)
stats[39].value.toFixed(0) -
stats[6].value.toFixed(0)
}}</span>
</div>
</DialogListItem>
<DialogListItem class="font-gs" :name="translate('gs_FIGHT_PROP_ELEMENT_MASTERY')"
:val="stats['16'].value.toFixed(0)">
:val="stats[16].value.toFixed(0)">
<template #icon>
<StatIcon game="gs" stat="FIGHT_PROP_ELEMENT_MASTERY" fill="#eee" class="w-4 h-4"
style="margin-top: 2px;"/>
Expand Down
Loading

0 comments on commit 34ecdd8

Please sign in to comment.