changed string to hashmap/record for abilities

This commit is contained in:
2023-02-06 21:00:04 +09:00
parent 670a01a7fa
commit cc6cec5640
4 changed files with 11 additions and 8 deletions

View File

@@ -2,6 +2,7 @@
all(not(debug_assertions), target_os = "windows"), all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows" windows_subsystem = "windows"
)] )]
use std::collections::HashMap;
use std::fs; use std::fs;
use serde_json::json; use serde_json::json;
@@ -241,7 +242,7 @@ fn search(index: i64) -> SearchResult {
name: row.read::<&str, _>("name").to_string(), name: row.read::<&str, _>("name").to_string(),
types: serde_json::from_str(row.read::<&str, _>("types")).unwrap_or(vec![0]), types: serde_json::from_str(row.read::<&str, _>("types")).unwrap_or(vec![0]),
thumbnail: row.read::<&str, _>("thumbnail").to_string(), thumbnail: row.read::<&str, _>("thumbnail").to_string(),
abilities: row.read::<&str, _>("abilities").to_string(), abilities: serde_json::from_str(row.read::<&str, _>("abilities")).unwrap_or(HashMap::new()),
hp: row.read::<i64, _>("hp"), hp: row.read::<i64, _>("hp"),
attack: row.read::<i64, _>("attack"), attack: row.read::<i64, _>("attack"),
defense: row.read::<i64, _>("defense"), defense: row.read::<i64, _>("defense"),
@@ -257,7 +258,7 @@ fn search(index: i64) -> SearchResult {
name: "Missigno".to_string(), name: "Missigno".to_string(),
types: vec![], types: vec![],
thumbnail: "".to_string(), thumbnail: "".to_string(),
abilities: "{}".to_string(), abilities: HashMap::new(),
hp: 0, hp: 0,
attack: 0, attack: 0,
defense: 0, defense: 0,

View File

@@ -1,3 +1,5 @@
use std::collections::HashMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
@@ -11,7 +13,7 @@ pub struct SearchResult {
pub special_attack: i64, pub special_attack: i64,
pub special_defense: i64, pub special_defense: i64,
pub speed: i64, pub speed: i64,
pub abilities: String, pub abilities: HashMap<String, String>,
pub thumbnail: String, pub thumbnail: String,
pub learnset: Vec<PokemonDataLearnset>, pub learnset: Vec<PokemonDataLearnset>,
} }
@@ -82,7 +84,7 @@ pub struct PokemonDataToLoad {
pub name: String, pub name: String,
pub types: Vec<i64>, pub types: Vec<i64>,
pub thumbnail: String, pub thumbnail: String,
pub abilities: String, pub abilities: HashMap<String, String>,
pub hp: i64, pub hp: i64,
pub attack: i64, pub attack: i64,
pub defense: i64, pub defense: i64,

View File

@@ -135,8 +135,8 @@
} else if (!pokemonData.speed_plus && !!pokemonData.speed_minus) { } else if (!pokemonData.speed_plus && !!pokemonData.speed_minus) {
spd_p = 0.9; spd_p = 0.9;
} }
abilities = Object.keys(JSON.parse(pokemonData.abilities)); abilities = Object.keys(pokemonData.abilities);
abilities_description = Object.values(JSON.parse(pokemonData.abilities)); abilities_description = Object.values(pokemonData.abilities);
hp_final = calculate_hp( hp_final = calculate_hp(
pokemonData.hp, pokemonData.hp,
pokemonData.hp_v, pokemonData.hp_v,

View File

@@ -3,7 +3,7 @@ export interface PokemonDBData {
name: string; name: string;
types: number[]; types: number[];
thumbnail: string; thumbnail: string;
abilities: string; abilities: Record<string, string>;
hp: number; hp: number;
attack: number; attack: number;
defense: number; defense: number;
@@ -17,7 +17,7 @@ export interface PokemonData {
name: string; name: string;
types: number[]; types: number[];
thumbnail: string; thumbnail: string;
abilities: string; abilities: Record<string, string>;
hp: number; hp: number;
attack: number; attack: number;
defense: number; defense: number;