mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2025-11-18 06:24:17 +01:00
Support for old 'paths' syntax for skill trees. Warning if usage of old syntax is detected. Logs if problems are detected with the config
This commit is contained in:
parent
5225e97042
commit
e5ecd46611
@ -74,6 +74,13 @@ public class ParentInformation {
|
||||
return shape;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void addElement(@NotNull IntCoords coordinates) {
|
||||
Validate.isTrue(!this.elements.containsKey(coordinates), "Path element already present at " + coordinates);
|
||||
this.elements.put(coordinates, null); // Place new
|
||||
this.elements.replaceAll((e, v) -> computePathShape(e)); // Update all
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the method for computing the shape of a path element ie
|
||||
* whether it goes up, right, up-right, etc. based on the presence
|
||||
|
||||
@ -277,6 +277,32 @@ public class SkillTreeNode implements ExperienceObject {
|
||||
|
||||
//region Deprecated
|
||||
|
||||
@Deprecated
|
||||
public void loadLegacyPathSection(@NotNull ConfigurationSection section) {
|
||||
for (var childId : section.getKeys(false)) {
|
||||
final var child = tree.getNode(childId);
|
||||
Validate.notNull(child, "Could not find child node '" + childId + "' for path");
|
||||
|
||||
// Find corresponding edge
|
||||
ParentInformation edge = null;
|
||||
for (var existingEdge : children)
|
||||
if (existingEdge.getChild().equals(child)) {
|
||||
edge = existingEdge;
|
||||
break;
|
||||
}
|
||||
if (edge == null) {
|
||||
MMOCore.log("Could not find parent-child relation between '" + id + "' and '" + childId + "'. Did you forget to add it in the 'parents' or 'children' section?");
|
||||
continue;
|
||||
}
|
||||
|
||||
final var subsection = section.getConfigurationSection(childId);
|
||||
for (var pathKey : subsection.getKeys(false)) {
|
||||
final var coords = IntCoords.from(subsection.get(pathKey));
|
||||
edge.addElement(coords);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getParentNeededLevel(SkillTreeNode parent) {
|
||||
for (var edge : parents)
|
||||
|
||||
@ -65,7 +65,7 @@ public abstract class SkillTree implements RegisteredObject {
|
||||
MMOCore.log(Level.WARNING, "Couldn't load skill tree node " + id + "." + key + ": " + exception.getMessage());
|
||||
}
|
||||
|
||||
// Post load all nodes
|
||||
// Post load all nodes (relatives)
|
||||
for (var node : nodes.values())
|
||||
try {
|
||||
node.getPostLoadAction().performAction();
|
||||
@ -75,6 +75,9 @@ public abstract class SkillTree implements RegisteredObject {
|
||||
exception.printStackTrace(); // TODO remove
|
||||
}
|
||||
|
||||
// [Syntax Deprecated] Load legacy "paths" section
|
||||
loadLegacyPaths(config);
|
||||
|
||||
// Resolve node shapes
|
||||
resolveNodeShapes();
|
||||
|
||||
@ -415,6 +418,29 @@ public abstract class SkillTree implements RegisteredObject {
|
||||
|
||||
//region Deprecated
|
||||
|
||||
@Deprecated
|
||||
private void loadLegacyPaths(ConfigurationSection config) {
|
||||
|
||||
int warnings = 0;
|
||||
|
||||
for (var node : nodes.values()) {
|
||||
final var section = config.getConfigurationSection("nodes." + node.getId() + ".paths");
|
||||
if (section == null) continue;
|
||||
if (warnings++ < 3) {
|
||||
// Warn max 3 times
|
||||
MMOCore.log("You are using deprecated syntax for skill tree node '" + id + "' of skill tree '"
|
||||
+ this.getId() + "'. You may update your config to use the 'parents' section instead of the 'paths' section. " +
|
||||
"Please visit 'https://gitlab.com/phoenix-dvpmt/mmocore/-/wikis/Skill%20Trees' to read about this new syntax");
|
||||
}
|
||||
node.loadLegacyPathSection(section);
|
||||
}
|
||||
|
||||
// Repopulate pathByCoordinate map
|
||||
if (warnings > 0)
|
||||
for (var node : nodes.values())
|
||||
node.getParents().forEach(parentInfo -> parentInfo.getElements().forEach(coords -> this.pathByCoordinate.put(coords, parentInfo)));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isNode(@NotNull IntCoords coordinates) {
|
||||
// TODO remove usage
|
||||
|
||||
Loading…
Reference in New Issue
Block a user