tile manager
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
name = "phos"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
build = "build.rs"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
||||
48
game/main/build.rs
Normal file
48
game/main/build.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use std::{
|
||||
env, fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
/// A helper function for recursively copying a directory.
|
||||
fn copy_dir<P, Q>(from: P, to: Q)
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
Q: AsRef<Path>,
|
||||
{
|
||||
let to = to.as_ref().to_path_buf();
|
||||
|
||||
for path in fs::read_dir(from).unwrap() {
|
||||
let path = path.unwrap().path();
|
||||
let to = to.clone().join(path.file_name().unwrap());
|
||||
|
||||
if path.is_file() {
|
||||
fs::copy(&path, to).unwrap();
|
||||
} else if path.is_dir() {
|
||||
if !to.exists() {
|
||||
fs::create_dir(&to).unwrap();
|
||||
}
|
||||
|
||||
copy_dir(&path, to);
|
||||
} else { /* Skip other content */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const COPY_DIR: &'static str = "assets";
|
||||
|
||||
fn main() {
|
||||
// Request the output directory
|
||||
let out = env::var("PROFILE").unwrap();
|
||||
let out = PathBuf::from(format!("../../target/{}/{}", out, COPY_DIR));
|
||||
|
||||
// If it is already in the output directory, delete it and start over
|
||||
if out.exists() {
|
||||
fs::remove_dir_all(&out).unwrap();
|
||||
}
|
||||
|
||||
// Create the out directory
|
||||
fs::create_dir(&out).unwrap();
|
||||
|
||||
// Copy the directory
|
||||
copy_dir(COPY_DIR, &out);
|
||||
}
|
||||
@@ -1,21 +1,22 @@
|
||||
use crate::prelude::*;
|
||||
use bevy::asset::LoadState;
|
||||
use bevy::pbr::{ExtendedMaterial};
|
||||
use bevy::pbr::ExtendedMaterial;
|
||||
use bevy::{pbr::CascadeShadowConfig, prelude::*};
|
||||
use camera_system::PhosCameraPlugin;
|
||||
use iyes_perf_ui::prelude::*;
|
||||
use world_generation::hex_utils::{offset_to_world, HexCoord};
|
||||
use world_generation::hex_utils::offset_to_world;
|
||||
use world_generation::{
|
||||
heightmap::generate_heightmap, mesh_generator::generate_chunk_mesh, prelude::*,
|
||||
};
|
||||
use crate::prelude::*;
|
||||
|
||||
pub struct PhosGamePlugin;
|
||||
|
||||
impl Plugin for PhosGamePlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_plugins(PhosCameraPlugin).add_plugins(MaterialPlugin::<
|
||||
ExtendedMaterial<StandardMaterial, ChunkMaterial>,
|
||||
>::default());
|
||||
app.add_plugins(PhosCameraPlugin)
|
||||
.add_plugins(MaterialPlugin::<
|
||||
ExtendedMaterial<StandardMaterial, ChunkMaterial>,
|
||||
>::default());
|
||||
app.add_systems(Startup, init_game)
|
||||
.add_systems(Startup, (load_textures, create_map).chain());
|
||||
app.add_systems(Update, (check_texture, spawn_map));
|
||||
@@ -51,10 +52,7 @@ fn init_game(mut commands: Commands) {
|
||||
commands.insert_resource(PhosMap::default());
|
||||
}
|
||||
|
||||
fn load_textures(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
) {
|
||||
fn load_textures(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
let main_tex = asset_server.load("textures/world/stack.png");
|
||||
commands.insert_resource(ChunkAtlas {
|
||||
handle: main_tex.clone(),
|
||||
@@ -80,42 +78,11 @@ fn check_texture(
|
||||
let array_layers = 7;
|
||||
image.reinterpret_stacked_2d_as_array(array_layers);
|
||||
|
||||
|
||||
atlas.is_loaded = true;
|
||||
map.ready = true;
|
||||
map.regenerate = true;
|
||||
}
|
||||
|
||||
fn draw_gizmos(mut gizmos: Gizmos, hm: Res<Map>) {
|
||||
gizmos.arrow(Vec3::ZERO, Vec3::Y * 1.5, Color::GREEN);
|
||||
gizmos.arrow(Vec3::ZERO, Vec3::Z * 1.5, Color::BLUE);
|
||||
gizmos.arrow(Vec3::ZERO, Vec3::X * 1.5, Color::RED);
|
||||
|
||||
let coord = HexCoord::from_grid_pos(64, 14);
|
||||
let ch = &hm.chunks[coord.to_chunk_index(hm.width) as usize];
|
||||
let h = ch.points[coord.to_chunk_local_index() as usize];
|
||||
gizmos.ray(coord.to_world(h), Vec3::Y, Color::RED);
|
||||
gizmos.ray(coord.to_world(h), Vec3::Z * 1.5, Color::BLUE);
|
||||
|
||||
// let t = coord.get_neighbor(5);
|
||||
// let h = ch.points[t.to_chunk_local_index() as usize];
|
||||
// gizmos.ray(t.to_world(h), Vec3::Y * 1., Color::PINK);
|
||||
let n = coord.get_neighbors();
|
||||
let nh = hm.get_neighbors(&coord);
|
||||
for i in 0..6 {
|
||||
let t = n[i];
|
||||
let h = nh[i];
|
||||
if h.is_none() {
|
||||
continue;
|
||||
}
|
||||
gizmos.ray(
|
||||
t.to_world(h.unwrap()),
|
||||
Vec3::Y * (i + 1) as f32,
|
||||
Color::CYAN,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn create_map(mut commands: Commands) {
|
||||
let heightmap = generate_heightmap(
|
||||
&GenerationConfig {
|
||||
@@ -216,4 +183,3 @@ fn spawn_map(
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user