Start of data-driven design (Section 4.2)
This commit is contained in:
parent
cb2839733b
commit
70494d8122
30
raws/spawns.json
Normal file
30
raws/spawns.json
Normal file
@ -0,0 +1,30 @@
|
||||
{
|
||||
"items": [{
|
||||
"name": "Health Potion",
|
||||
"renderable": {
|
||||
"glpyh": "!",
|
||||
"fg": "#FF00FF",
|
||||
"bg": "#000000",
|
||||
"order": 2
|
||||
},
|
||||
"consumable": {
|
||||
"effects": {
|
||||
"provides_healing": "8"
|
||||
}
|
||||
}
|
||||
}, {
|
||||
"name": "Magic Missile Scroll",
|
||||
"renderable": {
|
||||
"glyph": ")",
|
||||
"fg": "#00FFFF",
|
||||
"bg": "#000000",
|
||||
"order": 2
|
||||
},
|
||||
"consumable": {
|
||||
"effects": {
|
||||
"ranged": "6",
|
||||
"damage": "20"
|
||||
}
|
||||
}
|
||||
}]
|
||||
}
|
@ -17,6 +17,7 @@ mod monster_ai_system;
|
||||
mod particle_system;
|
||||
mod player;
|
||||
pub mod random_table;
|
||||
pub mod raws;
|
||||
mod rect;
|
||||
mod rex_assets;
|
||||
pub mod saveload_system;
|
||||
@ -535,6 +536,8 @@ fn main() -> rltk::BError {
|
||||
|
||||
gs.ecs.insert(SimpleMarkerAllocator::<SerializeMe>::new());
|
||||
|
||||
raws::load_raws();
|
||||
|
||||
gs.ecs.insert(Map::new(1, 64, 64));
|
||||
gs.ecs.insert(Point::zero());
|
||||
gs.ecs.insert(rltk::RandomNumberGenerator::new());
|
||||
|
18
src/raws.rs
Normal file
18
src/raws.rs
Normal file
@ -0,0 +1,18 @@
|
||||
mod item_structs;
|
||||
|
||||
use item_structs::Raws;
|
||||
|
||||
rltk::embedded_resource!(RAW_FILE, "../raws/spawns.json");
|
||||
|
||||
pub fn load_raws() {
|
||||
let raw_data = rltk::embedding::EMBED
|
||||
.lock()
|
||||
.get_resource("../raws/spawns.json".to_string())
|
||||
.unwrap();
|
||||
|
||||
let raw_string =
|
||||
std::str::from_utf8(&raw_data).expect("Unable to convert to a valid UTF-8 string.");
|
||||
let decoder: Raws = serde_json::from_str(&raw_string).expect("Unable to parse JSON");
|
||||
|
||||
rltk::console::log(format!("{:?}", decoder));
|
||||
}
|
28
src/raws/item_structs.rs
Normal file
28
src/raws/item_structs.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct Raws {
|
||||
pub items: Vec<Item>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct Item {
|
||||
pub name: String,
|
||||
pub renderable: Option<Renderable>,
|
||||
pub consumable: Option<Consumable>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct Renderable {
|
||||
pub glyph: String,
|
||||
pub fg: String,
|
||||
pub bg: String,
|
||||
pub order: i32,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct Consumable {
|
||||
pub effects: HashMap<String, String>,
|
||||
}
|
Loading…
Reference in New Issue
Block a user