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",
|
||||||
"bevy_egui",
|
"bevy_egui",
|
||||||
"building",
|
"building",
|
||||||
|
"building_core",
|
||||||
"building_placement",
|
"building_placement",
|
||||||
"combat",
|
"combat",
|
||||||
"input",
|
"input",
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,22 @@
|
||||||
(
|
(
|
||||||
map: {
|
map: {
|
||||||
MouseButton(Middle): [
|
|
||||||
CameraOrbitEnable,
|
|
||||||
],
|
|
||||||
KeyCode(ShiftLeft): [
|
KeyCode(ShiftLeft): [
|
||||||
MultiPlaceTower,
|
MultiPlaceTower,
|
||||||
],
|
],
|
||||||
KeyCode(F1): [
|
|
||||||
ToggleDebugUI,
|
|
||||||
],
|
|
||||||
MouseButton(Right): [
|
MouseButton(Right): [
|
||||||
PlaceTower,
|
PlaceTower,
|
||||||
],
|
],
|
||||||
|
MouseButton(Left): [
|
||||||
|
CameraPanEnable,
|
||||||
|
],
|
||||||
|
MouseButton(Middle): [
|
||||||
|
CameraOrbitEnable,
|
||||||
|
],
|
||||||
MouseScroll: [
|
MouseScroll: [
|
||||||
CameraZoom,
|
CameraZoom,
|
||||||
],
|
],
|
||||||
MouseButton(Left): [
|
KeyCode(F1): [
|
||||||
CameraPanEnable,
|
ToggleDebugUI,
|
||||||
],
|
],
|
||||||
MouseMovementX: [
|
MouseMovementX: [
|
||||||
CameraYaw,
|
CameraYaw,
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use building::{BuildingInfo, BuildingPreview, Core, PREVIEW_ALPHA, PopulatePlacedBuilding};
|
use building::{BuildingInfo, BuildingPreview, Core, PREVIEW_ALPHA, PopulatePlacedBuilding};
|
||||||
use combat::{Defense, Health, Range};
|
use combat::{Defense, Health, Range};
|
||||||
|
use state::CoreState;
|
||||||
use ui_range_indicator::CustomRangeIndicator;
|
use ui_range_indicator::CustomRangeIndicator;
|
||||||
|
|
||||||
pub struct BuildingCorePlugin;
|
pub struct BuildingCorePlugin;
|
||||||
|
|
@ -22,6 +23,9 @@ struct CoreResources {
|
||||||
info_entity: Entity,
|
info_entity: Entity,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct CorePreview;
|
||||||
|
|
||||||
const SIZE: UVec3 = UVec3::new(2, 2, 2);
|
const SIZE: UVec3 = UVec3::new(2, 2, 2);
|
||||||
|
|
||||||
fn register(
|
fn register(
|
||||||
|
|
@ -50,6 +54,7 @@ fn register(
|
||||||
Visibility::Hidden,
|
Visibility::Hidden,
|
||||||
Mesh3d(mesh.clone()),
|
Mesh3d(mesh.clone()),
|
||||||
MeshMaterial3d(preview_material),
|
MeshMaterial3d(preview_material),
|
||||||
|
CorePreview,
|
||||||
))
|
))
|
||||||
.id();
|
.id();
|
||||||
commands.entity(info).insert((
|
commands.entity(info).insert((
|
||||||
|
|
@ -74,6 +79,7 @@ fn populate(
|
||||||
trigger: Trigger<PopulatePlacedBuilding>,
|
trigger: Trigger<PopulatePlacedBuilding>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
|
mut next_core_state: ResMut<NextState<CoreState>>,
|
||||||
res: Res<CoreResources>,
|
res: Res<CoreResources>,
|
||||||
) {
|
) {
|
||||||
if trigger.event().info != res.info_entity {
|
if trigger.event().info != res.info_entity {
|
||||||
|
|
@ -91,4 +97,5 @@ fn populate(
|
||||||
..default()
|
..default()
|
||||||
})),
|
})),
|
||||||
));
|
));
|
||||||
|
next_core_state.set(CoreState::Placed);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ use bevy::{
|
||||||
render::camera::Exposure,
|
render::camera::Exposure,
|
||||||
};
|
};
|
||||||
use bevy_egui::PrimaryEguiContext;
|
use bevy_egui::PrimaryEguiContext;
|
||||||
use building::{BuildingTypes, PlaceBuilding};
|
|
||||||
use camera::ControlledCamera;
|
use camera::ControlledCamera;
|
||||||
use inhabitant::Inhabitant;
|
use inhabitant::Inhabitant;
|
||||||
use inhabitant_coranth::SpawnCoranth;
|
use inhabitant_coranth::SpawnCoranth;
|
||||||
|
|
@ -54,8 +53,6 @@ fn setup(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
buildings: Res<BuildingTypes>,
|
|
||||||
mut place_writer: EventWriter<PlaceBuilding>,
|
|
||||||
mut coranth_writer: EventWriter<SpawnCoranth>,
|
mut coranth_writer: EventWriter<SpawnCoranth>,
|
||||||
mut graveyard_writer: EventWriter<PlaceGraveyard>,
|
mut graveyard_writer: EventWriter<PlaceGraveyard>,
|
||||||
) {
|
) {
|
||||||
|
|
@ -85,11 +82,6 @@ fn setup(
|
||||||
|
|
||||||
graveyard_writer.write(PlaceGraveyard(Vec3::new(-10., 0.25, -10.)));
|
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
|
// Light
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
DirectionalLight {
|
DirectionalLight {
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ impl Plugin for StatePlugin {
|
||||||
.enable_state_scoped_entities::<AppState>()
|
.enable_state_scoped_entities::<AppState>()
|
||||||
.add_sub_state::<GameState>()
|
.add_sub_state::<GameState>()
|
||||||
.add_sub_state::<BasePhaseState>()
|
.add_sub_state::<BasePhaseState>()
|
||||||
|
.add_sub_state::<CoreState>()
|
||||||
.enable_state_scoped_entities::<GameState>()
|
.enable_state_scoped_entities::<GameState>()
|
||||||
.add_computed_state::<Phase>()
|
.add_computed_state::<Phase>()
|
||||||
.configure_sets(
|
.configure_sets(
|
||||||
|
|
@ -112,16 +113,30 @@ pub enum Phase {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ComputedStates for Phase {
|
impl ComputedStates for Phase {
|
||||||
type SourceStates = (BasePhaseState, GameState);
|
type SourceStates = (BasePhaseState, GameState, CoreState);
|
||||||
|
|
||||||
fn compute(sources: Self::SourceStates) -> Option<Self> {
|
fn compute(sources: Self::SourceStates) -> Option<Self> {
|
||||||
match sources {
|
match sources {
|
||||||
(_, GameState::Loading) | (_, GameState::Paused) => None,
|
(_, GameState::Loading, _) | (_, GameState::Paused, _) => None,
|
||||||
(BasePhaseState::Execute { .. }, GameState::Running) => Some(Self::Execute),
|
(_, _, CoreState::Dead) | (_, _, CoreState::Unplaced) => None,
|
||||||
(BasePhaseState::Plan { .. }, GameState::Running) => Some(Self::Plan),
|
(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)]
|
#[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone)]
|
||||||
pub enum GameSystemSet {
|
pub enum GameSystemSet {
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ resources = { path = "../resources" }
|
||||||
building = { path = "../building" }
|
building = { path = "../building" }
|
||||||
input = { path = "../input" }
|
input = { path = "../input" }
|
||||||
building_placement = { path = "../building_placement" }
|
building_placement = { path = "../building_placement" }
|
||||||
|
building_core = { path = "../building_core" }
|
||||||
upgrade = { path = "../upgrade" }
|
upgrade = { path = "../upgrade" }
|
||||||
combat = { path = "../combat" }
|
combat = { path = "../combat" }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,12 @@ use bevy_egui::{
|
||||||
egui::{self, Align2, RichText},
|
egui::{self, Align2, RichText},
|
||||||
};
|
};
|
||||||
use building::{BuildingInfo, Core};
|
use building::{BuildingInfo, Core};
|
||||||
|
use building_core::CorePreview;
|
||||||
use building_placement::SelectBuildingPreview;
|
use building_placement::SelectBuildingPreview;
|
||||||
use combat::Range;
|
use combat::Range;
|
||||||
use input::{SelectEntity, Selected};
|
use input::{SelectEntity, Selected};
|
||||||
use resources::{AvailableWorkers, Cost, ResourceDeposit, Resources, WorkedResourceDeposit};
|
use resources::{AvailableWorkers, Cost, ResourceDeposit, Resources, WorkedResourceDeposit};
|
||||||
use state::{BasePhaseState, Phase};
|
use state::{BasePhaseState, CoreState, Phase};
|
||||||
use ui_state::GameUIState;
|
use ui_state::GameUIState;
|
||||||
use upgrade::{UnlockUpgrade, Upgradable, Upgrade};
|
use upgrade::{UnlockUpgrade, Upgradable, Upgrade};
|
||||||
|
|
||||||
|
|
@ -27,7 +28,10 @@ impl Plugin for UiIngamePlugin {
|
||||||
.add_systems(
|
.add_systems(
|
||||||
EguiPrimaryContextPass,
|
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))),
|
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))),
|
execute_ui.run_if(in_state(GameUIState::Default).and(in_state(Phase::Execute))),
|
||||||
transition_ui.run_if(
|
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 LARGE_FONT_SIZE: f32 = 24.;
|
||||||
const FONT_SIZE: f32 = 16.;
|
const FONT_SIZE: f32 = 16.;
|
||||||
|
|
||||||
|
|
@ -80,7 +85,7 @@ fn plan_ui(
|
||||||
.anchor(Align2::CENTER_BOTTOM, [0., 0.])
|
.anchor(Align2::CENTER_BOTTOM, [0., 0.])
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
if ui
|
if ui
|
||||||
.button(RichText::new("EXECUTE").size(LARGE_FONT_SIZE))
|
.button(RichText::new("EXECUTE").size(VERY_LARGE_FONT_SIZE))
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
next_phase.set(BasePhaseState::Execute {
|
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(
|
fn toggle_pause(
|
||||||
state: Res<State<GameState>>,
|
state: Res<State<GameState>>,
|
||||||
|
mut removed_cancellations: RemovedComponents<Cancellable>,
|
||||||
mut next_state: ResMut<NextState<GameState>>,
|
mut next_state: ResMut<NextState<GameState>>,
|
||||||
query: Query<(), With<Cancellable>>,
|
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
|
// cancelling takes priority over pausing
|
||||||
|
removed_cancellations.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let next = match state.get() {
|
let next = match state.get() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue