Skip to content

Commit

Permalink
Merge branch 'develop' into changeLog1110alpha6
Browse files Browse the repository at this point in the history
  • Loading branch information
Phergus authored Nov 30, 2021
2 parents ca7c957 + f49e2f5 commit 41fab4d
Show file tree
Hide file tree
Showing 47 changed files with 1,915 additions and 138 deletions.
4 changes: 2 additions & 2 deletions src/main/java/net/rptools/lib/io/PackedFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,8 @@ public Asset getAsset(String path) throws IOException {
}
}

if (id == null || name == null || extension == null || type == null) {
log.error("Error reading asset, missing id, name, extension, or type.");
if (id == null || name == null || extension == null) {
log.error("Error reading asset, missing id, name, extension.");
return null;
}

Expand Down
17 changes: 9 additions & 8 deletions src/main/java/net/rptools/maptool/client/AppActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import net.rptools.maptool.client.ui.StartServerDialogPreferences;
import net.rptools.maptool.client.ui.StaticMessageDialog;
import net.rptools.maptool.client.ui.SysInfoDialog;
import net.rptools.maptool.client.ui.addon.AddOnLibrariesDialog;
import net.rptools.maptool.client.ui.assetpanel.AssetPanel;
import net.rptools.maptool.client.ui.assetpanel.Directory;
import net.rptools.maptool.client.ui.campaignproperties.CampaignPropertiesDialog;
Expand Down Expand Up @@ -118,8 +119,6 @@
import net.rptools.maptool.model.ZonePoint;
import net.rptools.maptool.model.campaign.CampaignManager;
import net.rptools.maptool.model.drawing.DrawableTexturePaint;
import net.rptools.maptool.model.library.LibraryManager;
import net.rptools.maptool.model.library.addon.AddOnLibraryImporter;
import net.rptools.maptool.model.player.LocalPlayer;
import net.rptools.maptool.model.player.PasswordDatabaseException;
import net.rptools.maptool.model.player.PasswordFilePlayerDatabase;
Expand Down Expand Up @@ -2966,8 +2965,8 @@ protected void executeAction() {
}
};

