Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

12670 - Prevent essential components being accidentally deleted #12671

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions vassal-app/src/main/java/VASSAL/build/Buildable.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,30 @@ public interface Buildable {
* @return an XML element from which this component can be built
*/
Element getBuildElement(Document doc);

/**
* Is this component a reqired component within its parent?
*
* @return true if component is mandatory
*/
default boolean isMandatory() {
return false;
}

/**
* Is this component allowed to be moved around the Configure Tree?
* @return true is component is movable
*/
default boolean isMovable() {
return true;
}

/**
* Does this component need to be unique within it's parent?
* @return
*/
default boolean isUnique() {
return false;
}

}
25 changes: 3 additions & 22 deletions vassal-app/src/main/java/VASSAL/build/GameModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@
import VASSAL.build.module.WizardSupport;
import VASSAL.build.module.documentation.HelpFile;
import VASSAL.build.module.folder.ModuleSubFolder;
import VASSAL.build.module.gamepieceimage.ColorManager;
import VASSAL.build.module.gamepieceimage.FontManager;
import VASSAL.build.module.gamepieceimage.GamePieceImageDefinitions;
import VASSAL.build.module.gamepieceimage.GamePieceLayoutsContainer;
import VASSAL.build.module.index.IndexManager;
import VASSAL.build.module.map.CounterDetailViewer;
import VASSAL.build.module.metadata.AbstractMetaData;
Expand Down Expand Up @@ -89,7 +86,7 @@
import VASSAL.configure.CompoundValidityChecker;
import VASSAL.configure.ConfigureTree;
import VASSAL.configure.MandatoryComponent;
import VASSAL.configure.SingleChildInstance;
import VASSAL.configure.RecursiveSingleChildInstance;
import VASSAL.configure.StringArrayConfigurer;
import VASSAL.configure.StringConfigurer;
import VASSAL.configure.TextConfigurer;
Expand All @@ -106,7 +103,6 @@
import VASSAL.launch.PlayerWindow;
import VASSAL.preferences.PositionOption;
import VASSAL.preferences.Prefs;
import VASSAL.script.ScriptContainer;
import VASSAL.script.expression.Expression;
import VASSAL.tools.ArchiveWriter;
import VASSAL.tools.CRCUtils;
Expand All @@ -130,6 +126,7 @@
import VASSAL.tools.menu.MenuManager;
import VASSAL.tools.swing.SwingUtils;
import VASSAL.tools.version.VersionUtils;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -680,23 +677,7 @@ public void windowClosing(WindowEvent e) {
validator = new CompoundValidityChecker(
new MandatoryComponent(this, Documentation.class),
new MandatoryComponent(this, GlobalOptions.class))
.append(new SingleChildInstance(this, ChessClockControl.class))
.append(new SingleChildInstance(this, Documentation.class))
.append(new SingleChildInstance(this, GlobalOptions.class))
.append(new SingleChildInstance(this, PrototypesContainer.class))
.append(new SingleChildInstance(this, ColorManager.class))
.append(new SingleChildInstance(this, FontManager.class))
.append(new SingleChildInstance(this, GamePieceImageDefinitions.class))
.append(new SingleChildInstance(this, GamePieceLayoutsContainer.class))
.append(new SingleChildInstance(this, ScriptContainer.class))
.append(new SingleChildInstance(this, GlobalTranslatableMessages.class))
.append(new SingleChildInstance(this, GlobalProperties.class))
.append(new SingleChildInstance(this, Language.class))
.append(new SingleChildInstance(this, Documentation.class))
.append(new SingleChildInstance(this, PlayerRoster.class))
.append(new SingleChildInstance(this, Chatter.class))
.append(new SingleChildInstance(this, KeyNamer.class))
.append(new SingleChildInstance(this, Localization.class));
.append(new RecursiveSingleChildInstance());

addCommandEncoder(new ChangePropertyCommandEncoder(propsContainer));
}
Expand Down
10 changes: 10 additions & 0 deletions vassal-app/src/main/java/VASSAL/build/module/Chatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,16 @@ public void dropActionChanged(DropTargetDragEvent event) {
public void drop(DropTargetDropEvent dtde) {
GameModule.getGameModule().getGameState().dropFile(dtde);
}

@Override
public boolean isMandatory() {
return true;
}

@Override
public boolean isUnique() {
return true;
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -1006,4 +1006,10 @@ public void mousePressed(MouseEvent e) {
}
}
}

/** There can be only one! */
@Override
public boolean isUnique() {
return true;
}
}
10 changes: 10 additions & 0 deletions vassal-app/src/main/java/VASSAL/build/module/Documentation.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,14 @@ public void setAttribute(String name, Object value) {
public String getAttributeValueString(String name) {
return null;
}

@Override
public boolean isUnique() {
return true;
}

@Override
public boolean isMandatory() {
return true;
}
}
10 changes: 10 additions & 0 deletions vassal-app/src/main/java/VASSAL/build/module/GlobalOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -949,4 +949,14 @@ public void addImageNamesRecursively(Collection<String> s) {
s.add(c.getValueString());
}
}

@Override
public boolean isMandatory() {
return true;
}

@Override
public boolean isUnique() {
return true;
}
}
10 changes: 10 additions & 0 deletions vassal-app/src/main/java/VASSAL/build/module/KeyNamer.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,14 @@ public static String getKeyString(KeyStroke k) {
}
return StringUtils.capitalize(sb.toString().replace(' ', '_'));
}

