place core to start the game
This commit is contained in:
parent
3a25a1bd87
commit
1ecd054a31
8 changed files with 67 additions and 24 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -5310,6 +5310,7 @@ dependencies = [
|
|||
"bevy",
|
||||
"bevy_egui",
|
||||
"building",
|
||||
"building_core",
|
||||
"building_placement",
|
||||
"combat",
|
||||
"input",
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
(
|
||||
map: {
|
||||
MouseButton(Middle): [
|
||||
CameraOrbitEnable,
|
||||
],
|
||||
KeyCode(ShiftLeft): [
|
||||
MultiPlaceTower,
|
||||
],
|
||||
KeyCode(F1): [
|
||||
ToggleDebugUI,
|
||||
],
|
||||
MouseButton(Right): [
|
||||
PlaceTower,
|
||||
],
|
||||
MouseButton(Left): [
|
||||
CameraPanEnable,
|
||||
],
|
||||
MouseButton(Middle): [
|
||||
CameraOrbitEnable,
|
||||
],
|
||||
MouseScroll: [
|
||||
CameraZoom,
|
||||
],
|
||||
MouseButton(Left): [
|
||||
CameraPanEnable,
|
||||
KeyCode(F1): [
|
||||
ToggleDebugUI,
|
||||
],
|
||||
MouseMovementX: [
|
||||
CameraYaw,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
use bevy::prelude::*;
|
||||
use building::{BuildingInfo, BuildingPreview, Core, PREVIEW_ALPHA, PopulatePlacedBuilding};
|
||||
use combat::{Defense, Health, Range};
|
||||
use state::CoreState;
|
||||
use ui_range_indicator::CustomRangeIndicator;
|
||||
|
||||
pub struct BuildingCorePlugin;
|
||||
|
|
@ -22,6 +23,9 @@ struct CoreResources {
|
|||
info_entity: Entity,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct CorePreview;
|
||||
|
||||
const SIZE: UVec3 = UVec3::new(2, 2, 2);
|
||||
|
||||
fn register(
|
||||
|
|
@ -50,6 +54,7 @@ fn register(
|
|||
Visibility::Hidden,
|
||||
Mesh3d(mesh.clone()),
|
||||
MeshMaterial3d(preview_material),
|
||||
CorePreview,
|
||||
))
|
||||
.id();
|
||||
commands.entity(info).insert((
|
||||
|
|
@ -74,6 +79,7 @@ fn populate(
|
|||
trigger: Trigger<PopulatePlacedBuilding>,
|
||||
mut commands: Commands,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
mut next_core_state: ResMut<NextState<CoreState>>,
|
||||
res: Res<CoreResources>,
|
||||
) {
|
||||
if trigger.event().info != res.info_entity {
|
||||
|
|
@ -91,4 +97,5 @@ fn populate(
|
|||
..default()
|
||||
})),
|
||||
));
|
||||
next_core_state.set(CoreState::Placed);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ use bevy::{
|
|||
render::camera::Exposure,
|
||||
};
|
||||
use bevy_egui::PrimaryEguiContext;
|
||||
use building::{BuildingTypes, PlaceBuilding};
|
||||
use camera::ControlledCamera;
|
||||
use inhabitant::Inhabitant;
|
||||
use inhabitant_coranth::SpawnCoranth;
|
||||
|
|
@ -54,8 +53,6 @@ fn setup(
|
|||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
buildings: Res<BuildingTypes>,
|
||||
mut place_writer: EventWriter<PlaceBuilding>,
|
||||
mut coranth_writer: EventWriter<SpawnCoranth>,
|
||||
mut graveyard_writer: EventWriter<PlaceGraveyard>,
|
||||
) {
|
||||
|
|
@ -85,11 +82,6 @@ fn setup(
|
|||
|
||||
graveyard_writer.write(PlaceGraveyard(Vec3::new(-10., 0.25, -10.)));
|
||||
|
||||
place_writer.write(PlaceBuilding {
|
||||
info: buildings.info.get("Core").unwrap().0,
|
||||
location: IVec3 { x: 5, y: 0, z: 5 },
|
||||
});
|
||||
|
||||
// Light
|
||||
commands.spawn((
|
||||
DirectionalLight {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ impl Plugin for StatePlugin {
|
|||
.enable_state_scoped_entities::<AppState>()
|
||||
.add_sub_state::<GameState>()
|
||||
.add_sub_state::<BasePhaseState>()
|
||||
.add_sub_state::<CoreState>()
|
||||
.enable_state_scoped_entities::<GameState>()
|
||||
.add_computed_state::<Phase>()
|
||||
.configure_sets(
|
||||
|
|
@ -112,15 +113,29 @@ pub enum Phase {
|
|||
}
|
||||
|
||||
impl ComputedStates for Phase {
|
||||
type SourceStates = (BasePhaseState, GameState);
|
||||
type SourceStates = (BasePhaseState, GameState, CoreState);
|
||||
|
||||
fn compute(sources: Self::SourceStates) -> Option<Self> {
|
||||
match sources {
|
||||
(_, GameState::Loading) | (_, GameState::Paused) => None,
|
||||
(BasePhaseState::Execute { .. }, GameState::Running) => Some(Self::Execute),
|
||||
(BasePhaseState::Plan { .. }, GameState::Running) => Some(Self::Plan),
|
||||
(_, GameState::Loading, _) | (_, GameState::Paused, _) => None,
|
||||
(_, _, CoreState::Dead) | (_, _, CoreState::Unplaced) => None,
|
||||
(BasePhaseState::Execute { .. }, GameState::Running, CoreState::Placed) => {
|
||||
Some(Self::Execute)
|
||||
}
|
||||
(BasePhaseState::Plan { .. }, GameState::Running, CoreState::Placed) => {
|
||||
Some(Self::Plan)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Eq, PartialEq, Hash, SubStates)]
|
||||
#[source(AppState = AppState::Game)]
|
||||
pub enum CoreState {
|
||||
#[default]
|
||||
Unplaced,
|
||||
Placed,
|
||||
Dead,
|
||||
}
|
||||
|
||||
#[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone)]
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ resources = { path = "../resources" }
|
|||
building = { path = "../building" }
|
||||
input = { path = "../input" }
|
||||
building_placement = { path = "../building_placement" }
|
||||
building_core = { path = "../building_core" }
|
||||
upgrade = { path = "../upgrade" }
|
||||
combat = { path = "../combat" }
|
||||
|
||||
|
|
|
|||
|
|
@ -10,11 +10,12 @@ use bevy_egui::{
|
|||
egui::{self, Align2, RichText},
|
||||
};
|
||||
use building::{BuildingInfo, Core};
|
||||
use building_core::CorePreview;
|
||||
use building_placement::SelectBuildingPreview;
|
||||
use combat::Range;
|
||||
use input::{SelectEntity, Selected};
|
||||
use resources::{AvailableWorkers, Cost, ResourceDeposit, Resources, WorkedResourceDeposit};
|
||||
use state::{BasePhaseState, Phase};
|
||||
use state::{BasePhaseState, CoreState, Phase};
|
||||
use ui_state::GameUIState;
|
||||
use upgrade::{UnlockUpgrade, Upgradable, Upgrade};
|
||||
|
||||
|
|
@ -27,7 +28,10 @@ impl Plugin for UiIngamePlugin {
|
|||
.add_systems(
|
||||
EguiPrimaryContextPass,
|
||||
(
|
||||
side_panel.run_if(in_state(GameUIState::Default)),
|
||||
place_core
|
||||
.run_if(in_state(GameUIState::Default).and(in_state(CoreState::Unplaced))),
|
||||
side_panel
|
||||
.run_if(in_state(GameUIState::Default).and(in_state(CoreState::Placed))),
|
||||
plan_ui.run_if(in_state(GameUIState::Default).and(in_state(Phase::Plan))),
|
||||
execute_ui.run_if(in_state(GameUIState::Default).and(in_state(Phase::Execute))),
|
||||
transition_ui.run_if(
|
||||
|
|
@ -56,6 +60,7 @@ impl Plugin for UiIngamePlugin {
|
|||
}
|
||||
}
|
||||
|
||||
const VERY_LARGE_FONT_SIZE: f32 = 48.;
|
||||
const LARGE_FONT_SIZE: f32 = 24.;
|
||||
const FONT_SIZE: f32 = 16.;
|
||||
|
||||
|
|
@ -80,7 +85,7 @@ fn plan_ui(
|
|||
.anchor(Align2::CENTER_BOTTOM, [0., 0.])
|
||||
.show(ctx, |ui| {
|
||||
if ui
|
||||
.button(RichText::new("EXECUTE").size(LARGE_FONT_SIZE))
|
||||
.button(RichText::new("EXECUTE").size(VERY_LARGE_FONT_SIZE))
|
||||
.clicked()
|
||||
{
|
||||
next_phase.set(BasePhaseState::Execute {
|
||||
|
|
@ -334,3 +339,21 @@ fn side_panel(
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn place_core(
|
||||
mut contexts: EguiContexts,
|
||||
mut selected_preview_writer: EventWriter<SelectBuildingPreview>,
|
||||
core_preview: Single<Entity, With<CorePreview>>,
|
||||
) {
|
||||
let ctx = contexts.ctx_mut().unwrap();
|
||||
egui::Window::new("PlaceCore")
|
||||
.resizable(false)
|
||||
.collapsible(false)
|
||||
.title_bar(false)
|
||||
.anchor(Align2::CENTER_BOTTOM, [0., 0.])
|
||||
.show(ctx, |ui| {
|
||||
if ui.button(RichText::new("COLONIZE").size(64.)).clicked() {
|
||||
selected_preview_writer.write(SelectBuildingPreview(Some(*core_preview)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,11 +39,15 @@ fn pause_screen(mut contexts: EguiContexts) {
|
|||
|
||||
fn toggle_pause(
|
||||
state: Res<State<GameState>>,
|
||||
mut removed_cancellations: RemovedComponents<Cancellable>,
|
||||
mut next_state: ResMut<NextState<GameState>>,
|
||||
query: Query<(), With<Cancellable>>,
|
||||
) {
|
||||
if !query.is_empty() {
|
||||
// sometimes race condition can happen where the cancellable component gets cancelled before this system runs
|
||||
// instead of actually scheduling systems, I will just do this.
|
||||
if !query.is_empty() || !removed_cancellations.is_empty() {
|
||||
// cancelling takes priority over pausing
|
||||
removed_cancellations.clear();
|
||||
return;
|
||||
}
|
||||
let next = match state.get() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue