Skip to content

Commit e2a4750

Browse files
authored
Merge pull request #5894 from kwvanderlinde/bugfix/5643-null-stat-sheet-location
Fix null stat sheet location
2 parents b5802c2 + 011c225 commit e2a4750

File tree

7 files changed

+15
-78
lines changed

7 files changed

+15
-78
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
@@ -487,9 +487,8 @@ private void populateStatSheetComboBoxes(String propertyType) {
487487
var statSheetProperty = tokenTypeStatSheetMap.get(propertyType);
488488
String id;
489489
if (statSheetProperty == null) {
490-
id = ssManager.getDefaultStatSheetId();
491-
tokenTypeStatSheetMap.put(
492-
propertyType, new StatSheetProperties(ssManager.getDefaultStatSheetId(), null));
490+
id = StatSheetManager.LEGACY_STATSHEET.id();
491+
tokenTypeStatSheetMap.put(propertyType, new StatSheetProperties(id, null));
493492
} else {
494493
id = statSheetProperty.id();
495494
}
@@ -522,7 +521,7 @@ public void initStatSheetDetails() {
522521
if (getStatSheetComboBox().hasFocus()) { // Only if user has made change
523522
var tokenType = (String) getTokenTypeList().getSelectedValue();
524523
if (ss != null && tokenType != null) {
525-
var id = new StatSheetManager().getId(ss);
524+
var id = ss.id();
526525
var location = tokenTypeStatSheetMap.get(tokenType).location();
527526
tokenTypeStatSheetMap.put(tokenType, new StatSheetProperties(id, location));
528527
getStatSheetLocationComboBox().setSelectedItem(location);

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +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-
if (location == null) {
174-
location = StatSheetLocation.BOTTOM_LEFT;
175-
}
176-
token.setStatSheet(new StatSheetProperties(ssManager.getId(statSheet), location));
172+
token.setStatSheet(new StatSheetProperties(statSheet.id(), location));
177173
}
178174

179175
return true;

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -908,12 +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-
if (location == null) {
914-
location = StatSheetLocation.BOTTOM_LEFT;
915-
}
916-
token.setStatSheet(new StatSheetProperties(ssManager.getId(ss), location));
912+
token.setStatSheet(new StatSheetProperties(ss.id(), location));
917913
}
918914

919915
/* Macros */

src/main/java/net/rptools/maptool/model/CampaignProperties.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import net.rptools.maptool.client.ui.token.YieldTokenOverlay;
5151
import net.rptools.maptool.language.I18N;
5252
import net.rptools.maptool.model.drawing.DrawableColorPaint;
53-
import net.rptools.maptool.model.sheet.stats.StatSheetLocation;
5453
import net.rptools.maptool.model.sheet.stats.StatSheetManager;
5554
import net.rptools.maptool.model.sheet.stats.StatSheetProperties;
5655
import net.rptools.maptool.server.proto.CampaignPropertiesDto;
@@ -212,9 +211,7 @@ public Map<String, List<TokenProperty>> getTokenTypeMap() {
212211
*/
213212
public StatSheetProperties getTokenTypeDefaultStatSheet(String propertyType) {
214213
return tokenTypeStatSheetMap.getOrDefault(
215-
propertyType,
216-
new StatSheetProperties(
217-
StatSheetManager.LEGACY_STATSHEET_ID, StatSheetLocation.BOTTOM_LEFT));
214+
propertyType, new StatSheetProperties(StatSheetManager.LEGACY_STATSHEET_ID, null));
218215
}
219216

220217
/**

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,

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package net.rptools.maptool.model.sheet.stats;
1616

1717
import java.util.Objects;
18+
import javax.annotation.Nullable;
1819
import net.rptools.maptool.server.proto.StatSheetPropertiesDto;
1920

2021
/**
@@ -33,11 +34,12 @@ public final class StatSheetProperties {
3334
* Creates a new instance of the class.
3435
*
3536
* @param id The id of the stat sheet.
36-
* @param location The location of the stat sheet.
37+
* @param location The location of the stat sheet, or {@code null} to use the default of {@link
38+
* StatSheetLocation#BOTTOM_LEFT}.
3739
*/
38-
public StatSheetProperties(String id, StatSheetLocation location) {
40+
public StatSheetProperties(String id, @Nullable StatSheetLocation location) {
3941
this.id = id;
40-
this.location = location;
42+
this.location = Objects.requireNonNullElse(location, StatSheetLocation.BOTTOM_LEFT);
4143
}
4244

4345
/**

0 commit comments

Comments
 (0)