rename some stuff and be more specific on some usages

This commit is contained in:
OMGeeky
2025-06-21 20:12:17 +02:00
parent 3cc6eb9edb
commit b5a6aa6706
13 changed files with 88 additions and 55 deletions

View File

@@ -36,29 +36,6 @@ public abstract class GameDataElement implements ProjectTreeNode, Serializable {
public String id = null;
protected boolean linkCheck() {
if (checkNotRelatedToParseOrLink()) {
//This type of state is unrelated to parsing/linking.
return false;
} else if (this.state == State.init) {
//Not parsed yet.
this.parse();
} else if (this.state == State.linked) {
//Already linked.
return false;
}
return true;
}
protected boolean checkNotRelatedToParseOrLink() {
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
//This type of state is unrelated to parsing/linking.
return true;
}
return false;
}
@Override
public Enumeration<ProjectTreeNode> children() {
return null;
@@ -226,4 +203,34 @@ public abstract class GameDataElement implements ProjectTreeNode, Serializable {
public abstract List<SaveEvent> attemptSave();
/**
* Checks if the current state indicates that parsing/linking should be skipped.
* @return true if the operation should be skipped, false otherwise
*/
protected boolean shouldSkipParseOrLink() {
if (shouldSkipParse()) return true;
if (this.state == State.linked) {
//Already linked.
return true;
}
return false;
}
protected boolean shouldSkipParse() {
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
//This type of state is unrelated to parsing/linking.
return true;
}
return false;
}
/**
* Ensures the element is parsed if needed based on its current state.
*/
protected void ensureParseIfNeeded() {
if (this.state == State.init) {
//Not parsed yet.
this.parse();
}
}
}

View File

@@ -222,7 +222,10 @@ public class ActorCondition extends JSONElement {
@Override
public void link() {
if (!this.linkCheck()) return;
if (shouldSkipParseOrLink()) {
return;
}
ensureParseIfNeeded();
if (this.icon_id != null) {
String spritesheetId = this.icon_id.split(":")[0];
if (getProject().getSpritesheet(spritesheetId) == null) {

View File

@@ -205,7 +205,10 @@ public class Dialogue extends JSONElement {
@Override
public void link() {
if (!this.linkCheck()) return;
if (shouldSkipParseOrLink()) {
return;
}
ensureParseIfNeeded();
Project proj = getProject();
if (proj == null) {
Notification.addError("Error linking dialogue " + id + ". No parent project found.");

View File

@@ -128,7 +128,10 @@ public class Droplist extends JSONElement {
@Override
public void link() {
if (!this.linkCheck()) return;
if (shouldSkipParseOrLink()) {
return;
}
ensureParseIfNeeded();
Project proj = getProject();
if (proj == null) {
Notification.addError("Error linking droplist " + id + ". No parent project found.");

View File

@@ -206,7 +206,10 @@ public class Item extends JSONElement {
@Override
public void link() {
if (!this.linkCheck()) return;
if (shouldSkipParseOrLink()) {
return;
}
ensureParseIfNeeded();
Project proj = getProject();
if (proj == null) {
Notification.addError("Error linking item " + id + ". No parent project found.");

View File

@@ -171,7 +171,10 @@ public class ItemCategory extends JSONElement {
@Override
public void link() {
if (!this.linkCheck()) return;
if (shouldSkipParseOrLink()) {
return;
}
ensureParseIfNeeded();
//Nothing to link to :D
this.state = State.linked;

View File

@@ -21,8 +21,7 @@ public abstract class JSONElement extends GameDataElement {
@SuppressWarnings("rawtypes")
public void parse() {
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
//This type of state is unrelated to parsing/linking.
if (shouldSkipParse()) {
return;
}
JSONParser parser = new JSONParser();

View File

@@ -210,7 +210,10 @@ public class NPC extends JSONElement {
@Override
public void link() {
if (!this.linkCheck()) return;
if (shouldSkipParseOrLink()) {
return;
}
ensureParseIfNeeded();
Project proj = getProject();
if (proj == null) {
Notification.addError("Error linking item " + id + ". No parent project found.");

View File

@@ -112,7 +112,10 @@ public class Quest extends JSONElement {
@Override
public void link() {
if (!this.linkCheck()) return;
if (shouldSkipParseOrLink()) {
return;
}
ensureParseIfNeeded();
for (QuestStage stage : stages) {
stage.link();

View File

@@ -59,7 +59,10 @@ public class QuestStage extends JSONElement {
@Override
public void link() {
if (!this.linkCheck()) return;
if (shouldSkipParseOrLink()) {
return;
}
ensureParseIfNeeded();
//Nothing to link to :D
this.state = State.linked;

View File

@@ -122,7 +122,10 @@ public class Requirement extends JSONElement {
@Override
public void link() {
if (!this.linkCheck()) return;
if (shouldSkipParseOrLink()) {
return;
}
ensureParseIfNeeded();
Project proj = getProject();
if (proj == null) {
Notification.addError("Error linking requirement " + getDesc() + ". No parent project found.");

View File

@@ -530,7 +530,7 @@ public class WriterModeData extends GameDataElement {
@SuppressWarnings("rawtypes")
public void parse() {
if (checkNotRelatedToParseOrLink()) return;
if (shouldSkipParse()) return;
JSONParser parser = new JSONParser();
FileReader reader = null;
try {

View File

@@ -29,23 +29,23 @@ public class UiUtils {
}
public static <S, E, M extends OrderedListenerListModel<S, E>> CollapsibleItemListCreation<E> getCollapsibleItemList(FieldUpdateListener listener,
M itemsListModel,
BasicLambda selectedItemReset,
BasicLambdaWithArg<E> setSelectedItem,
BasicLambdaWithReturn<E> selectedItem,
M listModel,
BasicLambda selectedReset,
BasicLambdaWithArg<E> setSelected,
BasicLambdaWithReturn<E> getSelected,
BasicLambdaWithArg<E> valueChanged,
BasicLambdaWithArg<JPanel> updateEditorPane,
boolean writable,
Supplier<E> tempSupplier,
Supplier<E> newValueSupplier,
DefaultListCellRenderer cellRenderer,
String title,
BasicLambdaWithArgAndReturn<E, GameDataElement> getReferencedObj) {
CollapsiblePanel itemsPane = new CollapsiblePanel(title);
itemsPane.setLayout(new JideBoxLayout(itemsPane, JideBoxLayout.PAGE_AXIS));
final JList<E> itemsList = new JList<>(itemsListModel);
itemsList.setCellRenderer(cellRenderer);
itemsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
itemsPane.add(new JScrollPane(itemsList), JideBoxLayout.FIX);
final JList<E> list = new JList<>(listModel);
list.setCellRenderer(cellRenderer);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
itemsPane.add(new JScrollPane(list), JideBoxLayout.FIX);
final JPanel editorPane = new JPanel();
final JButton createBtn = new JButton(new ImageIcon(DefaultIcons.getCreateIcon()));
final JButton deleteBtn = new JButton(new ImageIcon(DefaultIcons.getNullifyIcon()));
@@ -54,18 +54,18 @@ public class UiUtils {
deleteBtn.setEnabled(false);
moveUpBtn.setEnabled(false);
moveDownBtn.setEnabled(false);
itemsList.addListSelectionListener(e -> {
E selectedValue = itemsList.getSelectedValue();
list.addListSelectionListener(e -> {
E selectedValue = list.getSelectedValue();
valueChanged.doIt(selectedValue);
setSelectedItem.doIt(selectedValue);
setSelected.doIt(selectedValue);
if (selectedValue == null) {
deleteBtn.setEnabled(false);
moveUpBtn.setEnabled(false);
moveDownBtn.setEnabled(false);
} else {
deleteBtn.setEnabled(true);
moveUpBtn.setEnabled(itemsList.getSelectedIndex() > 0);
moveDownBtn.setEnabled(itemsList.getSelectedIndex() < (itemsListModel.getSize() - 1));
moveUpBtn.setEnabled(list.getSelectedIndex() > 0);
moveDownBtn.setEnabled(list.getSelectedIndex() < (listModel.getSize() - 1));
}
updateEditorPane.doIt(editorPane);
@@ -74,14 +74,14 @@ public class UiUtils {
JPanel listButtonsPane = new JPanel();
listButtonsPane.setLayout(new JideBoxLayout(listButtonsPane, JideBoxLayout.LINE_AXIS, 6));
addRemoveAndAddButtons(listener, itemsListModel, selectedItemReset, selectedItem, tempSupplier, createBtn, itemsList, listButtonsPane, deleteBtn);
addMoveButtonListeners(listener, itemsListModel, selectedItem, moveUpBtn, itemsList, listButtonsPane, moveDownBtn);
addRemoveAndAddButtons(listener, listModel, selectedReset, getSelected, newValueSupplier, createBtn, list, listButtonsPane, deleteBtn);
addMoveButtonListeners(listener, listModel, getSelected, moveUpBtn, list, listButtonsPane, moveDownBtn);
listButtonsPane.add(new JPanel(), JideBoxLayout.VARY);
itemsPane.add(listButtonsPane, JideBoxLayout.FIX);
}
addNavigationListeners(getReferencedObj, itemsList);
addNavigationListeners(getReferencedObj, list);
editorPane.setLayout(new JideBoxLayout(editorPane, JideBoxLayout.PAGE_AXIS));
itemsPane.add(editorPane, JideBoxLayout.FIX);
@@ -89,14 +89,14 @@ public class UiUtils {
return new CollapsibleItemListCreation<E>() {
{
collapsiblePanel = itemsPane;
list = itemsList;
list = list;
}
};
}
private static <S, E, M extends OrderedListenerListModel<S, E>> void addRemoveAndAddButtons(FieldUpdateListener listener, M itemsListModel, BasicLambda selectedItemReset, BasicLambdaWithReturn<E> selectedItem, Supplier<E> tempSupplier, JButton createBtn, JList<E> itemsList, JPanel listButtonsPane, JButton deleteBtn) {
private static <S, E, M extends OrderedListenerListModel<S, E>> void addRemoveAndAddButtons(FieldUpdateListener listener, M itemsListModel, BasicLambda selectedItemReset, BasicLambdaWithReturn<E> selectedItem, Supplier<E> newValueSupplier, JButton createBtn, JList<E> itemsList, JPanel listButtonsPane, JButton deleteBtn) {
createBtn.addActionListener(e -> {
E tempItem = tempSupplier.get();
E tempItem = newValueSupplier.get();
itemsListModel.addItem(tempItem);
itemsList.setSelectedValue(tempItem, true);
listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.