Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ public JsonElement jsonEvaluate(JsonElement jsonElement, MapToolVariableResolver
*/
public String jsonIndent(JsonElement json, int indent) {
final Gson gsonPrettyPrinting =
new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
new GsonBuilder().setPrettyPrinting().serializeNulls().disableHtmlEscaping().create();

try (final Writer writer = new StringWriter()) {
final JsonWriter jWriter = gsonPrettyPrinting.newJsonWriter(writer);
Expand Down
26 changes: 8 additions & 18 deletions src/main/java/net/rptools/maptool/client/tool/Toolbox.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,19 @@ public void setSelectedTool(Class<? extends Tool> toolClass) {
public void setSelectedTool(final Tool tool) {
EventQueue.invokeLater(
() -> {
if (tool == currentTool) {
if (tool == null || tool == currentTool || !tool.isAvailable()) {
return;
}

detach();
var accepted = makeCurrent(tool);
if (accepted) {
attach();

currentTool = tool;
tool.setSelected(true);
if (MapTool.getFrame() != null) {
MapTool.getFrame().setStatusMessage(I18N.getText(currentTool.getInstructions()));
}

attach();
});
}

Expand Down Expand Up @@ -155,18 +159,4 @@ private void detach() {
}
}
}

private boolean makeCurrent(Tool tool) {
if (tool == null || !tool.isAvailable()) {
return false;
}

currentTool = tool;
tool.setSelected(true);
if (MapTool.getFrame() != null) {
MapTool.getFrame().setStatusMessage(I18N.getText(currentTool.getInstructions()));
}

return true;
}
}
21 changes: 20 additions & 1 deletion src/main/java/net/rptools/maptool/model/AssetLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ public synchronized void removeAllRepositories() {
repositoryStateMap.clear();
}

/**
* Check whether there is currently a pending request for the given asset ID.
*
* <p>NOTE: This may be immediately incorrect by the time this function returns so decisions on
* whether to request an asset must not depend on the result.
*
* @return true if there is an incomplete request.
*/
public synchronized boolean isIdRequested(MD5Key id) {
return requestedIdSet.contains(id);
}
Expand Down Expand Up @@ -226,9 +234,20 @@ protected File getRepoIndexFile(String repository) {
return new File(REPO_CACHE_DIR.getAbsolutePath() + "/" + new MD5Key(repository.getBytes()));
}

public synchronized void requestAsset(MD5Key id) {
/**
* Submit a new request to retrieve the asset with the given ID if needed.
*
* @param id The ID of the asset to request.
* @return false if there was already a request, true if a new request was submitted.
*/
public synchronized boolean requestAsset(MD5Key id) {
if (requestedIdSet.contains(id)) {
return false;
}

retrievalThreadPool.submit(new ImageRetrievalRequest(id, createRequestQueue(id)));
requestedIdSet.add(id);
return true;
}

public synchronized void completeRequest(MD5Key id) {
Expand Down
16 changes: 1 addition & 15 deletions src/main/java/net/rptools/maptool/model/AssetManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,6 @@ public static void updateRepositoryList() {
}
}

/**
* Determine if the asset is currently being requested. While an asset is being loaded it will be
* marked as requested and this function will return true. Once the asset is done loading this
* function will return false and the asset will be available from the cache.
*
* @param key MD5Key of asset being requested
* @return True if asset is currently being requested, false otherwise
*/
public static boolean isAssetRequested(MD5Key key) {
return assetLoader.isIdRequested(key);
}

/**
* Register a listener with the asset manager. The listener will be notified when the asset is
* done loading.
Expand Down Expand Up @@ -300,9 +288,7 @@ public static void getAssetAsynchronously(

// Let's get it from the server
// As a last resort we request the asset from the server
if (!isAssetRequested(id)) {
requestAssetFromServer(id, listeners);
}
requestAssetFromServer(id, listeners);
});
}

Expand Down