@Override
public boolean isMandatory() {
return true;
}

@Override
public boolean isUnique() {
return true;
}
}
15 changes: 0 additions & 15 deletions vassal-app/src/main/java/VASSAL/build/module/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
import VASSAL.configure.MandatoryComponent;
import VASSAL.configure.NamedHotKeyConfigurer;
import VASSAL.configure.PlayerIdFormattedExpressionConfigurer;
import VASSAL.configure.SingleChildInstance;
import VASSAL.configure.UniquelyNamedChildren;
import VASSAL.configure.VisibilityCondition;
import VASSAL.counters.BasicPiece;
Expand Down Expand Up @@ -965,20 +964,6 @@ public void addTo(Buildable b) {
new MandatoryComponent(this, BoardPicker.class),
new MandatoryComponent(this, StackMetrics.class))
.append(idMgr)
.append(new SingleChildInstance(this, Zoomer.class))
.append(new SingleChildInstance(this, HighlightLastMoved.class))
.append(new SingleChildInstance(this, Scroller.class))
.append(new SingleChildInstance(this, ForwardToChatter.class))
.append(new SingleChildInstance(this, MenuDisplayer.class))
.append(new SingleChildInstance(this, MapCenterer.class))
.append(new SingleChildInstance(this, StackExpander.class))
.append(new SingleChildInstance(this, PieceMover.class))
.append(new SingleChildInstance(this, KeyBufferer.class))
.append(new SingleChildInstance(this, ForwardToKeyBuffer.class))
.append(new SingleChildInstance(this, GlobalProperties.class))
.append(new SingleChildInstance(this, SelectionHighlighters.class))
.append(new SingleChildInstance(this, LayeredPieceCollection.class))
.append(new SingleChildInstance(this, BoardPicker.class))
.append(new UniquelyNamedChildren(this, MapShader.class));

final DragGestureListener dgl = dge -> {
Expand Down
10 changes: 10 additions & 0 deletions vassal-app/src/main/java/VASSAL/build/module/PlayerRoster.java
Original file line number Diff line number Diff line change
Expand Up @@ -1031,4 +1031,14 @@ public ComponentI18nData getI18nData() {
c.setAttributeTranslatable(SIDES, true);
return c;
}

@Override
public boolean isMandatory() {
return true;
}

@Override
public boolean isUnique() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,14 @@ public ComponentI18nData getI18nData() {
data.setPrefix(""); //$NON-NLS-1$
return data;
}

@Override
public boolean isMandatory() {
return true;
}

@Override
public boolean isUnique() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,14 @@ public String[] getColorDisplayNames() {
}
return names.toArray(new String[0]);
}

@Override
public boolean isUnique() {
return true;
}

@Override
public boolean isMandatory() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,14 @@ public String[] getFontNames() {
}
return names.toArray(new String[0]);
}

@Override
public boolean isUnique() {
return true;
}

@Override
public boolean isMandatory() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,14 @@ public GamePieceImage getGenericDefn(String defnName) {
return definitions.getGenericDefn(defnName);

}

@Override
public boolean isUnique() {
return true;
}

@Override
public boolean isMandatory() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,15 @@ public GamePieceImage getGenericDefn(String defnName) {
}
return null;
}

@Override
public boolean isMandatory() {
return true;
}

@Override
public boolean isUnique() {
return true;
}
}

10 changes: 10 additions & 0 deletions vassal-app/src/main/java/VASSAL/build/module/map/BoardPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -897,4 +897,14 @@ public void repaint() {
public String[] getAttributeNames() {
return new String[0];
}

@Override
public boolean isMandatory() {
return true;
}

@Override
public boolean isUnique() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,14 @@ private void process(KeyEvent e) {
GameModule.getGameModule().getChatter().keyCommand(SwingUtils.getKeyStrokeForEvent(e));
}
}

@Override
public boolean isMandatory() {
return true;
}

@Override
public boolean isUnique() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,14 @@ protected void process(KeyEvent e) {
}
}
}

@Override
public boolean isMandatory() {
return true;
}

@Override
public boolean isUnique() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,14 @@ public static String getConfigureTypeName() {
public Class<?>[] getAllowableConfigureComponents() {
return new Class<?>[0];
}

@Override
public boolean isMandatory() {
return true;
}

@Override
public boolean isUnique() {
return true;
}
}
10 changes: 10 additions & 0 deletions vassal-app/src/main/java/VASSAL/build/module/map/ImageSaver.java
Original file line number Diff line number Diff line change
Expand Up @@ -458,4 +458,14 @@ public static String getConfigureTypeName() {
public Class<?>[] getAllowableConfigureComponents() {
return new Class<?>[0];
}

@Override
public boolean isMandatory() {
return true;
}

@Override
public boolean isUnique() {
return true;
}
}
10 changes: 10 additions & 0 deletions vassal-app/src/main/java/VASSAL/build/module/map/KeyBufferer.java
Original file line number Diff line number Diff line change
Expand Up @@ -680,4 +680,14 @@ public void draw(Graphics g, Map map) {
public boolean drawAboveCounters() {
return true;
}

@Override
public boolean isMandatory() {
return true;
}

@Override
public boolean isUnique() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,14 @@ public List<String> getPropertyList() {
l.addAll(Arrays.asList(collection.layerOrder));
return l;
}

@Override
public boolean isMandatory() {
return true;
}

@Override
public boolean isUnique() {
return true;
}
}
Loading