Skip to main content

ItemDef

Struct ItemDef 

Source
pub struct ItemDef {
Show 24 fields pub id: u32, pub name: String, pub group: ItemGroup, pub icon: String, pub model: Option<String>, pub material: Material, pub weight: u32, pub description: Option<String>, pub color: Option<[u8; 3]>, pub scale: Option<f32>, pub fx: Option<u32>, pub alpha: Option<f32>, pub shininess: Option<f32>, pub blend: Option<u32>, pub durability: Option<f32>, pub health_change: Option<f32>, pub behaviour: Option<String>, pub damage: Option<String>, pub speed: Option<f32>, pub drag: Option<f32>, pub rate: Option<u32>, pub weapon_state: Option<String>, pub radius: Option<f32>, pub collision: Option<u32>,
}
Expand description

Full definition of a single item type.

Represents one entry from an item .inf file, serialisable to/from RON, JSON, or any serde-compatible format.

Most fields are optional and default to None — only the identity fields (id, name, icon) are required for construction via from_inf_fields.

§Construction from .inf fields

use std::collections::HashMap;
use openstranded_common_items::ItemDef;

let mut fields = HashMap::new();
fields.insert("id".into(), vec!["2".into()]);
fields.insert("name".into(), vec!["small Crystal".into()]);
fields.insert("icon".into(), vec!["gfx\\crystal01.bmp".into()]);
fields.insert("group".into(), vec!["material".into()]);
fields.insert("mat".into(), vec!["stone".into()]);
fields.insert("weight".into(), vec!["200".into()]);

let item = ItemDef::from_inf_fields(&fields).unwrap();
assert_eq!(item.id, 2);

Fields§

§id: u32

Unique numeric identifier.

§name: String

Display name.

§group: ItemGroup

Category group.

§icon: String

Path to the icon texture (.png after conversion).

§model: Option<String>

Path to the 3D model (.glb after conversion).

§material: Material

Base material type.

§weight: u32

Weight in grams.

§description: Option<String>

Short description / info text.

§color: Option<[u8; 3]>

RGB colour tint.

§scale: Option<f32>

Uniform scale factor.

§fx: Option<u32>

Blitz3D FX flags.

§alpha: Option<f32>

Alpha transparency.

§shininess: Option<f32>

Shininess / specular intensity.

§blend: Option<u32>

Blend mode.

§durability: Option<f32>

Item durability / hit points.

§health_change: Option<f32>

Health change when consumed.

§behaviour: Option<String>

Behaviour type string (e.g. "throw", "blade", "ammo:51").

§damage: Option<String>

Damage value (number or formula string).

§speed: Option<f32>

Projectile speed or weapon range.

§drag: Option<f32>

Air drag for projectiles.

§rate: Option<u32>

Fire rate / use cooldown in milliseconds.

§weapon_state: Option<String>

Weapon state effect (e.g. "intoxication").

§radius: Option<f32>

Pick radius for collision.

§collision: Option<u32>

Collision type index.

Implementations§

Source§

impl ItemDef

Source

pub fn from_inf_fields(fields: &HashMap<String, Vec<String>>) -> Option<Self>

Construct an ItemDef from the raw fields of a parsed .inf entry.

This is the main entry point for WASM plugins that receive registry data in the InfEntry format and want to convert it to a strongly-typed ItemDef.

Unknown or unparseable fields are silently ignored; missing required fields (id, name, icon) return None.

Trait Implementations§

Source§

impl Clone for ItemDef

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ItemDef

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ItemDef

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for ItemDef

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ItemDef

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ItemDef

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.