This commit is contained in:
LunarAkai 2025-08-01 00:31:47 +02:00
commit 33440da8f7
10 changed files with 135 additions and 21 deletions

View file

@ -0,0 +1,69 @@
use moonhare_window::{window_config, winit_window::{self, WinitWindow}};
use crate::{basic::node::Node, Game};
#[derive(Debug)]
pub struct GameWindow {
pub title: &'static str,
pub width: u32,
pub height: u32,
pub visble: bool,
pub decorations: bool,
pub winit_window: Option<WinitWindow>,
}
impl Node for GameWindow {
}
impl Default for GameWindow {
fn default() -> Self {
Self {
title: "window",
width: default_game_window_width(),
height: default_game_window_height(),
visble: default_game_window_visibility(),
decorations: default_game_window_decorations(),
winit_window: None,
}
}
}
impl GameWindow {
pub fn create() -> Self {
let mut window_config = window_config::WindowConfig::default();
moonhare_log::info(format!("creating window with config {:?}", window_config));
let mut window = Self::default();
window_config.title = window.title.to_owned();
window_config.width = window.width;
window_config.height = window.height;
window_config.visble = window.visble;
window_config.decorations = window.decorations;
let winit = winit_window::WinitWindow::new(window_config);
window.winit_window = Some(winit);
// todo: tell winit to create a window for us
moonhare_log::info(format!("created window {:?}", window));
window
}
}
fn default_game_window_title() -> String {
"Moonhare Engine".to_owned()
}
fn default_game_window_width() -> u32 {
1280
}
fn default_game_window_height() -> u32 {
720
}
fn default_game_window_visibility() -> bool {
true
}
fn default_game_window_decorations() -> bool {
true
}

View file

@ -1,2 +1,2 @@
pub mod node;
pub mod window;
pub mod game_window;

View file

@ -1,10 +0,0 @@
use crate::basic::{node::Node};
pub struct GameWindow {
}
impl Node for GameWindow {
}

View file

@ -1,15 +1,43 @@
//! Base functionality for a Moonhare Game Engine Project
use moonhare_log::*;
use crate::basic::game_window::GameWindow;
pub mod basic;
/// Only one Game may exist per project
#[derive(Debug)]
pub struct Game {
pub name: String
pub name: String,
pub primary_window: Option<GameWindow>,
}
impl Default for Game {
fn default() -> Self {
Self {
name: default_game_name()
name: default_game_name(),
primary_window: None,
}
}
}
impl Game {
pub fn new() -> Self {
Game::default()
}
pub fn run(&self) {
info("Running Game...");
loop {
}
}
pub fn add_window(&mut self) {
moonhare_log::info(format!("Adding window to {:?}", self));
if self.primary_window.is_none() {
moonhare_log::trace("Primary Window is none");
self.primary_window = Some(GameWindow::create());
}
}
}