TypeScript用のタイプ追加 #2
@@ -2,9 +2,10 @@
|
||||
import { invoke } from "@tauri-apps/api/tauri";
|
||||
import AutoComplete from "simple-svelte-autocomplete";
|
||||
import attack_types from "../const/attack_types.json";
|
||||
import type { PokemonData } from "../model/PokemonStatus";
|
||||
|
||||
export let player1Data;
|
||||
export let player2Data;
|
||||
export let player1Data: PokemonData | undefined;
|
||||
export let player2Data: PokemonData | undefined;
|
||||
let attackData;
|
||||
$: {
|
||||
if (myValue > 0 && myValue !== currentValue) {
|
||||
@@ -62,13 +63,13 @@
|
||||
minDamage: 0,
|
||||
// 攻撃側タイプ
|
||||
// TODO: try catchでエラーハンドリング
|
||||
atk_type: JSON.parse(attacker.types), // 配列なのでjson parse
|
||||
atk_type: attacker.types,
|
||||
atk_terastype: attacker.terastype,
|
||||
// 防御側タイプ
|
||||
def_type:
|
||||
defender.terastype[0] > 0
|
||||
? defender.terastype
|
||||
: JSON.parse(defender.types),
|
||||
: defender.types,
|
||||
|
||||
// 技タイプ
|
||||
move_type: JSON.parse(attackData.types),
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { invoke } from "@tauri-apps/api/tauri";
|
||||
import AutoComplete from "simple-svelte-autocomplete";
|
||||
import DisplayData from "./DisplayData.svelte";
|
||||
import type { PokemonData } from "../model/PokemonStatus";
|
||||
$: {
|
||||
if (myValue > 0 && myValue !== currentValue) {
|
||||
invoke("search", { index: myValue }).then((r) => {
|
||||
@@ -11,7 +12,7 @@
|
||||
});
|
||||
}
|
||||
pokemonStatus = {
|
||||
types: pokemonData?.types ? pokemonData.types : [],
|
||||
types: pokemonData?.types ? JSON.parse(pokemonData.types) : [],
|
||||
terastype: terastype,
|
||||
hp: hp_final,
|
||||
atk: atk_final,
|
||||
@@ -32,7 +33,7 @@
|
||||
let spatk_final = 0;
|
||||
let spdef_final = 0;
|
||||
let spd_final = 0;
|
||||
export let pokemonStatus = {
|
||||
export let pokemonStatus: PokemonData = {
|
||||
types: [],
|
||||
terastype: [0],
|
||||
hp: 0,
|
||||
|
||||
10
src/model/PokemonStatus.ts
Normal file
10
src/model/PokemonStatus.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export interface PokemonData {
|
||||
types: number[],
|
||||
terastype: number[],
|
||||
hp: number,
|
||||
atk: number,
|
||||
def: number,
|
||||
spatk: number,
|
||||
spdef: number,
|
||||
spd: number
|
||||
};
|
||||
Reference in New Issue
Block a user