-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add provinces, dynasties, religions, holdings and expand alive data #19
Draft
clemux
wants to merge
5
commits into
rakaly:master
Choose a base branch
from
clemux:extend_models
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,44 @@ | ||
use std::env; | ||
|
||
use ck3save::{models::Gamestate, Ck3File, EnvTokens}; | ||
use serde::Deserialize; | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let args: Vec<String> = env::args().collect(); | ||
let data = std::fs::read(&args[1])?; | ||
let file = Ck3File::from_slice(&data)?; | ||
let mut zip_sink = Vec::new(); | ||
let file = file.parse(&mut zip_sink)?; | ||
let save: Gamestate = file.deserializer(&EnvTokens).deserialize()?; | ||
print!("{:#?}", save.meta_data.version); | ||
let deserializer = file.deserializer(&EnvTokens); | ||
let result: Result<Gamestate, _> = serde_path_to_error::deserialize(deserializer); | ||
match result { | ||
Ok(_) => panic!("expected a type error"), | ||
Err(err) => { | ||
let path = err.path().to_string(); | ||
assert_eq!(path, "dependencies.serde.version"); | ||
} | ||
} | ||
// let save: Gamestate = deserializer.deserialize()?; | ||
// println!("{:#?}", save.meta_data.version); | ||
// println!("{:#?}", save.played_character.character); | ||
// println!("{:#?}", save.living.get(&save.played_character.character)); | ||
// let traits = save | ||
// .living | ||
// .get(&save.played_character.character) | ||
// .unwrap() | ||
// .traits | ||
// .clone() | ||
// .unwrap(); | ||
// let trait_strings = traits | ||
// .iter() | ||
// .map(|t| save.traits_lookup[*t].clone()) | ||
// .collect::<Vec<String>>(); | ||
// println!( | ||
// "{:#?}", | ||
// traits | ||
// .iter() | ||
// .map(|t| save.traits_lookup[*t].clone()) | ||
// .collect::<Vec<String>>() | ||
// ); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use std::fmt; | ||
use std::marker::PhantomData; | ||
use serde::{Deserialize, Deserializer, de, Serialize}; | ||
|
||
#[derive(Debug, Clone, PartialEq, Serialize)] | ||
pub enum MaybeObject<T> { | ||
Text(String), | ||
Object(T), | ||
} | ||
|
||
impl<'de, T> Deserialize<'de> for MaybeObject<T> | ||
where | ||
T: Deserialize<'de>, | ||
{ | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
struct MaybeObjectVisitor<T1> { | ||
marker: PhantomData<T1>, | ||
} | ||
|
||
impl<'de, T1> de::Visitor<'de> for MaybeObjectVisitor<T1> | ||
where | ||
T1: Deserialize<'de>, | ||
{ | ||
type Value = MaybeObject<T1>; | ||
|
||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { | ||
formatter.write_str("an object or string") | ||
} | ||
|
||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> | ||
where | ||
E: de::Error, | ||
{ | ||
Ok(MaybeObject::Text(String::from(v))) | ||
} | ||
|
||
fn visit_map<A>(self, map: A) -> Result<Self::Value, A::Error> | ||
where | ||
A: de::MapAccess<'de>, | ||
{ | ||
let mvd = de::value::MapAccessDeserializer::new(map); | ||
let result = T1::deserialize(mvd)?; | ||
Ok(MaybeObject::Object(result)) | ||
} | ||
} | ||
|
||
deserializer.deserialize_map(MaybeObjectVisitor { | ||
marker: PhantomData, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
There are some saves that omit
buildings
, and my guess is that paradox often excludes fields that are empty or their default values, so I tend to prefer to use#[serde(default)]
and not use Option too much unless there is a difference between empty/0 andNone
in game.