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
[HW] Add config file for Character class #56
Conversation
base: 12 | ||
increase: 2 | ||
distance: | ||
Near: 9 |
There was a problem hiding this comment.
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:
- have a standalone field like
type: near
that gets translated to the group the enemies end up in - have sublists to group the enemies, e.g.
enemies:
- near:
- wolf: ...
- rat: ...
- middle:
- ...
- (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: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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)?; |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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
No description provided.