Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HW] Add config file for Character class #56

Closed

Conversation

juanbono
Copy link

No description provided.

@juanbono juanbono changed the base branch from main to hackweek_2021 June 11, 2021 14:13
base: 12
increase: 2
distance:
Near: 9
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we shouldn't have to specify the distance like this (for one the number is not used). We should consider:

  1. have a standalone field like type: near that gets translated to the group the enemies end up in
  2. have sublists to group the enemies, e.g.
enemies:
  -  near:
    - wolf: ...
    - rat: ...
  - middle:
    - ...
  1. (if it's easier to implement) just skip the enemy grouping for now and have it hardcoded in the code.

@@ -0,0 +1,216 @@
hero:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider this shorter format:

player:
  - hero:
      hp: [30, 7]
      str: [12, 3]
      spd: [11, 2]
enemy:
  - rat:
      type: common
      hp: [10, 3]
      str: [5, 2] 
      spd: [16, 2]
  - wolf:
      type: common
      hp: [15, 3]
      strength: [8, 2]
      speed: [12, 2]
  - skeleton:
      type: rare
      hp: [30, 3]
      str: [10, 2]
      spd: [10, 2]
  - balrog:
      type: legendary
      hp: [200, 3]
      str: [200, 2]
      spd: [14, 2]

In addition to being shorter, you can keep the shorter Stat struct

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, i'm working on this :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!


impl CharacterConfig {
pub fn load(file: path::PathBuf) -> Result<Self, Box<dyn std::error::Error>> {
let f = fs::File::open(file)?;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing that's kind of important for this feature is that we shouldn't force the user to setup their own config file (we let them do it if they want, but we need to fallback to the default definition).

This means we need to explore how to package the yaml with default classes into the binary. The approach I was thinking of is using include_bytes or some crate with a similar effect. Then we look for the custom classes file at a known location, e.g. ~/.rpg/config.yml but if that is missing we use the defaults.

@@ -44,6 +45,7 @@ impl Game {
pub fn load() -> Result<Self, Error> {
let data = fs::read(data_file()).or(Err(Error::NoDataFile))?;
let game: Game = bincode::deserialize(&data).unwrap();
let _config = character::CharacterConfig::load(config_file());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider doing this directly in main, so tha game module doesn't need to know about it

@facundoolano facundoolano deleted the branch facundoolano:hackweek_2021 June 17, 2021 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants