Skip to main content

Assets

Struct Assets 

Source
pub struct Assets {
Show 22 fields pub map_sources: FxHashMap<String, String>, pub maps: FxHashMap<String, Map>, pub entities: FxHashMap<String, (String, String)>, pub items: FxHashMap<String, (String, String)>, pub tiles: IndexMap<Uuid, Tile>, pub materials: FxHashMap<Uuid, Tile>, pub textures: FxHashMap<String, Texture>, pub tile_list: Vec<Tile>, pub tile_indices: FxHashMap<Uuid, u16>, pub screens: FxHashMap<String, Map>, pub character_maps: FxHashMap<String, Map>, pub entity_tiles: FxHashMap<u32, IndexMap<String, Tile>>, pub item_maps: FxHashMap<String, Map>, pub item_tiles: FxHashMap<u32, IndexMap<String, Tile>>, pub config: String, pub atlas: Texture, pub fonts: FxHashMap<String, Font>, pub audio: FxHashMap<String, Vec<u8>>, pub palette: ThePalette, pub global: ShapeFXGraph, pub locales: FxHashMap<String, FxHashMap<String, String>>, pub avatars: FxHashMap<String, Avatar>,
}

Fields§

§map_sources: FxHashMap<String, String>§maps: FxHashMap<String, Map>§entities: FxHashMap<String, (String, String)>§items: FxHashMap<String, (String, String)>§tiles: IndexMap<Uuid, Tile>§materials: FxHashMap<Uuid, Tile>§textures: FxHashMap<String, Texture>§tile_list: Vec<Tile>§tile_indices: FxHashMap<Uuid, u16>§screens: FxHashMap<String, Map>§character_maps: FxHashMap<String, Map>

Maps which build character tiles.

§entity_tiles: FxHashMap<u32, IndexMap<String, Tile>>

The rendered tiles for a given entity.

§item_maps: FxHashMap<String, Map>

Maps which build item tiles.

§item_tiles: FxHashMap<u32, IndexMap<String, Tile>>

The rendered tiles for a given item.

§config: String§atlas: Texture§fonts: FxHashMap<String, Font>§audio: FxHashMap<String, Vec<u8>>§palette: ThePalette§global: ShapeFXGraph§locales: FxHashMap<String, FxHashMap<String, String>>

A map of locale names to their translations.

§avatars: FxHashMap<String, Avatar>

The avatars

Implementations§

Source§

impl Assets

Source

pub fn new() -> Self

Source

pub fn read_locales(&mut self)

Reads all locale tables (locale_*) from the config file.

Source

pub fn clean_tile_list(&mut self)

Clears the tile list.

Source

pub fn tile_index(&self, id: &Uuid) -> Option<u16>

Returns the index into the tile_list for the given Tile Id

Source

pub fn set_tiles(&mut self, tiles: IndexMap<Uuid, Tile>)

Set the tiles and atlas from a list of RGBA tiles.

Source

pub fn set_materials(&mut self, materials: FxHashMap<Uuid, Map>)

Compile the materials.

Source

pub fn blocking_tiles(&self) -> FxHashSet<Uuid>

Returns an FxHashSet of Uuid representing the blocking tiles and materials.

Source

pub fn collect_from_directory(&mut self, dir_path: String)

Collects the assets from a directory.

Examples found in repository?
examples/minigame.rs (line 24)
19    fn new() -> Self
20    where
21        Self: Sized,
22    {
23        let mut assets = Assets::default();
24        assets.collect_from_directory("minigame".to_string());
25        // assets.compile_source_maps();
26
27        let mut rusterix = Rusterix::default();
28        rusterix.set_assets(assets);
29        rusterix.create_regions();
30
31        let camera = Box::new(D3FirstPCamera::new());
32        rusterix.client.set_camera_d3(camera);
33
34        // if let Some(map) = rusterix.assets.get_map("world") {
35        //     // Build the 3D scene from the map meta data
36        //     rusterix
37        //         .client
38        //         .build_scene_d3(map, &rusterix.assets, &ValueContainer::default());
39        // }
40
41        // Add logo on top of the scene
42        rusterix.client.scene_d3.d2_static = vec![
43            Batch2D::from_rectangle(0.0, 0.0, 200.0, 200.0)
44                .receives_light(false)
45                .source(PixelSource::StaticTileIndex(0)),
46        ];
47        // rusterix
48        //     .client
49        //     .scene_d3
50        //     .textures
51        //     .push(Tile::from_texture(Texture::from_image(Path::new(
52        //         "images/logo.png",
53        //     ))));
54
55        Self { rusterix }
56    }
Source

