Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
Merge branch 'development' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
DevScyu authored Sep 13, 2023
2 parents dfb264e + f28c584 commit 1417cb0
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 20 deletions.
24 changes: 12 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
## [1.15.1-beta.7](https://github.com/Wynntils/Wynntils/compare/v1.15.1-beta.6...v1.15.1-beta.7) (2023-09-13)


### Bug Fixes

* Fix Guild Map Crashing ([#689](https://github.com/Wynntils/Wynntils/issues/689)) ([e5cc971](https://github.com/Wynntils/Wynntils/commit/e5cc9718dad93581000783c1a298862e6da91c99))

## [1.15.1-beta.6](https://github.com/Wynntils/Wynntils/compare/v1.15.1-beta.5...v1.15.1-beta.6) (2023-08-12)


### Bug Fixes

* Fixed TAB_EFFECT_PATTERN regex ([#686](https://github.com/Wynntils/Wynntils/issues/686)) ([46408de](https://github.com/Wynntils/Wynntils/commit/46408de7d589c2dc5ef6dcabe54eb4bfe27d39bf))


### Miscellaneous Chores

* **release:** v1.15.1-beta.6 [skip ci] ([71bf7fe](https://github.com/Wynntils/Wynntils/commit/71bf7fee9698345af1b61eb7f3b39c57b51fb497))

## [1.15.1-beta.5](https://github.com/Wynntils/Wynntils/compare/v1.15.1-beta.4...v1.15.1-beta.5) (2023-07-24)


Expand Down Expand Up @@ -37,15 +49,3 @@

* **release:** v1.15.1-beta.3 [skip ci] ([ffab244](https://github.com/Wynntils/Wynntils/commit/ffab244e16a0ab9c3613b11f732ae0e1d2be7719))

## [1.15.1-beta.2](https://github.com/Wynntils/Wynntils/compare/v1.15.1-beta.1...v1.15.1-beta.2) (2023-04-17)


### Bug Fixes

* The mod can now load Artemis (1.19.3) lootruns ([#675](https://github.com/Wynntils/Wynntils/issues/675)) ([cc98eb1](https://github.com/Wynntils/Wynntils/commit/cc98eb12022bf752acdd359883a9254ae35d192c))


### Miscellaneous Chores

* **release:** v1.15.1-beta.2 [skip ci] ([28538a3](https://github.com/Wynntils/Wynntils/commit/28538a36d44442a94940193c981a00604b4fa9d0))

Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,26 @@
import com.wynntils.core.framework.rendering.colors.CommonColors;
import com.wynntils.core.framework.rendering.colors.CustomColor;
import com.wynntils.core.framework.rendering.textures.Textures;
import com.wynntils.core.utils.StringUtils;
import com.wynntils.core.utils.objects.Storage;
import com.wynntils.modules.map.configs.MapConfig;
import com.wynntils.modules.map.instances.GuildResourceContainer;
import com.wynntils.modules.map.instances.MapProfile;
import com.wynntils.modules.map.managers.GuildResourceManager;
import com.wynntils.modules.map.overlays.renderer.MapInfoUI;
import com.wynntils.webapi.WebManager;
import com.wynntils.webapi.profiles.TerritoryProfile;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.text.TextFormatting;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

public class MapTerritory {

private static final CustomColor territoryNameColour = new CustomColor(CommonColors.WHITE);
private static final HashMap<String, CustomColor> backupGuildColors = new HashMap<>();

ScreenRenderer renderer = null;

Expand Down Expand Up @@ -64,7 +68,7 @@ public MapTerritory(TerritoryProfile territory) {
description.add(TextFormatting.GRAY + "✦ Treasury: " + resources.getTreasury());
description.add(TextFormatting.GRAY + "Territory Defences: " + resources.getDefences());
description.add("");

String treasuryColor = resources.getTreasury().substring(0, 2);
description.add(TextFormatting.GRAY + "Time held: " + treasuryColor + territory.getReadableRelativeTimeAcquired());

Expand Down Expand Up @@ -160,12 +164,26 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks, boolean terri
}

private CustomColor getTerritoryColor(boolean resourceColor) {
if (!resourceColor) {
return territory.getGuildColor() == null ? StringUtils.colorFromString(territory.getGuild()) :
StringUtils.colorFromHex(territory.getGuildColor());
} else {
return resources.getColor();
if (resourceColor) return resources.getColor();

if (WebManager.getGuildColors().containsKey(territory.getGuild())) {
return WebManager.getGuildColors().get(territory.getGuild());
}

// Guild not found in the list, check backup list and add a random color if not found
if (!backupGuildColors.containsKey(territory.getGuild())) {
Random random = new Random();
backupGuildColors.put(
territory.getGuild(),
CustomColor.fromHSV(
random.nextFloat(),
random.nextFloat(),
0.5f + random.nextFloat() * 0.5f,
1f
)
);
}
return backupGuildColors.get(territory.getGuild());
}

public void postDraw(int mouseX, int mouseY, float partialTicks, int width, int height) {
Expand Down
35 changes: 34 additions & 1 deletion src/main/java/com/wynntils/webapi/WebManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.wynntils.Reference;
import com.wynntils.core.events.custom.WynnGuildWarEvent;
import com.wynntils.core.framework.FrameworkManager;
import com.wynntils.core.framework.rendering.colors.CustomColor;
import com.wynntils.core.utils.Utils;
import com.wynntils.modules.core.enums.UpdateStream;
import com.wynntils.modules.core.overlays.UpdateOverlay;
Expand All @@ -37,7 +38,6 @@
import com.wynntils.webapi.profiles.item.ItemGuessProfile;
import com.wynntils.webapi.profiles.item.ItemProfile;
import com.wynntils.webapi.profiles.item.enums.ItemType;
import com.wynntils.webapi.profiles.item.objects.IdentificationContainer;
import com.wynntils.webapi.profiles.item.objects.MajorIdentification;
import com.wynntils.webapi.profiles.music.MusicLocationsProfile;
import com.wynntils.webapi.profiles.player.PlayerStatsProfile;
Expand Down Expand Up @@ -68,6 +68,7 @@ public class WebManager {
private static @Nullable WebReader apiUrls;

private static HashMap<String, TerritoryProfile> territories = new HashMap<>();
private static HashMap<String, CustomColor> guildColors = new HashMap<>();
private static UpdateProfile updateProfile;
private static boolean ignoringJoinUpdate = false;

Expand Down Expand Up @@ -139,6 +140,7 @@ public static void setupWebApi(boolean withProgress) {
}

updateTerritories(handler);
updateGuildColors(handler);
updateItemList(handler);
updateIngredientList(handler);
updateMapLocations(handler);
Expand Down Expand Up @@ -207,6 +209,10 @@ public static HashMap<String, TerritoryProfile> getTerritories() {
return territories;
}

public static HashMap<String, CustomColor> getGuildColors() {
return guildColors;
}

public static HashMap<String, ItemProfile> getItems() {
return items;
}
Expand Down Expand Up @@ -331,6 +337,33 @@ public static void updateTerritories(RequestHandler handler) {
);
}

public static void updateGuildColors(RequestHandler handler) {
if (apiUrls == null) return;
String url = apiUrls.get("Athena") + "/cache/get/guildListWithColors";
handler.addRequest(new Request(url, "guildColors")
.cacheTo(new File(API_CACHE_ROOT, "guildColors.json"))
.handleJsonObject(json -> {
if (!json.has("0")) return false;
// json is {"0": {data}}, {"1": {data}}, etc.
// we need to convert it to {data}, {data}, etc.
guildColors = new HashMap<>();
for (Map.Entry<String, JsonElement> entry : json.entrySet()) {
JsonObject data = entry.getValue().getAsJsonObject();
// data is now {"_id":"Kingdom Foxes","prefix":"Fox","color":"#FF8200"}

String colorString = entry.getValue().getAsJsonObject().get("color").getAsString();
if (colorString.length() != 7 && colorString.length() != 4 && colorString.length() != 3) continue;

guildColors.put( // name, CustomColor
entry.getValue().getAsJsonObject().get("_id").getAsString(),
CustomColor.fromString(colorString, 1f)
);
}
return true;
})
);
}

public static void updateCurrentSplash() {
if (apiUrls == null || apiUrls.getList("Splashes") == null) return;

Expand Down

0 comments on commit 1417cb0

Please sign in to comment.