From dce698174bf4e480ea4675bd1f50a86029b6fac4 Mon Sep 17 00:00:00 2001 From: Nitamet <13808955+heh-mda@users.noreply.github.com> Date: Mon, 29 Jan 2024 23:38:37 +0300 Subject: [PATCH 1/7] refactor(loader, front): change mythic item to core item and bump versions --- backend/lolbuild/loader.go | 20 +++++++++---------- .../components/Lobby/ChampionBuilds/Build.vue | 4 ++-- frontend/wailsjs/go/models.ts | 8 ++++---- updater.go | 3 +-- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/backend/lolbuild/loader.go b/backend/lolbuild/loader.go index 077a825..0f49db2 100644 --- a/backend/lolbuild/loader.go +++ b/backend/lolbuild/loader.go @@ -12,9 +12,9 @@ import ( "sync" ) -const buildDataVersion = 2 +const buildDataVersion = 3 -// previousVersionsToTry is a number of previous versions to try to load builds from if the latest version fails +// previousVersionsToTry is a number of previous build versions to try if the current one is unavailable const previousVersionsToTry = 2 // URLs-related constants @@ -88,11 +88,11 @@ type SummonerSpell struct { Name string `json:"name"` } type Item struct { - ID int `json:"id"` - Name string `json:"name"` - Slug string `json:"slug"` - IconUrl string `json:"iconUrl"` - IsMythic bool `json:"isMythic"` + ID int `json:"id"` + Name string `json:"name"` + Slug string `json:"slug"` + IconUrl string `json:"iconUrl"` + IsCoreItem bool `json:"IsCoreItem"` } type ItemGroup struct { Items []Item `json:"items"` @@ -109,7 +109,7 @@ type Build struct { SelectedPerks []Rune `json:"selectedPerks"` SummonerSpells []SummonerSpell `json:"summonerSpells"` ItemGroups []ItemGroup `json:"itemGroups"` - Mythic Item `json:"mythic"` + CoreItem Item `json:"coreItem"` } // BuildCollection is a collection of builds from a single source @@ -454,8 +454,8 @@ func (l *Loader) loadBuildCollection(championName, source, role string, version lolItem.Name = itemData.Name lolItem.IconUrl = itemData.IconUrl - if lolItem.IsMythic { - build.Mythic = *lolItem + if lolItem.IsCoreItem { + build.CoreItem = *lolItem } } } diff --git a/frontend/src/components/Lobby/ChampionBuilds/Build.vue b/frontend/src/components/Lobby/ChampionBuilds/Build.vue index 3b6352e..4cca074 100644 --- a/frontend/src/components/Lobby/ChampionBuilds/Build.vue +++ b/frontend/src/components/Lobby/ChampionBuilds/Build.vue @@ -65,8 +65,8 @@ const matches = computed(() => ); const getCoreItem = () => { - if ('' !== props.build.mythic.name) { - return props.build.mythic; + if ('' !== props.build.coreItem.name) { + return props.build.coreItem; } const coreItemGroup = props.build.itemGroups.find( diff --git a/frontend/wailsjs/go/models.ts b/frontend/wailsjs/go/models.ts index 0ae9fb7..6500d95 100755 --- a/frontend/wailsjs/go/models.ts +++ b/frontend/wailsjs/go/models.ts @@ -130,7 +130,7 @@ export namespace lolbuild { name: string; slug: string; iconUrl: string; - isMythic: boolean; + IsCoreItem: boolean; static createFrom(source: any = {}) { return new Item(source); @@ -142,7 +142,7 @@ export namespace lolbuild { this.name = source["name"]; this.slug = source["slug"]; this.iconUrl = source["iconUrl"]; - this.isMythic = source["isMythic"]; + this.IsCoreItem = source["IsCoreItem"]; } } export class ItemGroup { @@ -240,7 +240,7 @@ export namespace lolbuild { selectedPerks: Rune[]; summonerSpells: SummonerSpell[]; itemGroups: ItemGroup[]; - mythic: Item; + coreItem: Item; static createFrom(source: any = {}) { return new Build(source); @@ -256,7 +256,7 @@ export namespace lolbuild { this.selectedPerks = this.convertValues(source["selectedPerks"], Rune); this.summonerSpells = this.convertValues(source["summonerSpells"], SummonerSpell); this.itemGroups = this.convertValues(source["itemGroups"], ItemGroup); - this.mythic = this.convertValues(source["mythic"], Item); + this.coreItem = this.convertValues(source["coreItem"], Item); } convertValues(a: any, classs: any, asMap: boolean = false): any { diff --git a/updater.go b/updater.go index a5a8112..a8f9313 100644 --- a/updater.go +++ b/updater.go @@ -5,7 +5,7 @@ import ( "log" ) -const version = "v0.3.1" +const version = "v0.3.2" const updaterURL = "https://geemo.app/" func setupUpdater() *selfupdate.Updater { @@ -32,5 +32,4 @@ func autoUpdate(updater *selfupdate.Updater) { log.Println("Error occurred while updating: ", err) } }() - } From 946ccce194155064d4a3d312982eb1276c1a4faf Mon Sep 17 00:00:00 2001 From: Nitamet <13808955+heh-mda@users.noreply.github.com> Date: Wed, 31 Jan 2024 22:11:27 +0300 Subject: [PATCH 2/7] feat(loader, front): add skill order map --- backend/lolbuild/loader.go | 95 ++++++++++++++- frontend/src/components/Lobby/BuildInfo.vue | 15 ++- .../src/components/Lobby/ChampionBuilds.vue | 3 +- frontend/src/components/Lobby/Item.vue | 2 +- frontend/src/components/Lobby/ItemGroup.vue | 2 +- .../components/Lobby/RuneCollection/Rune.vue | 4 +- .../Lobby/RuneCollection/RuneTree.vue | 4 +- .../Lobby/RuneCollection/StatMod.vue | 2 +- .../Lobby/RuneCollection/StatMods.vue | 2 +- frontend/src/components/Lobby/SkillBox.vue | 75 ++++++++++++ frontend/src/components/Lobby/SkillOrder.vue | 113 +++++++++++++++++ .../src/components/Lobby/SummonerSpell.vue | 2 +- frontend/src/css/app.scss | 12 ++ frontend/src/stores/application-store.ts | 1 + frontend/wailsjs/go/lolbuild/Loader.d.ts | 2 + frontend/wailsjs/go/lolbuild/Loader.js | 4 + frontend/wailsjs/go/models.ts | 115 ++++++++++++++++++ 17 files changed, 433 insertions(+), 20 deletions(-) create mode 100644 frontend/src/components/Lobby/SkillBox.vue create mode 100644 frontend/src/components/Lobby/SkillOrder.vue diff --git a/backend/lolbuild/loader.go b/backend/lolbuild/loader.go index 0f49db2..5fa263f 100644 --- a/backend/lolbuild/loader.go +++ b/backend/lolbuild/loader.go @@ -5,6 +5,8 @@ import ( "encoding/json" "fmt" "github.com/Nitamet/geemo/backend" + "golang.org/x/text/cases" + golangLanguage "golang.org/x/text/language" "log" "net/http" "strconv" @@ -21,13 +23,15 @@ const previousVersionsToTry = 2 const ( buildCollectionsHost = "https://geemo.app" dataDragonVersionsUrl = "https://ddragon.leagueoflegends.com/api/versions.json" - dataDragonRunesReforgedUrl = "http://ddragon.leagueoflegends.com/cdn/%s/data/%s/runesReforged.json" - dataDragonSpellsUrl = "http://ddragon.leagueoflegends.com/cdn/%s/data/%s/summoner.json" + dataDragonRunesReforgedUrl = "https://ddragon.leagueoflegends.com/cdn/%s/data/%s/runesReforged.json" + dataDragonSpellsUrl = "https://ddragon.leagueoflegends.com/cdn/%s/data/%s/summoner.json" dataDragonAssetsUrl = "https://ddragon.leagueoflegends.com/cdn/img/" - dataDragonSpellIconUrl = "http://ddragon.leagueoflegends.com/cdn/%s/img/spell/%s.png" - dataDragonItemUrl = "http://ddragon.leagueoflegends.com/cdn/%s/data/%s/item.json" + dataDragonSpellIconUrl = "https://ddragon.leagueoflegends.com/cdn/%s/img/spell/%s.png" + dataDragonPassiveIconUrl = "https://ddragon.leagueoflegends.com/cdn/%s/img/passive/%s.png" + dataDragonItemUrl = "https://ddragon.leagueoflegends.com/cdn/%s/data/%s/item.json" dataDragonItemIcon = "https://ddragon.leagueoflegends.com/cdn/%s/img/item/%s.png" - dataDragonChampionUrl = "http://ddragon.leagueoflegends.com/cdn/%s/data/%s/champion.json" + dataDragonChampionsUrl = "https://ddragon.leagueoflegends.com/cdn/%s/data/%s/champion.json" + dataDragonChampionUrl = "https://ddragon.leagueoflegends.com/cdn/%s/data/%s/champion/%s.json" ) type AssetData struct { @@ -110,6 +114,8 @@ type Build struct { SummonerSpells []SummonerSpell `json:"summonerSpells"` ItemGroups []ItemGroup `json:"itemGroups"` CoreItem Item `json:"coreItem"` + SkillMaxOrder []int `json:"skillMaxOrder"` + SkillOrder []int `json:"skillOrder"` } // BuildCollection is a collection of builds from a single source @@ -118,6 +124,25 @@ type BuildCollection struct { Source string `json:"source"` } +type SpellImage struct { + Full string `json:"full"` +} +type Spell struct { + Name string `json:"name"` + Image SpellImage `json:"image"` +} +type Passive struct { + Name string `json:"name"` + Image SpellImage `json:"image"` +} +type ChampionData struct { + Spells []Spell `json:"spells"` + Passive Passive `json:"passive"` +} +type championDataResponse struct { + Data map[string]ChampionData `json:"data"` +} + // loadRuneTrees loads all rune trees from data dragon func (l *Loader) loadRuneTrees() RuneTrees { if l.runeTrees != nil && len(l.runeTrees) > 0 { @@ -237,7 +262,7 @@ func (l *Loader) loadChampions() { return } - resp, err := http.Get(fmt.Sprintf(dataDragonChampionUrl, l.getLatestVersion(), l.language)) + resp, err := http.Get(fmt.Sprintf(dataDragonChampionsUrl, l.getLatestVersion(), l.language)) if err != nil { log.Fatalln("Error fetching champions data") } @@ -597,3 +622,61 @@ func (l *Loader) GetSources() []BuildSource { return result } + +// GetChampionData loads champion data from data dragon +func (l *Loader) GetChampionData(championId int, language string) *ChampionData { + // TODO: Add cache + if l.language != language { + l.setLanguage(language) + } + + championSlug := l.GetChampionName(championId, language).Slug + + championUrl := fmt.Sprintf( + dataDragonChampionUrl, + l.getLatestVersion(), + l.language, + cases.Title(golangLanguage.English, cases.NoLower).String(championSlug), + ) + + log.Printf("Loading championg data from %s", championUrl) + + resp, err := http.Get(championUrl) + if err != nil { + log.Panic(err) + } + + if resp.StatusCode == http.StatusNotFound { + return nil + } + + var championDataResponse championDataResponse + err = json.NewDecoder(resp.Body).Decode(&championDataResponse) + + if err != nil { + log.Println("Error decoding champion data: ", err) + return nil + } + + var championData *ChampionData + for _, data := range championDataResponse.Data { + championData = &data + break + } + + if championData == nil { + log.Println("Champion data response is empty") + return nil + } + + for i := range championData.Spells { + spell := &championData.Spells[i] + spell.Image.Full = strings.Replace(spell.Image.Full, ".png", "", -1) + spell.Image.Full = fmt.Sprintf(dataDragonSpellIconUrl, l.getLatestVersion(), spell.Image.Full) + } + + championData.Passive.Image.Full = strings.Replace(championData.Passive.Image.Full, ".png", "", -1) + championData.Passive.Image.Full = fmt.Sprintf(dataDragonPassiveIconUrl, l.getLatestVersion(), championData.Passive.Image.Full) + + return championData +} diff --git a/frontend/src/components/Lobby/BuildInfo.vue b/frontend/src/components/Lobby/BuildInfo.vue index a2ad805..d7d3062 100644 --- a/frontend/src/components/Lobby/BuildInfo.vue +++ b/frontend/src/components/Lobby/BuildInfo.vue @@ -1,23 +1,29 @@