Skip to content

Commit

Permalink
Working towards item generation and construction
Browse files Browse the repository at this point in the history
  • Loading branch information
ryankopf committed Aug 18, 2023
1 parent ca16785 commit ab67e32
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 108 deletions.
144 changes: 71 additions & 73 deletions src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ pub enum PersonalityTrait {
// Traits for People
Adventurous, Ambitious, Analytical, Airheaded, Artistic, Brave, Calm, Charismatic, Confident, Cowardly,
Creative, Curious, Charitable, Cynical, Dumb, Eccentric, Energetic, Empath, Empathetic, Enthusiastic,
Fearless, Friendly, Greedy, Impulsive, Jinxed, Loyal, Logical, Lucky, Mean, Mischievous,
Fearless, Friendly, Greedy, Human, Impulsive, Jinxed, Loyal, Logical, Lucky, Mean, Mischievous,
Nice, Optimistic, Patient, Pessimistic, Rebellious, Reliable, Sensitive, Shy, Smart, Stupid,
Technophile, Timid, Tolerant, Trusting, Violent, Weak, Workaholic, Witty, Outgoing,
// Traits for Creatures
Expand All @@ -597,7 +597,7 @@ pub struct GiveMeAName;
#[derive(Component)]
pub struct Plant {
pub growth: f32,
pub plant_type: PlantType,
pub plant_type: ItemType,
}
impl HoverNote for Plant {
fn hover_note(&self) -> String {
Expand All @@ -615,16 +615,14 @@ pub struct ZoneMarker;
#[derive(Component)]
pub struct Zone {
pub zone_type: ZoneType,
pub plant_type: Option<PlantType>,
pub item_type: Option<ItemType>,
pub item_type: ItemType,
}

impl Default for Zone {
fn default() -> Self {
Zone {
zone_type: ZoneType::Farm,
plant_type: Some(PlantType::Cabbage),
item_type: None,
item_type: ItemType::Cabbage
}
}
}
Expand All @@ -637,7 +635,7 @@ pub struct NearestEntity {

#[derive(Component, PartialEq, Copy, Clone, Debug)]
pub enum ZoneType {
Farm, Pasture, Storage, Fishing, Hospital, Party, Meeting
Farm, Pasture, Storage, Fishing, Hospital, Party, Meeting, Construction
}


Expand All @@ -651,72 +649,72 @@ pub enum Motivation { // Sorted in order of prioritization.
Crisis, Rage, Order, Danger, Hunger, Thirst, Tired, Injured, Sick, Bored, Happy, Sad, Angry, Lonely, Love, Fear, Hate, Work, Personality, Meander, Idle
}

#[derive(Component, PartialEq, Copy, Clone, Debug)]
pub enum PlantType {
Aloe,
Azalea,
Bush,
Cabbage,
CactusRound,
CactusUp,
Carrot,
CedarTree,
FlowerBush,
PineTree,
OakTree,
ThornBush,
Vine,
Weed,
}

impl PlantType {
pub fn is_edible(&self) -> bool {
matches!(self, PlantType::Cabbage)
}
pub fn sprite_row_and_col(&self) -> (usize, usize) {
match self {
PlantType::Aloe => (67, 57),
PlantType::Azalea => (67, 57),
PlantType::Bush => (67, 57),
PlantType::Cabbage => (94, 32),
PlantType::CactusRound => (67, 57),
PlantType::CactusUp => (67, 57),
PlantType::Carrot => (94, 31),
PlantType::CedarTree => (13, 15),
PlantType::PineTree => (13, 13),
PlantType::OakTree => (13, 14),
PlantType::ThornBush => (67, 57),
PlantType::FlowerBush => (67, 57),
PlantType::Vine => (67, 57),
PlantType::Weed => (67, 57),
}
}
pub fn sprite_index(&self) -> usize {
let (row, col) = self.sprite_row_and_col();
row * 64 + col
}
pub fn growth_speed(&self) -> f32 {
match self {
PlantType::Cabbage => 0.001,
_ => 0.01
}
}
pub fn is_forageable(&self) -> (Option<ItemType>, i32, ForageType) {
match self {
PlantType::Cabbage => (Some(ItemType::Cabbage), 1, ForageType::Once),
PlantType::Carrot => (Some(ItemType::Carrot), 1, ForageType::Once),
_ => (None, 0, ForageType::Once),
}
}
pub fn is_choppable(&self) -> (Option<ItemType>, i32) {
match self {
PlantType::PineTree => (Some(ItemType::PineLog), 1),
PlantType::OakTree => (Some(ItemType::OakLog), 1),
PlantType::CedarTree => (Some(ItemType::CedarLog), 1),
_ => (None, 0),
}
}
}
// #[derive(Component, PartialEq, Copy, Clone, Debug)]
// pub enum PlantType {
// Aloe,
// Azalea,
// Bush,
// Cabbage,
// CactusRound,
// CactusUp,
// Carrot,
// CedarTree,
// FlowerBush,
// PineTree,
// OakTree,
// ThornBush,
// Vine,
// Weed,
// }

// impl PlantType {
// pub fn is_edible(&self) -> bool {
// matches!(self, PlantType::Cabbage)
// }
// pub fn sprite_row_and_col(&self) -> (usize, usize) {
// match self {
// PlantType::Aloe => (67, 57),
// PlantType::Azalea => (67, 57),
// PlantType::Bush => (67, 57),
// PlantType::Cabbage => (94, 32),
// PlantType::CactusRound => (67, 57),
// PlantType::CactusUp => (67, 57),
// PlantType::Carrot => (94, 31),
// PlantType::CedarTree => (13, 15),
// PlantType::PineTree => (13, 13),
// PlantType::OakTree => (13, 14),
// PlantType::ThornBush => (67, 57),
// PlantType::FlowerBush => (67, 57),
// PlantType::Vine => (67, 57),
// PlantType::Weed => (67, 57),
// }
// }
// pub fn sprite_index(&self) -> usize {
// let (row, col) = self.sprite_row_and_col();
// row * 64 + col
// }
// pub fn growth_speed(&self) -> f32 {
// match self {
// PlantType::Cabbage => 0.001,
// _ => 0.01
// }
// }
// pub fn is_forageable(&self) -> (Option<ItemType>, i32, ForageType) {
// match self {
// PlantType::Cabbage => (Some(ItemType::Cabbage), 1, ForageType::Once),
// PlantType::Carrot => (Some(ItemType::Carrot), 1, ForageType::Once),
// _ => (None, 0, ForageType::Once),
// }
// }
// pub fn is_choppable(&self) -> (Option<ItemType>, i32) {
// match self {
// PlantType::PineTree => (Some(ItemType::PineLog), 1),
// PlantType::OakTree => (Some(ItemType::OakLog), 1),
// PlantType::CedarTree => (Some(ItemType::CedarLog), 1),
// _ => (None, 0),
// }
// }
// }

#[derive(Component, PartialEq, Copy, Clone, Debug)]
pub enum ForageType {
Expand Down
4 changes: 2 additions & 2 deletions src/initializations/biome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ impl Plugin for BiomePlugin {
pub fn starting_biome() -> Biome {
Biome {
name: "Forest".to_string(),
plants: vec![PlantType::Cabbage, PlantType::Carrot, PlantType::PineTree, PlantType::PineTree, PlantType::PineTree, PlantType::PineTree, PlantType::PineTree,
PlantType::CedarTree, PlantType::ThornBush, PlantType::Weed, PlantType::CactusRound],
plants: vec![ItemType::Cabbage, ItemType::Carrot, ItemType::PineTree, ItemType::PineTree, ItemType::PineTree, ItemType::PineTree, ItemType::PineTree,
ItemType::CedarTree, ItemType::ThornBush, ItemType::Weed, ItemType::CactusRound],
plant_scarcity: vec![1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
plant_overall_scarcity: 10,
tiles: vec![TileType::Grass, TileType::Grass, TileType::Grass, TileType::Grass, TileType::Grass, TileType::Grass, TileType::Grass,
Expand Down
2 changes: 1 addition & 1 deletion src/initializations/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn startup(
if plant_type.is_forageable().0.is_some() && growth > 0.5 {
commands.entity(plant).insert(Foragable);
}
if [PlantType::OakTree,PlantType::PineTree].contains(&plant_type) && growth > 0.5 {
if plant_type.is_choppable().0.is_some() && growth > 0.5 {
commands.entity(plant).insert(Choppable);
}
}
Expand Down
30 changes: 24 additions & 6 deletions src/interface/game_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,31 +213,49 @@ pub fn game_ui_click(
2 => {
dragging.looking_for = SelectableType::Zoning;
dragging.zone_type = ZoneType::Farm;
dragging.plant_type = PlantType::Cabbage;
dragging.item_type = ItemType::Cabbage;
},
3 => {
dragging.looking_for = SelectableType::Zoning;
dragging.zone_type = ZoneType::Farm;
dragging.plant_type = PlantType::PineTree;
dragging.item_type = ItemType::PineTree;
},
4 => {
dragging.looking_for = SelectableType::Zoning;
dragging.zone_type = ZoneType::Farm;
dragging.plant_type = PlantType::OakTree;
dragging.item_type = ItemType::OakTree;
},
5 => {
dragging.looking_for = SelectableType::Zoning;
dragging.zone_type = ZoneType::Farm;
dragging.plant_type = PlantType::CedarTree;
dragging.item_type = ItemType::CedarTree;
},
_ => { },
}
}
MenuStates::Zone => {
menu_state.state = MenuStates::Home;
match button_index {
_ => {
dragging.looking_for = SelectableType::Nothing;
menu_state.state = MenuStates::Home;
},
}
}
MenuStates::Build => {
menu_state.state = MenuStates::Home;
match button_index {
1 => {
dragging.looking_for = SelectableType::Unzoning;
},
2 => {
dragging.looking_for = SelectableType::Zoning;
dragging.zone_type = ZoneType::Construction;
dragging.item_type = ItemType::WallWood;
},
_ => {
dragging.looking_for = SelectableType::Nothing;
menu_state.state = MenuStates::Home;
},
}
}
MenuStates::Craft => {
menu_state.state = MenuStates::Home;
Expand Down
61 changes: 50 additions & 11 deletions src/objects.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bevy::prelude::*;
use crate::prelude::*;

#[derive(Component)]
pub struct Object {
Expand All @@ -20,8 +21,6 @@ enum ItemGroup {

#[derive(Component, PartialEq, Copy, Clone, Debug)]
pub enum ItemType {
Cabbage,
Carrot,
CedarLog,
PineLog,
OakLog,
Expand Down Expand Up @@ -80,13 +79,25 @@ pub enum ItemType {
LeafyDebris3,
LeafyDebris4,
WallWood,
Aloe,
Azalea,
Bush,
Cabbage,
CactusRound,
CactusUp,
Carrot,
CedarTree,
FlowerBush,
PineTree,
OakTree,
ThornBush,
Vine,
Weed,
}

impl ItemType {
pub fn sprite_row_and_col(&self) -> (usize, usize) {
match self {
ItemType::Cabbage => (94, 33),
ItemType::Carrot => (94, 24),
ItemType::CedarLog => (94, 30),
ItemType::PineLog => (94, 30),
ItemType::OakLog => (94, 30),
Expand Down Expand Up @@ -145,26 +156,54 @@ impl ItemType {
ItemType::LeafyDebris3 => (50, 17),
ItemType::LeafyDebris4 => (50, 18),
ItemType::WallWood => (16, 3),
ItemType::Aloe => (67, 57),
ItemType::Azalea => (67, 57),
ItemType::Bush => (67, 57),
ItemType::Cabbage => (94, 32),
ItemType::CactusRound => (67, 57),
ItemType::CactusUp => (67, 57),
ItemType::Carrot => (94, 31),
ItemType::CedarTree => (13, 15),
ItemType::PineTree => (13, 13),
ItemType::OakTree => (13, 14),
ItemType::ThornBush => (67, 57),
ItemType::FlowerBush => (67, 57),
ItemType::Vine => (67, 57),
ItemType::Weed => (67, 57),
}
}
pub fn sprite_index(&self) -> usize {
let (row, col) = self.sprite_row_and_col();
row * 64 + col
}
pub fn growth_speed(&self) -> f32 {
match self {
ItemType::Cabbage => 0.001,
_ => 0.01
}
}
pub fn is_forageable(&self) -> (Option<ItemType>, i32, ForageType) {
match self {
ItemType::Cabbage => (Some(ItemType::Cabbage), 1, ForageType::Once),
ItemType::Carrot => (Some(ItemType::Carrot), 1, ForageType::Once),
_ => (None, 0, ForageType::Once),
}
}
pub fn is_choppable(&self) -> (Option<ItemType>, i32) {
match self {
ItemType::PineTree => (Some(ItemType::PineLog), 1),
ItemType::OakTree => (Some(ItemType::OakLog), 1),
ItemType::CedarTree => (Some(ItemType::CedarLog), 1),
_ => (None, 0),
}
}
pub fn nutrition(&self) -> f32 {
match self {
ItemType::Cabbage => 10.0,
ItemType::Carrot => 10.0,
_ => 0.0,
}
}
// pub fn spoilage(&self) -> f32 {
// match self {
// ItemType::Cabbage => 1.0,
// ItemType::Carrot => 1.0,
// _ => 0.0,
// }
// }
pub fn spoilage_rate(&self) -> f32 {
match self {
ItemType::Cabbage => 0.1,
Expand Down
2 changes: 1 addition & 1 deletion src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub use super::components::{
GiveMeAName, HasName, HasNameShown, HighlightBox, Highlighted, HoverNote, InfoPanel, InGameButton, IsName,
Logs, MainMenuOverlay, MapTile, MenuStates, MonsterGenerator, Motivation, MoveRandom,
MoveTowardsNearestAttackable, MoveTowardsTarget, NearestEntity, Need, Nest,
Order, Pathing, PauseOverlay, PersonalityTrait, PhysicalBody, Plant, PlantType, Position,
Order, Pathing, PauseOverlay, PersonalityTrait, PhysicalBody, Plant, Position,
SelectableType, SetNest, Skillset, Skill, SizeXYZ, StrikeType,
Targeting, Task, TemporaryVisualElement, TextName, TileType, WorkMarker, WorkTarget, Zone, ZoneMarker, ZoneType,
};
Expand Down
Loading

0 comments on commit ab67e32

Please sign in to comment.