Skip to content

Commit 011c225

Browse files
committed
Make StatSheet responsible for deciding its own IDs
THere were several places where `StatSheetManager` instances had to be conjured out of nowhere just to append the namespace and name into an ID. This is no longer necessary as `StatSheet#id()` will do the same without involving a `StatSheetManager`.
1 parent f8889fd commit 011c225

File tree

5 files changed

+9
-65
lines changed

5 files changed

+9
-65
lines changed

src/main/java/net/rptools/maptool/client/ui/campaignproperties/TokenPropertiesManagementPanel.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,8 @@ private void populateStatSheetComboBoxes(String propertyType) {
479479
var statSheetProperty = tokenTypeStatSheetMap.get(propertyType);
480480
String id;
481481
if (statSheetProperty == null) {
482-
id = ssManager.getDefaultStatSheetId();
483-
tokenTypeStatSheetMap.put(
484-
propertyType, new StatSheetProperties(ssManager.getDefaultStatSheetId(), null));
482+
id = StatSheetManager.LEGACY_STATSHEET.id();
483+
tokenTypeStatSheetMap.put(propertyType, new StatSheetProperties(id, null));
485484
} else {
486485
id = statSheetProperty.id();
487486
}
@@ -514,7 +513,7 @@ public void initStatSheetDetails() {
514513
if (getStatSheetComboBox().hasFocus()) { // Only if user has made change
515514
var tokenType = (String) getTokenTypeList().getSelectedValue();
516515
if (ss != null && tokenType != null) {
517-
var id = new StatSheetManager().getId(ss);
516+
var id = ss.id();
518517
var location = tokenTypeStatSheetMap.get(tokenType).location();
519518
tokenTypeStatSheetMap.put(tokenType, new StatSheetProperties(id, location));
520519
getStatSheetLocationComboBox().setSelectedItem(location);

src/main/java/net/rptools/maptool/client/ui/token/dialog/create/NewTokenDialog.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,10 @@ public boolean commit() {
166166

167167
var statSheet = (StatSheet) getStatSheetComboBox().getSelectedItem();
168168
var location = (StatSheetLocation) getStatSheetLocationComboBox().getSelectedItem();
169-
var ssManager = new StatSheetManager();
170169
if (statSheet == null || (statSheet.name() == null && statSheet.namespace() == null)) {
171170
token.useDefaultStatSheet();
172171
} else {
173-
token.setStatSheet(new StatSheetProperties(ssManager.getId(statSheet), location));
172+
token.setStatSheet(new StatSheetProperties(statSheet.id(), location));
174173
}
175174

176175
return true;

src/main/java/net/rptools/maptool/client/ui/token/dialog/edit/EditTokenDialog.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -908,9 +908,8 @@ public boolean commit() {
908908
if (ss == null || (ss.name() == null && ss.namespace() == null)) {
909909
token.useDefaultStatSheet();
910910
} else {
911-
var ssManager = new StatSheetManager();
912911
var location = (StatSheetLocation) getStatSheetLocationCombo().getSelectedItem();
913-
token.setStatSheet(new StatSheetProperties(ssManager.getId(ss), location));
912+
token.setStatSheet(new StatSheetProperties(ss.id(), location));
914913
}
915914

916915
/* Macros */

src/main/java/net/rptools/maptool/model/sheet/stats/StatSheet.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
*/
3131
public record StatSheet(
3232
String name, String description, URL entry, Set<String> propertyTypes, String namespace) {
33+
public String id() {
34+
return namespace + "." + name;
35+
}
36+
3337
@Override
3438
public boolean equals(Object obj) {
3539
if (!(obj instanceof StatSheet other)) {

src/main/java/net/rptools/maptool/model/sheet/stats/StatSheetManager.java

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -76,42 +76,6 @@ public class StatSheetManager {
7676
statSheets.put(NO_STATSHEET, "");
7777
}
7878

79-
/**
80-
* Returns the default stat sheet.
81-
*
82-
* @return the default stat sheet.
83-
*/
84-
public StatSheet getDefaultStatSheet() {
85-
return LEGACY_STATSHEET;
86-
}
87-
88-
/**
89-
* Returns the id of the default stat sheet.
90-
*
91-
* @return the id of the default stat sheet.
92-
*/
93-
public String getDefaultStatSheetId() {
94-
return getId(LEGACY_STATSHEET);
95-
}
96-
97-
/**
98-
* Returns the "no" stat sheet.
99-
*
100-
* @return the "no" stat sheet.
101-
*/
102-
public StatSheet getNoStatSheet() {
103-
return NO_STATSHEET;
104-
}
105-
106-
/**
107-
* Returns the id of the "no" stat sheet.
108-
*
109-
* @return the id of the "no" stat sheet.
110-
*/
111-
public String getNoStatSheetId() {
112-
return getId(NO_STATSHEET);
113-
}
114-
11579
/**
11680
* Returns the name and namespace of the stat sheet with the given id.
11781
*
@@ -201,17 +165,6 @@ public StatSheet getStatSheet(String id) {
201165
return getStatSheet(name[0], name[1]);
202166
}
203167

204-
/**
205-
* Returns the id of the stat sheet with the given namespace and name.
206-
*
207-
* @param namespace the namespace of the stat sheet.
208-
* @param name the name of the stat sheet.
209-
* @return the id of the stat sheet with the given namespace and name.
210-
*/
211-
public String getId(String namespace, String name) {
212-
return namespace + "." + name;
213-
}
214-
215168
/**
216169
* Returns the id of the stat sheet.
217170
*
@@ -302,16 +255,6 @@ public String getStatSheetContent(String id) {
302255
return getStatSheetContent(name[0], name[1]);
303256
}
304257

305-
/**
306-
* Returns the id of the stat sheet.
307-
*
308-
* @param ss the stat sheet.
309-
* @return the id of the stat sheet.
310-
*/
311-
public String getId(StatSheet ss) {
312-
return getId(ss.namespace(), ss.name());
313-
}
314-
315258
/**
316259
* Compares two stat sheets. Internal stat sheets (null, legacy, and no stat sheet) come before
317260
* non-internal stat sheets. Among internal stat sheets, null (default) comes first, then legacy,

0 commit comments

Comments
 (0)