Skip to content

Commit 7cb6b4d

Browse files
committed
feat: updated java version to 17
feat: updated kotlin version to 2.1.0 feat: reimplemented enchantment tiers into enchantment groups, migrating their configuration from being hard-coded to toml-based feat: implemented automated enchantment files discovery fix: removed perks enchantment group chore: updated package dependencies chore: bumped the version to 2.0.2
1 parent 8882058 commit 7cb6b4d

File tree

14 files changed

+112
-207
lines changed

14 files changed

+112
-207
lines changed

android/app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ android {
1010
ndkVersion = "27.0.12077973"
1111

1212
compileOptions {
13-
sourceCompatibility = JavaVersion.VERSION_1_8
14-
targetCompatibility = JavaVersion.VERSION_1_8
13+
sourceCompatibility = JavaVersion.VERSION_17
14+
targetCompatibility = JavaVersion.VERSION_17
1515
}
1616

1717
kotlinOptions {
18-
jvmTarget = JavaVersion.VERSION_1_8
18+
jvmTarget = JavaVersion.VERSION_17
1919
}
2020

2121
defaultConfig {

android/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pluginManagement {
1919
plugins {
2020
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
2121
id "com.android.application" version '8.9.1' apply false
22-
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
22+
id "org.jetbrains.kotlin.android" version "2.1.0" apply false
2323
}
2424

2525
include("app")

assets/enchantments/medium.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
tier = "medium"
1+
[group]
2+
id = "medium"
3+
displayName = "Medium"
4+
color = "0xFFE6521F"
5+
order = 1
26

37
[shockingStrike]
48
name = "Shocking Strike"

assets/enchantments/mythical.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
tier = "mythical"
1+
[group]
2+
id = "mythical"
3+
displayName = "Mythical"
4+
color = "0xFF441752"
5+
order = 2
6+
hasAspect = false
27

38
[stone_fetters]
49
name = "Stone Fetters"

assets/enchantments/perk.toml

Lines changed: 0 additions & 82 deletions
This file was deleted.

assets/enchantments/simple.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
tier = "simple"
1+
[group]
2+
id = "simple"
3+
displayName = "Simple"
4+
color = "0xFF254D70"
5+
order = 0
26

37
[critical_protection]
48
name = "Critical Protection"

lib/logic/enchantment.dart

Lines changed: 34 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -23,82 +23,55 @@ import 'package:stalker/logic/equipment_type.dart';
2323
import 'package:toml/toml.dart';
2424
import 'package:xml/xml.dart';
2525

26-
enum EnchantmentTier { simple, medium, mythical, perk }
27-
28-
extension EnchantmentTierExtension on EnchantmentTier {
29-
int get color {
30-
switch (this) {
31-
case EnchantmentTier.simple:
32-
return 0xFF254D70;
33-
case EnchantmentTier.medium:
34-
return 0xFFE6521F;
35-
case EnchantmentTier.mythical:
36-
return 0xFF441752;
37-
case EnchantmentTier.perk:
38-
return 0xFFB45253;
39-
}
40-
}
26+
class EnchantmentGroup {
27+
final String id;
28+
final String displayName;
29+
final int color;
30+
final int order;
31+
final bool hasAspect;
4132

42-
String get recipeDeliveryName {
43-
switch (this) {
44-
case EnchantmentTier.simple:
45-
return "Simple";
46-
case EnchantmentTier.medium:
47-
return "Medium";
48-
case EnchantmentTier.mythical:
49-
return "Mythical"; // either Mythical or Mythic, not tested
50-
case EnchantmentTier.perk:
51-
return "";
52-
}
53-
}
33+
EnchantmentGroup(this.id, this.displayName, this.color, this.order, this.hasAspect);
5434

55-
static EnchantmentTier? tierFromRecipeName(String recipeDeliveryName) {
56-
return EnchantmentTier.values
57-
.where((c) => c.recipeDeliveryName == recipeDeliveryName)
58-
.firstOrNull;
35+
factory EnchantmentGroup.fromToml(Map<String, dynamic> tomlMap) {
36+
return EnchantmentGroup(tomlMap["id"], tomlMap["displayName"],
37+
int.parse(tomlMap["color"]), tomlMap["order"], tomlMap["hasAspect"] ?? true);
5938
}
6039
}
6140

6241
class Enchantment {
6342
final String name;
6443
final String id;
6544
final String? description;
66-
final EnchantmentTier tier;
6745
final Map<EquipmentType, String> ids;
46+
final EnchantmentGroup group;
6847

69-
const Enchantment(this.name, this.id, this.description, this.tier, this.ids);
48+
const Enchantment(this.name, this.id, this.description, this.ids, this.group);
7049

7150
factory Enchantment.fromToml(
72-
MapEntry<String, dynamic> entry, EnchantmentTier tier) {
73-
if (tier == EnchantmentTier.mythical || tier == EnchantmentTier.perk) {
51+
MapEntry<String, dynamic> entry, EnchantmentGroup group) {
52+
if (entry.value.containsKey("id")) {
7453
final id = entry.value["id"] as String;
7554
return Enchantment(
76-
entry.value["name"] as String,
77-
entry.key,
78-
entry.value["description"] as String?,
79-
tier,
80-
{
81-
EquipmentType.weapon: id,
82-
EquipmentType.ranged: id,
83-
EquipmentType.magic: id,
84-
EquipmentType.armor: id,
85-
EquipmentType.helm: id,
86-
},
87-
);
55+
entry.value["name"] as String,
56+
entry.key,
57+
entry.value["description"] as String?,
58+
{
59+
EquipmentType.weapon: id,
60+
EquipmentType.ranged: id,
61+
EquipmentType.magic: id,
62+
EquipmentType.armor: id,
63+
EquipmentType.helm: id,
64+
},
65+
group);
8866
} else {
8967
final equipmentIdsRaw =
9068
entry.value["equipment_ids"] as Map<String, dynamic>;
9169
final equipmentIds = equipmentIdsRaw.map(
9270
(k, v) => MapEntry(EquipmentType.values.byName(k), v as String),
9371
);
9472

95-
return Enchantment(
96-
entry.value["name"] as String,
97-
entry.key,
98-
entry.value["description"] as String?,
99-
tier,
100-
equipmentIds,
101-
);
73+
return Enchantment(entry.value["name"] as String, entry.key,
74+
entry.value["description"] as String?, equipmentIds, group);
10275
}
10376
}
10477

@@ -107,9 +80,11 @@ class Enchantment {
10780

10881
class EnchantmentsManager {
10982
static List<Enchantment> enchantments = [];
83+
static List<EnchantmentGroup> groups = [];
11084

11185
static Future<void> loadFromFiles() async {
11286
enchantments.clear();
87+
groups.clear();
11388
final manifestContent = await rootBundle.loadString('AssetManifest.json');
11489
final Map<String, dynamic> manifestMap = json.decode(manifestContent);
11590

@@ -118,13 +93,14 @@ class EnchantmentsManager {
11893
.toList()) {
11994
final tomlString = await rootBundle.loadString(file);
12095
final tomlMap = TomlDocument.parse(tomlString).toMap();
121-
final tier = EnchantmentTier.values.byName(tomlMap["tier"]);
122-
tomlMap.remove("tier");
96+
final group = EnchantmentGroup.fromToml(tomlMap["group"]);
97+
tomlMap.remove("group");
98+
groups.add(group);
12399
enchantments.addAll(tomlMap.entries.map((e) {
124-
final id = e.key;
125100
final data = e.value as Map<String, dynamic>;
126-
return Enchantment.fromToml(MapEntry(id, data), tier);
101+
return Enchantment.fromToml(MapEntry(e.key, data), group);
127102
}));
103+
groups.sort((a, b) => a.order.compareTo(b.order));
128104
}
129105
}
130106

lib/logic/equipment.dart

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,18 @@ class UpgradeDelivery {
4040
}
4141
}
4242

43+
enum RecipeEnchantmentTier {
44+
simple("Simple"),
45+
medium("Medium"),
46+
mythical("Mythical");
47+
48+
final String name;
49+
const RecipeEnchantmentTier(this.name);
50+
}
51+
4352
class RecipeDelivery {
4453
DateTime time = DateTime.fromMillisecondsSinceEpoch(0);
45-
late EnchantmentTier tier;
54+
late RecipeEnchantmentTier tier;
4655
int itemLevel = 0;
4756
int playerLevel = 0;
4857

@@ -52,7 +61,7 @@ class RecipeDelivery {
5261
time = DateTime.fromMillisecondsSinceEpoch(int.parse(deliveryTime) * 1000);
5362
this.itemLevel = int.parse(itemLevel);
5463
this.playerLevel = int.parse(playerLevel);
55-
this.tier = EnchantmentTierExtension.tierFromRecipeName(tier)!;
64+
this.tier = RecipeEnchantmentTier.values.firstWhere((e) => e.name == tier);
5665
}
5766
}
5867

@@ -66,7 +75,7 @@ class Equipment {
6675
int upgrade = 0;
6776
UpgradeDelivery? upgradeDelivery;
6877
RecipeDelivery? recipeDelivery;
69-
78+
7079
static const minLevel = 1;
7180
static const maxLevel = 52;
7281
static const minUpgrade = 0;
@@ -104,8 +113,7 @@ class Equipment {
104113
enchantments.map((e) => e.toXml(type))),
105114
if (recipeDelivery != null)
106115
XmlElement(XmlName("RecipeDelivery"), [
107-
XmlAttribute(
108-
XmlName("Name"), recipeDelivery!.tier.recipeDeliveryName),
116+
XmlAttribute(XmlName("Name"), recipeDelivery!.tier.name),
109117
XmlAttribute(
110118
XmlName("ItemLevel"), recipeDelivery!.itemLevel.toString()),
111119
XmlAttribute(

0 commit comments

Comments
 (0)