Skip to content

feat: cache masterfile on update#16

Merged
lenisko merged 3 commits intomasterfrom
cache-masterfile
Jan 6, 2025
Merged

feat: cache masterfile on update#16
lenisko merged 3 commits intomasterfrom
cache-masterfile

Conversation

@lenisko
Copy link
Collaborator

@lenisko lenisko commented Jan 3, 2025

Add ability to automatically save a cached version of MasterFile after successful fetch.

@jfberry
Copy link
Contributor

jfberry commented Jan 3, 2025

An example of use would be to call Fetch at init and if fail, use Load with the previously cached file?
BTW load should also clear the cache

@lenisko
Copy link
Collaborator Author

lenisko commented Jan 3, 2025

If we plan to ship Golbat with some version of MasterFile in repo, we could fire Load first, then Fetch to try updating it and Watch to keep it updated in background. So when Fetch or Watch will work, after restart we will have more recent copy of MF in cache to Load. This way it won't fail anymore, but in the worst case (where both Fetch and Watch will fail) we will get old MF data.

If we don't provide any MF within a repo, we can still potentially get a fail on fresh Golbat copy - on Fetch since we NEED this to get PvP working. I would just handle it by panic log Place master-file.json in X since we can't fetch it automatically for you...

Thank you, @jfberry - fixed! Good eye!

@jfberry
Copy link
Contributor

jfberry commented Jan 3, 2025

If we plan to ship Golbat with some version of MasterFile in repo, we could fire Load first, then Fetch to try updating it and Watch to keep it updated in background. So when Fetch or Watch will work, after restart we will have more recent copy of MF in cache to Load. This way it won't fail anymore, but in the worst case (where both Fetch and Watch will fail) we will get old MF data.

If we don't provide any MF within a repo, we can still potentially get a fail on fresh Golbat copy - on Fetch since we NEED this to get PvP working. I would just handle it by panic log Place master-file.json in X since we can't fetch it automatically for you...

Thank you, @jfberry - fixed! Good eye!

If you supply one with golbat, then startup should probably be:
Fetch - if fail - Load cache file - if fail - load distro file. Then call watch with the cache filename to have it write to that when it next succeeds to fetch.
This seems to cover all of the 'first install with network failure', 'restart with network failure' and 'restart normally' conditions? @Fabio1988

@jfberry
Copy link
Contributor

jfberry commented Jan 3, 2025

Ultimately golbat should just decode the masterfile proto message and feed that to gohbem but that's for another day

@lenisko
Copy link
Collaborator Author

lenisko commented Jan 3, 2025

Sounds good to me. Let me know if everything we want is provided within a PR - I will merge and add a version tag.

@lenisko
Copy link
Collaborator Author

lenisko commented Jan 3, 2025

Ultimately golbat should just decode the masterfile proto message and feed that to gohbem but that's for another day

If we can provide this data, I can add a method to update internal struct. Here's everything from MF we need to handle calculations:

type PokemonData struct {
	// Initialized bool            `json:"-"`
	Pokemon     map[int]Pokemon `json:"pokemon"`
	Costumes    map[int]bool    `json:"costumes"`
}

type Pokemon struct {
	Attack                    int                  `json:"attack"`
	Defense                   int                  `json:"defense"`
	Stamina                   int                  `json:"stamina"`
	Little                    bool                 `json:"little,omitempty"`
	Evolutions                []Evolution          `json:"evolutions,omitempty"`
	TempEvolutions            map[int]PokemonStats `json:"temp_evolutions,omitempty"`
	CostumeOverrideEvolutions []int                `json:"costume_override_evos,omitempty"`
	Forms                     map[int]Form         `json:"forms"`
}

type Form struct {
	Attack                    int                  `json:"attack,omitempty"`
	Defense                   int                  `json:"defense,omitempty"`
	Stamina                   int                  `json:"stamina,omitempty"`
	Little                    bool                 `json:"little,omitempty"`
	Evolutions                []Evolution          `json:"evolutions,omitempty"`
	TempEvolutions            map[int]PokemonStats `json:"temp_evolutions,omitempty"`
	CostumeOverrideEvolutions []int                `json:"costume_override_evos,omitempty"`
}

type PokemonStats struct {
	Attack     int  `json:"attack,omitempty"`
	Defense    int  `json:"defense,omitempty"`
	Stamina    int  `json:"stamina,omitempty"`
	Unreleased bool `json:"unreleased,omitempty"`
}

type Evolution struct {
	Pokemon           int `json:"pokemon"`
	Form              int `json:"form,omitempty"`
	GenderRequirement int `json:"gender_requirement,omitempty"`
}

@lenisko lenisko merged commit 04c52fc into master Jan 6, 2025
1 check passed
@lenisko lenisko deleted the cache-masterfile branch January 6, 2025 13:01
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.

2 participants