Skip to content

Commit

Permalink
Rewrite to be Component based
Browse files Browse the repository at this point in the history
  • Loading branch information
Brent committed Sep 11, 2023
1 parent 42b1f1a commit 93593ce
Show file tree
Hide file tree
Showing 37 changed files with 426 additions and 78 deletions.
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;
}

}
57 changes: 2 additions & 55 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 Down Expand Up @@ -681,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 Expand Up @@ -947,39 +927,6 @@ private void buildDefaultComponents() {
addComponent(Language.class);
}

/**
* Return a list of Components that should never be deleted or duplicated via the UI
* This would be better to implement this via isxxxx() methods in AbstractConfigrable
* but not all of these components are AbstractConfigurable, Sigh.
*
* @return List of Component classes
*/
public List<Class<?>> getEssentialComponents() {
return List.of(
Documentation.class,
PlayerRoster.class,
GlobalOptions.class,
GamePieceImageDefinitions.class,
GlobalProperties.class,
GlobalTranslatableMessages.class,
PrototypesContainer.class,
Chatter.class,
KeyNamer.class,
Language.class
);
}

/**
* Return a list of Components that should not be movable via the UI.
* Some Components are forced to the start of the Build sequence so that they are available
* for all subsequent components as they build
*
* @return
*/
public List<Class<?>> getImmobileComponents() {
return new ArrayList<>();
}

/**
* Initializes our actual window frame -- size, title bar. Send a message with our module name and version number
* to the chat log, to be displayed there once a Chatter is registered.
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;
}
}
Loading

0 comments on commit 93593ce

Please sign in to comment.