use std::path::Path; use bevy::color::palettes::css; use bevy::math::Affine3A; use bevy::prelude::*; use bevy::utils::HashSet; use bevy_egui::{egui, EguiPlugin}; use bevy_yoleck::vpeol::prelude::*; use bevy_yoleck::{prelude::*, YoleckEditableLevels}; use serde::{Deserialize, Serialize}; fn main() { let mut app = App::new(); app.add_plugins(DefaultPlugins); let level = if cfg!(target_arch = "wasm32") { Some("entry.yol".to_owned()) } else { std::env::args().nth(1) }; app.add_plugins(EguiPlugin); if let Some(level) = level { app.add_plugins(YoleckPluginForGame); app.add_plugins(Vpeol2dPluginForGame); app.add_systems( Startup, move |asset_server: Res, mut commands: Commands| { commands.spawn(YoleckLoadLevel( asset_server.load(Path::new("levels_doors").join(&level)), )); }, ); } else { app.add_plugins(YoleckPluginForEditor); app.add_plugins(Vpeol2dPluginForEditor); app.add_plugins(VpeolSelectionCuePlugin::default()); app.insert_resource(bevy_yoleck::YoleckEditorLevelsDirectoryPath( Path::new(".").join("assets").join("levels_doors"), )); } app.add_systems(Startup, setup_camera); app.add_yoleck_entity_type({ YoleckEntityType::new("Player") .with::() .insert_on_init(|| IsPlayer) }); app.add_systems(YoleckSchedule::Populate, populate_player); app.add_yoleck_entity_type({ YoleckEntityType::new("FloatingText") .with::() .with::() .with::() }); app.add_yoleck_edit_system(edit_text); app.add_systems(YoleckSchedule::Populate, populate_text); app.add_yoleck_entity_type({ YoleckEntityType::new("Doorway") .with::() .with::() .with::() }); app.add_yoleck_edit_system(edit_doorway_rotation); app.add_yoleck_edit_system(edit_doorway); app.add_systems(YoleckSchedule::Populate, populate_doorway); app.add_systems(Update, set_doorways_sprite_index); app.add_systems( YoleckSchedule::LevelLoaded, ( handle_player_entity_when_level_loads, position_level_from_opened_door, ), ); app.add_systems( Update, ( control_camera, control_player, handle_door_opening, close_old_doors, ) .run_if(in_state(YoleckEditorState::GameActive)), ); app.run(); } fn setup_camera(mut commands: Commands) { let mut camera = Camera2dBundle::default(); camera.transform.translation.z = 100.0; camera.transform.scale *= 2.0 * (Vec3::X + Vec3::Y) + Vec3::Z; commands .spawn(camera) .insert(VpeolCameraState::default()) .insert(Vpeol2dCameraControl::default()); } #[derive(Component)] struct IsPlayer; #[derive(Clone, PartialEq, Serialize, Deserialize)] struct Player { #[serde(default)] position: Vec2, #[serde(default)] rotation: f32, } fn populate_player( mut populate: YoleckPopulate<(), With>, asset_server: Res, mut texture_cache: Local>>, ) { populate.populate(|_ctx, mut cmd, ()| { cmd.insert((SpriteBundle { sprite: Sprite { custom_size: Some(Vec2::new(100.0, 100.0)), ..Default::default() }, texture: texture_cache .get_or_insert_with(|| asset_server.load("sprites/player.png")) .clone(), ..Default::default() },)); }); } fn control_camera( player_query: Query<&GlobalTransform, With>, mut camera_query: Query<&mut Transform, With>, time: Res