private static class MapPreviewFileChooser extends PreviewPanelFileChooser {
MapPreviewFileChooser() {
public static class MapPreviewFileChooser extends PreviewPanelFileChooser {
public MapPreviewFileChooser() {
super();
addChoosableFileFilter(MapTool.getFrame().getMapFileFilter());
}
Expand Down Expand Up @@ -3253,10 +3252,10 @@ protected void executeAction() {
}
};

public static final Action IMPORT_DROP_IN_LIBRARY =
public static final Action VIEW_ADD_ON_LIBRARIES =
new DefaultClientAction() {
{
init("action.importLibrary");
init("action.addOnLibraries");
}

@Override
Expand All @@ -3267,7 +3266,9 @@ public boolean isAvailable() {

@Override
protected void executeAction() {
JFileChooser chooser = new MapPreviewFileChooser();
new AddOnLibrariesDialog().show();
// TODO: CDW
/*JFileChooser chooser = new MapPreviewFileChooser();
chooser.setDialogTitle(I18N.getText("library.dialog.import.title"));
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setFileFilter(AddOnLibraryImporter.getAddOnLibraryFileFilter());
Expand All @@ -3288,7 +3289,7 @@ protected void executeAction() {
} catch (IOException | InterruptedException | ExecutionException ioException) {
MapTool.showError("library.import.ioError", ioException);
}
}
}*/
}
};

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/net/rptools/maptool/client/AppPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class AppPreferences {
private static final String KEY_SAVE_TOKEN_DIR = "saveTokenDir";
private static final String KEY_SAVE_MAP_DIR = "saveMapDir";
private static final String KEY_LOAD_DIR = "loadDir";
private static final String KEY_ADD_ON_LOAD_DIR = "addOnLoadDir";
private static final String KEY_MRU_CAMPAIGNS = "mruCampaigns";
private static final String KEY_SAVED_PAINT_TEXTURES = "savedTextures";

Expand Down Expand Up @@ -1016,6 +1017,15 @@ public static File getLoadDir() {
return filePath != null ? new File(filePath) : new File(File.separator);
}

public static File getAddOnLoadDir() {
String filePath = prefs.get(KEY_ADD_ON_LOAD_DIR, null);
return filePath != null ? new File(filePath) : getSaveDir();
}

public static void setAddOnLoadDir(File file) {
prefs.put(KEY_ADD_ON_LOAD_DIR, file.toString());
}

public static void addAssetRoot(File root) {
String list = prefs.get(KEY_ASSET_ROOTS, "");
if (!list.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected URLConnection openConnection(URL u) {
return new AssetURLConnection(u);
}

private static class AssetURLConnection extends URLConnection {
public static class AssetURLConnection extends URLConnection {

public AssetURLConnection(URL url) {
super(url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public DataFunctions() {
super(
0,
4,
/* Commented out are only used for debugging.
"data.listTypes",
"data.listNamespaces",
"data.createNamespace",
Expand All @@ -51,7 +52,7 @@ public DataFunctions() {
"data.listData",
"data.clearData",
"data.clearNamespace",
"data.clearAllData",
"data.clearAllData",*/
"data.getStaticData");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import net.rptools.maptool.client.MapTool;
import net.rptools.maptool.language.I18N;
import net.rptools.maptool.model.library.Library;
import net.rptools.maptool.model.library.LibraryInfo;
Expand All @@ -42,9 +41,7 @@ public LibraryFunctions() {
"library.listAddOnLibraries",
"library.getInfo",
"library.listTokenLibraries",
"library.getContents",
"library.removeAddOn",
"library.removeAllAddOns");
"library.getContents");
}

@Override
Expand All @@ -59,7 +56,7 @@ public Object childEvaluate(
switch (fName) {
case "library.listaddonlibraries" -> {
FunctionUtil.checkNumberParam(functionName, parameters, 0, 0);
return librariesAsJson(libraryManager.getLibraries(LibraryType.DROP_IN));
return librariesAsJson(libraryManager.getLibraries(LibraryType.ADD_ON));
}
case "library.getinfo" -> {
FunctionUtil.checkNumberParam(functionName, parameters, 1, 1);
Expand Down Expand Up @@ -88,23 +85,6 @@ public Object childEvaluate(
}
}

case "library.removeaddon" -> {
MapTool.addLocalMessage(I18N.getText("msg.warning.prerelease.only", functionName));
FunctionUtil.blockUntrustedMacro(functionName);
FunctionUtil.checkNumberParam(functionName, parameters, 1, 1);
String namespace = parameters.get(0).toString();
new LibraryManager().removeAddOnLibrary(namespace);
return "";
}

case "library.removealladdons" -> {
MapTool.addLocalMessage(I18N.getText("msg.warning.prerelease.only", functionName));
FunctionUtil.blockUntrustedMacro(functionName);
FunctionUtil.checkNumberParam(functionName, parameters, 0, 0);
new LibraryManager().removeAddOnLibraries();
return "";
}

default -> throw new ParserException(
I18N.getText("macro.function.general.unknownFunction", functionName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public Object childEvaluate(
return currentZR.getZone().getName();
}
} else if (functionName.equalsIgnoreCase("getMapDisplayName")) {
checkTrusted(functionName);
FunctionUtil.checkNumberParam(functionName, parameters, 0, 1);
if (parameters.size() == 0) {
ZoneRenderer currentZR = MapTool.getFrame().getCurrentZoneRenderer();
Expand All @@ -81,9 +82,6 @@ public Object childEvaluate(
List<ZoneRenderer> rendererList =
new LinkedList<ZoneRenderer>(
MapTool.getFrame().getZoneRenderers()); // copied from ZoneSelectionPopup
if (!MapTool.getPlayer().isGM()) {
rendererList.removeIf(renderer -> !renderer.getZone().isVisible());
}
String searchMap = parameters.get(0).toString();
String foundMap = null;
for (int i = 0; i < rendererList.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected JMenu createFileMenu() {
fileMenu.add(createExportMenu());
fileMenu.addSeparator();
fileMenu.add(new JMenuItem(AppActions.ADD_RESOURCE_TO_LIBRARY));
fileMenu.add(new JMenuItem(AppActions.IMPORT_DROP_IN_LIBRARY));
fileMenu.add(new JMenuItem(AppActions.VIEW_ADD_ON_LIBRARIES));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem(AppActions.START_SERVER));
fileMenu.add(new JMenuItem(AppActions.CONNECT_TO_SERVER));
Expand Down
176 changes: 176 additions & 0 deletions src/main/java/net/rptools/maptool/client/ui/ViewAssetDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/*
* This software Copyright by the RPTools.net development team, and
* licensed under the Affero GPL Version 3 or, at your option, any later
* version.
*
* MapTool Source Code is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public
* License * along with this source Code. If not, please visit
* <http://www.gnu.org/licenses/> and specifically the Affero license
* text at <http://www.gnu.org/licenses/agpl.html>.
*/
package net.rptools.maptool.client.ui;

import com.vladsch.flexmark.ext.definition.DefinitionExtension;
import com.vladsch.flexmark.ext.gfm.tasklist.TaskListExtension;
import com.vladsch.flexmark.ext.tables.TablesExtension;
import com.vladsch.flexmark.ext.toc.TocExtension;
import com.vladsch.flexmark.html.HtmlRenderer;
import com.vladsch.flexmark.parser.ParserEmulationProfile;
import com.vladsch.flexmark.util.ast.Node;
import com.vladsch.flexmark.util.data.MutableDataHolder;
import com.vladsch.flexmark.util.data.MutableDataSet;
import com.vladsch.flexmark.util.misc.Extension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.List;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebView;
import javax.swing.JDialog;
import net.rptools.lib.swing.SwingUtil;
import net.rptools.maptool.client.MapTool;
import net.rptools.maptool.model.Asset;

/**
* Creates a dialog that can be used to view an asset. Currently, only supports Plain Text, HTML,
* and Markdown.
*/
public class ViewAssetDialog {
/** The Swing Dialog to display the asset in. */
private final JDialog dialog;

/** Embedded JavaFX panel used to display the asset. */
private final JFXPanel jfxPanel;

/** The width of the dialog, */
private final int width;

/** The height of the dialog, */
private final int height;

/**
* Creates a new ViewAssetDialog.
*
* @param asset the asset to display.
* @param title the title of the dialog.
* @param width the width of the dialog.
* @param height the height of the dialog.
* @throws IllegalArgumentException if the asset type is not supported.
*/
public ViewAssetDialog(Asset asset, String title, int width, int height) {
dialog = new JDialog(MapTool.getFrame(), title);
dialog.setSize(width, height);
this.width = width;
this.height = height;
jfxPanel = new JFXPanel();

dialog.getContentPane().add(jfxPanel);

switch (asset.getType()) {
case TEXT -> textDialog(asset);
case HTML -> htmlDialog(asset);
case MARKDOWN -> markdownDialog(asset);
default -> throw new IllegalArgumentException("Unsupported asset type: " + asset.getType());
}

dialog.addWindowListener(
new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
dialog.dispose();
}
});
}

/**
* Creates a markdown control to display the asset.
*
* @param asset the asset to display.
*/
private void markdownDialog(Asset asset) {
List<Extension> extensions =
List.of(
TablesExtension.create(),
TaskListExtension.create(),
DefinitionExtension.create(),
TocExtension.create());
MutableDataHolder options = new MutableDataSet();
options
.set(com.vladsch.flexmark.parser.Parser.SPACE_IN_LINK_URLS, true)
.setFrom(ParserEmulationProfile.GITHUB_DOC)
.set(TablesExtension.COLUMN_SPANS, false)
.set(TablesExtension.APPEND_MISSING_COLUMNS, true)
.set(TablesExtension.DISCARD_EXTRA_COLUMNS, true)
.set(TablesExtension.HEADER_SEPARATOR_COLUMN_MATCH, true)
.set(com.vladsch.flexmark.parser.Parser.EXTENSIONS, extensions);

var mdParser = com.vladsch.flexmark.parser.Parser.builder(options).build();
HtmlRenderer renderer = HtmlRenderer.builder(options).build();

Node document = mdParser.parse(asset.getDataAsString());

htmlDialog(renderer.render(document));
}

/**
* Creates a html control to display the asset.
*
* @param asset the asset to display.
*/
private void htmlDialog(Asset asset) {
htmlDialog(asset.getDataAsString());
}

/**
* Creates a html control to display a string.
*
* @param html the html to display.
*/
private void htmlDialog(String html) {
Platform.runLater(
() -> {
var pane = new StackPane();
var scene = new Scene(pane, width, height);
jfxPanel.setScene(scene);
var webView = new WebView();
webView.getEngine().loadContent(html);
pane.getChildren().add(webView);
});
}

/**
* Creates a text control to display the asset.
*
* @param asset the asset to display.
*/
private void textDialog(Asset asset) {
Platform.runLater(
() -> {
var pane = new StackPane();
var scene = new Scene(pane, width, height);
jfxPanel.setScene(scene);
var textArea = new TextArea(asset.getDataAsString());
textArea.setEditable(false);
pane.getChildren().add(textArea);
});
}

/** Displays the dialog. */
public void show() {
SwingUtil.centerOver(dialog, dialog.getOwner());
dialog.setVisible(true);
}

/** Displays the dialog in a modal state. */
public void showModal() {
dialog.setModal(true);
show();
}
}
Loading

0 comments on commit 41fab4d

Please sign in to comment.