Coder Social home page Coder Social logo

eu4save's Introduction

ci Version

EU4 Save

EU4 Save is a library to ergonomically work with EU4 saves (ironman + mp).

use eu4save::{Eu4File, Encoding, CountryTag, EnvTokens};
let data = std::fs::read("assets/saves/eng.txt.compressed.eu4")?;
let file = Eu4File::from_slice(&data)?;
let save = file.parse_save(&EnvTokens)?;
assert_eq!(file.encoding(), Encoding::TextZip);
assert_eq!(save.meta.player, "ENG".parse()?);

Querying

Even once decoded, the data might be too low level. For example a country can have an income ledger that looks like:

income = { 1.000 0 2.000 0.000 1.500 }

While the structure will decoded successfully into a vector, the context of what each index means is missing. What value represents the income from trade?

To help solve questions like these, the Query API was created

use eu4save::{Eu4Extractor, Encoding, CountryTag, query::Query};

let data = std::fs::read("assets/saves/eng.txt.compressed.eu4")?;
let file = Eu4File::from_slice(&data)?;
let save = file.parse_save(&EnvTokens)?;
let save_query = Query::from_save(save);
let trade = save_query.country(&"ENG".parse()?)
    .map(|country| save_query.country_income_breakdown(country))
    .map(|income| income.trade);
assert_eq!(Some(17.982), trade);

Ironman

By default, ironman saves will not be decoded properly.

To enable support, one must supply an environment variable (EU4_IRONMAN_TOKENS) that points to a newline delimited text file of token descriptions. For instance:

0xffff my_test_token
0xeeee my_test_token2

PDS has declared that in order to comply with EU4's terms of use, the list of tokens must not be shared. I am also restricted from divulging how the list of tokens can be derived.

You may look to other projects EU4 ironman projects like ironmelt or paperman for inspiration.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.