Skip to content

Commit

Permalink
failed to load free dynotype tileset in absence of proprietary canari…
Browse files Browse the repository at this point in the history
… tileset
  • Loading branch information
peregrine-l committed Dec 21, 2023
1 parent a2ea724 commit eed4609
Show file tree
Hide file tree
Showing 8 changed files with 364 additions and 48 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ regex = "1.5.4"
serde_json = { version = "1.0" }
tiled = { version = "0.11.0", default-features = false }
rand = {version = "0.8.5", features = [ "alloc" ]}
fmt = "0.1.0"

[dev-dependencies.bevy]
version = "0.11"
Expand Down
Binary file added assets/Dinotype/dinotype.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Dinotype/dinotype_x2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use bevy_ecs_tilemap::prelude::*;

pub mod components;
pub mod map;
pub mod resources;
pub mod startup;


Expand All @@ -20,6 +21,7 @@ fn main() {
.set(ImagePlugin::default_nearest()),
)
.add_plugins(TilemapPlugin)
.add_systems(PreStartup, crate::startup::select_asset_pack)
.add_systems(Startup, crate::startup::startup)
.add_systems(Update, bevy::window::close_on_esc)
.run();
Expand Down
46 changes: 29 additions & 17 deletions src/map.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
use bevy::prelude::*;
use rand::prelude::*;
use bevy_ecs_tilemap::tiles::TileTextureIndex;
use crate::map::tiles::CANARI_TILES;
use rand::prelude::*;

use crate::resources::AssetPack;
use self::tiles::DINOTYPE_TILES;
pub mod tiles;

pub fn random_ground() -> TileTextureIndex {
let mut rng = rand::thread_rng();

let ground_tiles = [
(CANARI_TILES.get("black"), 20),
(CANARI_TILES.get("ground: 1 dot a"), 3),
(CANARI_TILES.get("ground: 1 dot b"), 3),
(CANARI_TILES.get("ground: 2 dots"), 2),
(CANARI_TILES.get("ground: 3 dots a"), 1),
(CANARI_TILES.get("ground: 3 dots b"), 1),
];
pub fn random_ground(pack: &Res<AssetPack>) -> TileTextureIndex {
let mut rng = rand::thread_rng();
let index: u32;

let coordinates =
ground_tiles
if pack.folder_name == "Dinotype" {
let ground_tiles = [
(DINOTYPE_TILES.get(&' '), 10),
(DINOTYPE_TILES.get(&'.'), 1)
];
index = 1; /* *ground_tiles
.choose_weighted(&mut rng, |item| { item.1 })
.unwrap().0.unwrap(); */
} else if pack.folder_name == "OneBitCanariPack" {
let ground_tiles = [
(CANARI_TILES.get("black"), 20),
(CANARI_TILES.get("ground: 1 dot a"), 3),
(CANARI_TILES.get("ground: 1 dot b"), 3),
(CANARI_TILES.get("ground: 2 dots"), 2),
(CANARI_TILES.get("ground: 3 dots a"), 1),
(CANARI_TILES.get("ground: 3 dots b"), 1),
];
let coordinates = *ground_tiles
.choose_weighted(&mut rng, |item| { item.1 })
.unwrap().0.unwrap();

TileTextureIndex((coordinates.0 as u32) + 16 * (coordinates.1 as u32))
}
index = (coordinates.0 as u32) + 16 * (coordinates.1 as u32);
} else { return TileTextureIndex(0); }
TileTextureIndex(index)
}
Loading

0 comments on commit eed4609

Please sign in to comment.