reflect attack automatically

This commit is contained in:
2023-02-05 20:06:01 +09:00
parent fbea5ac8e5
commit 8b73b7f952
6 changed files with 53 additions and 10 deletions

View File

@@ -122,7 +122,7 @@ fn search(index: i64) -> SearchResult {
{
let row_result = PokemonDataLearnset {
id: row.read::<i64, _>("id"),
learset_id: row.read::<i64, _>("learnset_id"),
learnset_id: row.read::<i64, _>("learnset_id"),
name: row.read::<&str, _>("name").to_string(),
types: serde_json::from_str(row.read::<&str, _>("types")).unwrap_or(vec![0]),
power: row.read::<i64, _>("power"),

View File

@@ -19,7 +19,7 @@ pub struct SearchResult {
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PokemonDataLearnset {
pub id: i64,
pub learset_id: i64,
pub learnset_id: i64,
pub name: String,
pub types: Vec<i64>,
pub power: i64,

View File

@@ -4,19 +4,20 @@
import "carbon-components-svelte/css/g80.css";
let player1Data;
let player2Data;
let attackId;
</script>
<main class="container">
<div class="main-row">
<div class="column-1">
<MainWrapper bind:pokemonStatus={player1Data} />
<MainWrapper bind:pokemonStatus={player1Data} bind:attackId/>
</div>
<div class="column-2">
<MainWrapper bind:pokemonStatus={player2Data} />
<MainWrapper bind:pokemonStatus={player2Data} bind:attackId />
</div>
</div>
<div class="row">
<DamageCalculator bind:player1Data bind:player2Data />
<DamageCalculator bind:player1Data bind:player2Data bind:attackId />
</div>
</main>

View File

@@ -6,6 +6,7 @@
export let player1Data: PokemonData | undefined;
export let player2Data: PokemonData | undefined;
export let attackId: number | undefined;
let attackData;
$: {
if (myValue > 0 && myValue !== currentValue) {
@@ -15,6 +16,14 @@
console.log(attackData);
});
}
if (!!attackId) {
invoke("search_move", { index: attackId }).then((r) => {
currentValue = myValue = attackId;
attackData = r;
console.log(attackData);
attackId = undefined;
});
}
}
let attack_direction = "p1p2";
let total_max_damage = 0;

View File

@@ -6,6 +6,7 @@
import SpecialIcon from "../assets/tokushu.png";
import BuffIcon from "../assets/henka.png";
export let pokemonData: PokemonDBData | undefined;
export let attackId: number | undefined;
function v_validator(v) {
if (typeof v !== "number") {
return null;
@@ -618,10 +619,27 @@
</table>
</AccordionItem>
<AccordionItem open title="技">
<table class=weakness>
<table class="learnset">
{#each pokemonData.learnset as learnset}
<tr>
<td><img src={learnset.category === 1 ? PhysicalIcon : learnset.category === 2 ? SpecialIcon : BuffIcon} alt="a"></td>
<tr
on:click={() => {
console.log("passing" + learnset.name);
console.log(learnset.learnset_id);
console.log(attackId);
attackId = learnset.learnset_id;
console.log(attackId);
}}
>
<td
><img
src={learnset.category === 1
? PhysicalIcon
: learnset.category === 2
? SpecialIcon
: BuffIcon}
alt="a"
/></td
>
<td>{@html generate_type(learnset.types)}</td>
<td>{learnset.name}</td>
<td>{learnset.power}</td>
@@ -675,8 +693,8 @@
}
.vd-input {
width: 50px;
padding-left:0;
padding-right:0;
padding-left: 0;
padding-right: 0;
height: 8px;
}
.abilities_table {
@@ -700,4 +718,17 @@
vertical-align: middle;
min-height: 25px;
}
.learnset {
width: 90%;
}
.learnset > tr:hover {
width: 90%;
background-color: rgba(255, 255, 255, 0.5);
cursor: pointer;
}
.learnset > tr > td {
border: 1px solid;
vertical-align: middle;
min-height: 25px;
}
</style>

View File

@@ -24,6 +24,7 @@
};
console.log(pokemonStatus);
}
export let attackId: number | undefined;
let myValue;
let currentValue = 0;
let pokemonData: PokemonDBData | undefined;
@@ -78,6 +79,7 @@
bind:spatk_final
bind:spdef_final
bind:spd_final
bind:attackId
/>
</div>
</div>