pub fn get_map(&self, name: &str) -> Option<&Map>

Get a map by name.

Examples found in repository?
examples/minigame.rs (line 65)
59    fn draw(&mut self, pixels: &mut [u8], ctx: &mut TheContext) {
60        let _start = get_time();
61
62        // Update the entities on the server.
63        self.rusterix.server.update(&mut self.rusterix.assets);
64
65        if let Some(mut map) = self.rusterix.assets.get_map("world").cloned() {
66            self.rusterix.server.apply_entities_items(&mut map);
67            self.rusterix.build_entities_items_d3(&map);
68
69            self.rusterix
70                .draw_scene(&map, pixels, ctx.width, ctx.height);
71        }
72
73        let _stop = get_time();
74        println!("Execution time: {:?} ms.", _stop - _start);
75    }
Source

pub fn add_entity(&mut self, name: String, code: String, data: String)

Add an entity.

Source

pub fn textures(self, textures: Vec<Tile>) -> Self

Sets textures using the builder pattern.

Examples found in repository?
examples/obj.rs (lines 46-48)
24    fn new() -> Self
25    where
26        Self: Sized,
27    {
28        let scene = Scene::from_static(
29            vec![Batch2D::from_rectangle(0.0, 0.0, 200.0, 200.0)],
30            vec![
31                Batch3D::from_obj(Path::new("examples/teapot.obj"))
32                    .source(PixelSource::StaticTileIndex(0))
33                    .repeat_mode(RepeatMode::RepeatXY)
34                    .transform(Mat4::scaling_3d(Vec3::new(0.35, -0.35, 0.35)))
35                    .with_computed_normals(),
36            ],
37        )
38        .lights(vec![
39            Light::new(LightType::Point)
40                .with_intensity(1.0)
41                .with_color([1.0, 1.0, 0.95])
42                .compile(),
43        ])
44        .background(Box::new(VGrayGradientShader::new()));
45
46        let assets = Assets::default().textures(vec![Tile::from_texture(Texture::from_image(
47            Path::new("images/logo.png"),
48        ))]);
49
50        let mut camera = D3OrbitCamera::new();
51        camera.set_parameter_f32("distance", 1.5);
52
53        Self {
54            camera,
55            scene,
56            start_time: Instant::now(),
57            assets,
58        }
59    }
More examples
Hide additional examples
examples/cube.rs (lines 52-54)
23    fn new() -> Self
24    where
25        Self: Sized,
26    {
27        let scene = Scene::from_static(
28            vec![Batch2D::from_rectangle(0.0, 0.0, 200.0, 200.0)],
29            vec![
30                Batch3D::from_box(-0.5, -0.5, -0.5, 1.0, 1.0, 1.0)
31                    .source(PixelSource::StaticTileIndex(0))
32                    .cull_mode(CullMode::Off)
33                    // Metallic material which is based on half of the
34                    // saturation of the pixel color
35                    .material(Material::new(
36                        MaterialRole::Metallic,
37                        MaterialModifier::Saturation,
38                        0.6,
39                        0.0,
40                    ))
41                    .with_computed_normals(),
42            ],
43        )
44        .lights(vec![
45            Light::new(LightType::Point)
46                .with_intensity(1.0)
47                .with_color([1.0, 1.0, 0.95])
48                .compile(),
49        ])
50        .background(Box::new(VGrayGradientShader::new()));
51
52        let assets = Assets::default().textures(vec![Tile::from_texture(Texture::from_image(
53            Path::new("images/logo.png"),
54        ))]);
55
56        let mut camera = D3OrbitCamera::new();
57        camera.set_parameter_f32("distance", 1.5);
58
59        Self {
60            camera,
61            scene,
62            start_time: Instant::now(),
63            assets,
64        }
65    }
examples/cube_shaded.rs (lines 104-106)
23    fn new() -> Self
24    where
25        Self: Sized,
26    {
27        let mut scene = Scene::from_static(
28            vec![Batch2D::from_rectangle(0.0, 0.0, 200.0, 200.0)],
29            vec![
30                Batch3D::from_box(-0.5, -0.5, -0.5, 1.0, 1.0, 1.0)
31                    .source(PixelSource::StaticTileIndex(0))
32                    .cull_mode(CullMode::Off)
33                    .ambient_color(Vec3::broadcast(0.3))
34                    .shader(0)
35                    .with_computed_normals(),
36            ],
37        )
38        .lights(vec![
39            Light::new(LightType::Point)
40                .with_intensity(1.0)
41                .with_color([1.0, 1.0, 0.95])
42                .compile(),
43        ])
44        .background(Box::new(VGrayGradientShader::new()));
45
46        scene.add_shader(
47            r#"
48            fn shade() {
49                // Procedural wood: concentric growth rings warped by turbulence + fine grain.
50                // Only the .x channel of textures is used (value channel).
51                let t = time * 0.0;
52
53                // Move and scale domain; center the rings roughly in the middle of each face.
54                let uv2 = uv / 3.0 - vec2(1.5);
55
56                // fBm turbulence (zero-mean) to warp the rings
57                let n1 = sample(uv2 + vec2(t, 0.0), "fbm_perlin");   // [0,1]
58                let n2 = sample(uv2 * 2.0 + vec2(0.0, t*0.7), "fbm_perlin");
59                let turb = 0.65 * n1 + 0.35 * n2;                       // [0,1]
60                let turb_zm = (turb - 0.5) * 2.0;                       // [-1,1]
61
62                // Radial distance from center (log cross-section look)
63                let r = length(uv2);
64
65                // Warp rings by turbulence (phase modulation)
66                let ring_freq = 10.0;            // number of rings
67                let ring_warp = 0.22;            // strength of warp
68                let rings = r + ring_warp * turb_zm;
69                let waves = sin(rings * ring_freq);
70
71                // Map sine to ring mask; sharpen valleys to make rings thinner
72                let rings_mask = pow(1.0 - abs(waves), 3.0);
73
74                // Fine longitudinal grain: high-frequency value noise stretched along X
75                let grain_uv = vec2(uv2.x * 8.0, uv2.y * 40.0);
76                let g = sample(grain_uv + vec2(0.0, t*0.5), "value");
77                let grain = (g - 0.5) * 2.0;     // zero-mean
78
79                // Base wood hues
80                let base_light = vec3(0.72, 0.52, 0.32);
81                let base_dark  = vec3(0.45, 0.30, 0.16);
82
83                // Mix light/dark by ring mask
84                color = mix(base_light, base_dark, rings_mask);
85
86                // Apply subtle anisotropic grain as a multiplicative zero-mean factor
87                color *= (1.0 + 0.06 * grain);
88
89                // Optional pore streaks (cathedrals): directional bands along Y with slight turbulence
90                let band = uv2.y + 0.15 * turb_zm;
91                let cathedral = pow(1.0 - abs(sin(band * 6.0)), 4.0);
92                color = mix(color, color * 0.9, cathedral * 0.2);
93
94                // Roughness varies: pores are rougher, rings smoother
95                roughness = 0.6 + cathedral * 0.3;
96
97                // 16 Colors
98                //let color_steps = 16.0;
99                //color = floor(color * color_steps) / color_steps;
100            }
101        "#,
102        );
103
104        let assets = Assets::default().textures(vec![Tile::from_texture(Texture::from_image(
105            Path::new("images/logo.png"),
106        ))]);
107
108        let mut camera = D3OrbitCamera::new();
109        camera.set_parameter_f32("distance", 1.5);
110
111        Self {
112            camera,
113            scene,
114            start_time: Instant::now(),
115            assets,
116        }
117    }

Trait Implementations§

Source§

impl Clone for Assets

Source§

fn clone(&self) -> Assets

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Default for Assets

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,