@@ -3,7 +3,7 @@ use serde::Deserialize;
33
44use crate :: assets:: {
55 indexing:: { AssetIndexPlugin , Indexable } ,
6- loaders:: toml:: TomlAssetPlugin ,
6+ loaders:: toml:: { FromToml , TomlAssetPlugin } ,
77 tracking:: LoadResource ,
88} ;
99
@@ -17,7 +17,7 @@ pub fn plugin(app: &mut App) {
1717}
1818
1919#[ derive( Asset , Clone , Debug , Deserialize , Reflect ) ]
20- pub struct ItemDef {
20+ pub struct ItemRaw {
2121 pub id : String ,
2222 pub name : String ,
2323 pub description : String ,
@@ -28,6 +28,43 @@ pub struct ItemDef {
2828 pub transport : Transport ,
2929}
3030
31+ fn placeholder_sprite ( ) -> String {
32+ String :: from ( "sprites/items/placeholder.png" )
33+ }
34+
35+ #[ derive( Asset , Reflect , Debug ) ]
36+ pub struct ItemDef {
37+ pub id : String ,
38+ pub name : String ,
39+ pub description : String ,
40+ pub sprite : AssetId < Image > ,
41+ pub stack_size : u32 ,
42+ pub taxonomy : Taxonomy ,
43+ pub transport : Transport ,
44+ }
45+
46+ impl FromToml for ItemDef {
47+ type Raw = ItemRaw ;
48+
49+ fn from_toml ( raw : Self :: Raw , load_context : & mut bevy:: asset:: LoadContext ) -> Self {
50+ Self {
51+ id : raw. id ,
52+ name : raw. name ,
53+ description : raw. description ,
54+ sprite : load_context. load ( raw. sprite ) . id ( ) ,
55+ stack_size : raw. stack_size ,
56+ taxonomy : raw. taxonomy ,
57+ transport : raw. transport ,
58+ }
59+ }
60+ }
61+
62+ impl Indexable for ItemDef {
63+ fn index ( & self ) -> & String {
64+ & self . id
65+ }
66+ }
67+
3168#[ derive( Component , Clone , Debug , Deserialize , Reflect , PartialEq , Eq ) ]
3269#[ reflect( Component ) ]
3370pub enum Taxonomy {
@@ -42,16 +79,6 @@ pub enum Transport {
4279 Bag ,
4380}
4481
45- fn placeholder_sprite ( ) -> String {
46- String :: from ( "sprites/items/placeholder.png" )
47- }
48-
49- impl Indexable for ItemDef {
50- fn index ( & self ) -> & String {
51- & self . id
52- }
53- }
54-
5582#[ derive( Asset , Clone , Resource , Reflect ) ]
5683#[ reflect( Resource ) ]
5784pub struct ItemAssets {
0 commit comments