Static World Gen and Display for the Overworld #5

Merged
msrd0 merged 21 commits from overworld-house-gen into main 2024-07-06 20:23:25 +00:00
5 changed files with 36 additions and 15 deletions
Showing only changes of commit 44b257c710 - Show all commits

View file

@ -65,11 +65,12 @@ impl AssetsWriter {
) -> io::Result<()> {
for (group_name, group) in &root.groups {
writeln!(file, "{indent}mod {group_name} {{")?;
writeln!(file, "{indent}\tuse super::*;")?;
write_assets_struct(file, group, &format!("{indent}\t"))?;
writeln!(file, "}}")?;
}
writeln!(file, "{indent}struct Asset {{")?;
writeln!(file, "{indent}pub struct Assets {{")?;
for asset_name in root.assets.keys() {
writeln!(
file,
@ -88,7 +89,7 @@ impl AssetsWriter {
writeln!(file, "{indent}impl Assets {{")?;
writeln!(
file,
"{indent}\tpub fn load(c: &mut comfy::EngineContext) {{"
"{indent}\tpub fn load(c: &mut comfy::EngineContext<'_>) {{"
)?;
for asset_const_name in root.assets.values() {
writeln!(file, "{indent}\t\tc.load_texture_from_bytes({asset_const_name:?}, {asset_const_name});")?;
@ -101,7 +102,7 @@ impl AssetsWriter {
writeln!(
file,
"{indent}const ASSETS: comfy::Lazy<Assets> = Lazy::new(|| Assets {{"
"{indent}pub static ASSETS: comfy::Lazy<Assets> = comfy::Lazy::new(|| Assets {{"
)?;
for (asset_name, asset_const_name) in &root.assets {
writeln!(
@ -113,7 +114,7 @@ impl AssetsWriter {
for group_name in root.groups.keys() {
writeln!(
file,
"{indent}\t{group_name}: {group_name}::ASSETS.force(),"
"{indent}\t{group_name}: comfy::Lazy::force(&{group_name}::ASSETS),"
)?;
}
writeln!(file, "{indent}}});")?;

View file

@ -1,7 +1,7 @@
use comfy::*;
use comfy::{draw_circle, vec2, EngineContext, RED};
pub fn draw(_state: &crate::State, _engine: &comfy::EngineContext) {
pub fn draw(_state: &crate::State, _engine: &EngineContext<'_>) {
draw_circle(vec2(0.0, 0.0), 0.5, RED, 0);
}
pub fn update(_state: &mut crate::State, _engine: &mut comfy::EngineContext) {}
pub fn update(_state: &mut crate::State, _engine: &mut EngineContext<'_>) {}

View file

@ -1,9 +1,9 @@
use comfy::*;
use comfy::{draw_circle, vec2, EngineContext, GREEN};
pub mod worldgen;
pub fn draw(_state: &crate::State, _engine: &comfy::EngineContext) {
pub fn draw(_state: &crate::State, _engine: &EngineContext<'_>) {
draw_circle(vec2(0.0, 0.0), 0.5, GREEN, 0);
}
pub fn update(_state: &mut crate::State, _engine: &mut comfy::EngineContext) {}
pub fn update(_state: &mut crate::State, _engine: &mut EngineContext<'_>) {}

View file

@ -5,14 +5,14 @@ use crate::{
State
};
pub fn update(state: &mut State, engine: &mut EngineContext) {
pub fn update(state: &mut State, engine: &mut EngineContext<'_>) {
match state.activity {
Activity::House => house::update(state, engine),
Activity::Overworld => overworld::update(state, engine)
}
}
pub fn draw(state: &State, engine: &EngineContext) {
pub fn draw(state: &State, engine: &EngineContext<'_>) {
match state.activity {
Activity::House => house::draw(state, engine),
Activity::Overworld => overworld::draw(state, engine)

View file

@ -1,13 +1,24 @@
#![warn(rust_2018_idioms)]
#![forbid(clippy::wildcard_imports, elided_lifetimes_in_paths, unsafe_code)]
mod assets {
include!(env!("ASSETS_RS"));
}
mod activities;
mod game;
use activities::{overworld::worldgen::Overworld, Activity};
use comfy::*;
use self::{
activities::{overworld::worldgen::Overworld, Activity},
assets::Assets
};
use comfy::{GameLoop, EngineState, EngineContext, GameConfig, init_game_config, run_comfy_main_async, pollster};
const GAME_NAME: &str = "Powercreep";
#[derive(Debug, Default)]
struct State {
setup_called: bool,
activity: Activity,
overworld: Overworld
}
@ -17,7 +28,12 @@ impl GameLoop for State {
Self::default()
}
fn update(&mut self, engine: &mut EngineContext) {
fn update(&mut self, engine: &mut EngineContext<'_>) {
if !self.setup_called {
setup(engine);
self.setup_called = true;
}
game::update(self, engine);
game::draw(self, engine);
}
@ -27,6 +43,10 @@ fn config(config: GameConfig) -> GameConfig {
config
}
fn setup(ctx: &mut EngineContext<'_>) {
Assets::load(ctx);
}
async fn run() {
init_game_config(GAME_NAME.to_string(), env!("CARGO_PKG_VERSION"), config);
let mut engine = EngineState::new();