Skip to content

Commit 9e72420

Browse files
committed
load
1 parent b2b6f1b commit 9e72420

File tree

9 files changed

+102
-15
lines changed

9 files changed

+102
-15
lines changed

resources/beatmap/insane.ron

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:1eeb25b326a39e7318a10e3db5b6e99c37a23be967edeb5cbebeb9715e72fb08
3-
size 36
2+
oid sha256:59e6a1cc29021cd1ed7d3eea78775f26be328b4772f2a5a577f9689f5cb8f125
3+
size 83

src/bundle.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ use amethyst::{
33
ecs::prelude::DispatcherBuilder,
44
};
55

6+
use crate::systems::*;
7+
68
pub struct OsuBundle;
79

810
impl<'a, 'b> SystemBundle<'a, 'b> for OsuBundle {
911
fn build(self, builder: &mut DispatcherBuilder<'a, 'b>) -> bundle::Result<()> {
12+
builder.add(BeatmapSystem::new(), "beatmap_system", &[]);
1013
Ok(())
1114
}
1215
}

src/components/hitobject.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
use amethyst::ecs::prelude::{Component, DenseVecStorage};
22

3-
pub struct HitObject;
3+
#[derive(Clone)]
4+
pub struct HitObject {
5+
pub time: f64,
6+
pub kind: HitObjectKind,
7+
}
8+
9+
#[derive(Clone)]
10+
pub enum HitObjectKind {
11+
HitCircle,
12+
}
413

514
impl Component for HitObject {
615
type Storage = DenseVecStorage<Self>;

src/components/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
mod hitobject;
22

3-
pub use hitobject::HitObject;
3+
pub use hitobject::{HitObject, HitObjectKind};

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ mod state;
1010
mod systems;
1111

1212
use amethyst::{
13+
core::transform::TransformBundle,
1314
prelude::*,
1415
renderer::{DisplayConfig, DrawFlat2D, Pipeline, RenderBundle, Stage},
1516
ui::{DrawUi, UiBundle},
16-
core::transform::TransformBundle,
1717
utils::application_root_dir,
1818
};
1919

src/resources/hitcircle.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use amethyst::{assets::Handle, renderer::Mesh};
22

3+
use crate::components::HitObject as HitObjectComponent;
4+
35
#[derive(Clone)]
46
pub struct HitCircleResource {
57
pub hitcircle_mesh: Handle<Mesh>,
8+
pub component: HitObjectComponent,
69
}

src/resources/mod.rs

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,87 @@
11
mod hitcircle;
22

33
use amethyst::{
4-
assets::{AssetStorage, Loader},
4+
assets::{AssetStorage, Handle, Loader},
5+
core::nalgebra::{Vector2, Vector3},
56
ecs::prelude::World,
6-
renderer::{PngFormat, Texture, TextureMetadata},
7+
renderer::{Material, MaterialDefaults, Mesh, PngFormat, PosTex, Texture, TextureMetadata},
78
};
89

9-
fn load_single_texture_png(name: &'static str, world: &mut World) {
10+
use crate::components::{HitObject as HitObjectComponent, HitObjectKind};
11+
12+
use self::hitcircle::HitCircleResource;
13+
14+
fn create_png_vertices(left: f32, bottom: f32, right: f32, top: f32) -> Vec<PosTex> {
15+
vec![
16+
PosTex {
17+
position: Vector3::new(left, bottom, 0.0),
18+
tex_coord: Vector2::new(0.0, 0.0),
19+
},
20+
PosTex {
21+
position: Vector3::new(right, bottom, 0.0),
22+
tex_coord: Vector2::new(1.0, 0.0),
23+
},
24+
PosTex {
25+
position: Vector3::new(left, top, 0.0),
26+
tex_coord: Vector2::new(0.0, 1.0),
27+
},
28+
PosTex {
29+
position: Vector3::new(right, top, 0.0),
30+
tex_coord: Vector2::new(1.0, 1.0),
31+
},
32+
PosTex {
33+
position: Vector3::new(left, top, 0.),
34+
tex_coord: Vector2::new(0.0, 1.0),
35+
},
36+
PosTex {
37+
position: Vector3::new(right, bottom, 0.0),
38+
tex_coord: Vector2::new(1.0, 0.0),
39+
},
40+
]
41+
}
42+
43+
fn load_single_texture_png(
44+
name: &'static str,
45+
png_size: [f32; 2],
46+
world: &mut World,
47+
) -> (Handle<Mesh>, Material) {
1048
let loader = world.read_resource::<Loader>();
11-
loader.load(
49+
let albedo = loader.load(
1250
name,
1351
PngFormat,
1452
TextureMetadata::srgb_scale(),
1553
(),
1654
&world.read_resource::<AssetStorage<Texture>>(),
1755
);
56+
57+
let mat_defaults = world.read_resource::<MaterialDefaults>();
58+
let material = Material {
59+
albedo,
60+
..mat_defaults.0.clone()
61+
};
62+
63+
let vertices = create_png_vertices(0.0, 0.0, png_size[0], png_size[1]);
64+
let mesh = loader.load_from_data(
65+
vertices.into(),
66+
(),
67+
&world.read_resource::<AssetStorage<Mesh>>(),
68+
);
69+
(mesh, material)
70+
}
71+
72+
fn load_hitcircle_resource(world: &mut World) -> HitCircleResource {
73+
let (mesh, material) =
74+
load_single_texture_png("resources/skin/hitcircle.png", [128.0, 128.0], world);
75+
let resource = HitCircleResource {
76+
hitcircle_mesh: mesh,
77+
component: HitObjectComponent {
78+
time: 0.0,
79+
kind: HitObjectKind::HitCircle,
80+
}
81+
};
82+
world.add_resource(resource.clone());
83+
resource
1884
}
1985

2086
pub fn load_skin(world: &mut World) {
21-
load_single_texture_png("resources/skin/hitcircle.png", world);
2287
}

src/systems/beatmap.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
use amethyst::{ecs::prelude::*, core::timing::Time};
1+
use amethyst::{core::timing::Time, ecs::prelude::*};
22

33
use crate::components::HitObject;
44

55
pub struct BeatmapSystem;
66

7+
impl BeatmapSystem {
8+
pub fn new() -> Self {
9+
BeatmapSystem
10+
}
11+
}
12+
713
impl<'s> System<'s> for BeatmapSystem {
8-
type SystemData = (WriteStorage<'s, HitObject>, Read<'s, Time>,);
14+
type SystemData = (WriteStorage<'s, HitObject>, Read<'s, Time>);
915

10-
fn run(&mut self, (mut hitobjects, time,): Self::SystemData) {
11-
for hitobject in &mut hitobjects.join() {
12-
}
16+
fn run(&mut self, (mut hitobjects, time): Self::SystemData) {
17+
for hitobject in &mut hitobjects.join() {}
1318
}
1419
}

src/systems/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
mod beatmap;
2+
3+
pub use beatmap::BeatmapSystem;

0 commit comments

Comments
 (0)