Skip to content

Commit

Permalink
Map Tags & Use Maps Server (triplea_maps.yml now unused)
Browse files Browse the repository at this point in the history
__Always use Maps Server__
  Stop reading 'triplea_maps.yml'
  Specifically instead of downloading the 'triplea_maps.yml'
  file and parsing it, the front end will instead contact
  the server and receive a JSON payload that contains the
  map download list.

__Introduce and use map tags__
   Map tags are a generic
  way to add additional meta data to maps dynamically.
  For example, instead of having a 'category' value
  specifically enumerated, we instead now have a
  tag whose key is 'category'. This allows us to have
  an arbitrary set of meta information without
  needing to update the front end.

__Update server to send 'preview image url' to the frontend__
  The server computes the preview image URL to make it easier
  and more explicit for the frontend. Having the server
  instead of the client compute the preview image URL also
  allows for it to be updated in database.
  • Loading branch information
DanVanAtta committed Aug 11, 2021
1 parent f243a00 commit bc7c66a
Show file tree
Hide file tree
Showing 42 changed files with 568 additions and 263 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package games.strategy.engine.framework.map.download;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
Expand All @@ -9,6 +10,7 @@
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import org.triplea.http.client.maps.listing.MapDownloadListing;
import org.triplea.http.client.maps.listing.MapTag;
import org.triplea.swing.JTableBuilder;

/**
Expand All @@ -19,17 +21,53 @@ public class MapDownloadSwingTable {
private final JTable table;

public MapDownloadSwingTable(final Collection<MapDownloadListing> maps) {
// Build a jtable that has n+1 columns, the first column (+1) is the map name,
// the 'n' columns are one for each tag.
// Note, not all maps have all tags (potentially sparse), we will display a blank
// value if a map does not have a given tag.

final List<String> columnNames = new ArrayList<>();
columnNames.add("Map");

// Get the full set of all tag names in display order
final List<String> tagNames =
maps.stream()
.map(MapDownloadListing::getMapTags)
.flatMap(Collection::stream)
.sorted(Comparator.comparing(MapTag::getDisplayOrder))
.map(MapTag::getName)
.distinct()
.collect(Collectors.toList());

columnNames.addAll(tagNames); // .stream().map(MapTag::getName).collect(Collectors.toList()));

table =
JTableBuilder.<MapDownloadListing>builder()
.columnNames("Map", "Category")
.columnNames(columnNames)
.rowData(
maps.stream()
.sorted(Comparator.comparing(MapDownloadListing::getMapName))
.collect(Collectors.toList()))
.rowMapper(map -> List.of(map.getMapName(), map.getMapCategory()))
.rowMapper(mapDownloadListing -> rowMapper(mapDownloadListing, tagNames))
.build();
}

/**
* Given a download item and a set of tags (in correct display order), returns values for a table
* row, map name and then each of the map's tag values.
*/
private List<String> rowMapper(
final MapDownloadListing mapDownloadListing, final List<String> mapTags) {
final List<String> rowValues = new ArrayList<>();
rowValues.add(mapDownloadListing.getMapName());

for (final String tag : mapTags) {
final String tagValue = mapDownloadListing.getTagValue(tag);
rowValues.add(tagValue);
}
return rowValues;
}

public JTable getSwingComponent() {
// select first row, will trigger any selection listeners
table.setRowSelectionInterval(0, 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package games.strategy.engine.framework.map.listing;

import games.strategy.engine.framework.map.download.DownloadRunnable;
import games.strategy.triplea.UrlConstants;
import games.strategy.triplea.settings.ClientSetting;
import java.util.List;
import lombok.experimental.UtilityClass;
import org.triplea.http.client.maps.listing.MapDownloadListing;
import org.triplea.http.client.maps.listing.MapsListingClient;
import org.triplea.http.client.maps.listing.MapsListingHttpClient;
import org.triplea.live.servers.LiveServersFetcher;

Expand All @@ -15,11 +11,7 @@ public class MapListingFetcher {

/** Fetches the full listing of maps that are available for download. */
public static List<MapDownloadListing> getMapDownloadList() {
final MapsListingClient mapsListingClient =
ClientSetting.useMapsServerBetaFeature.getValue().orElse(false)
? new MapsListingHttpClient(new LiveServersFetcher().serverForCurrentVersion().getUri())
: new DownloadRunnable(UrlConstants.MAP_DOWNLOAD_LIST);

return mapsListingClient.fetchMapDownloads();
final var serverUri = new LiveServersFetcher().serverForCurrentVersion().getUri();
return new MapsListingHttpClient(serverUri).fetchMapDownloads();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ public abstract class ClientSetting<T> implements GameSetting<T> {
new BooleanClientSetting("USE_WEBSOCKET_NETWORK");
public static final ClientSetting<Boolean> showSerializeFeatures =
new BooleanClientSetting("SHOW_SERIALIZE_FEATURES");
public static final ClientSetting<Boolean> useMapsServerBetaFeature =
new BooleanClientSetting("USE_MAPS_SERVER_BETA_FEATURES");
public static final BooleanClientSetting showChatTimeSettings =
new BooleanClientSetting("SHOW_CHAT_TIME");
public static final BooleanClientSetting showCommentLog =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,16 +267,6 @@ public SelectionComponent<JComponent> newSelectionComponent() {
}
},

USE_MAPS_SERVER_BETA_FEATURE(
"Use Maps Server (Beta)",
SettingType.TESTING,
"Toggles whether to use the in 'beta' map server") {
@Override
public SelectionComponent<JComponent> newSelectionComponent() {
return booleanRadioButtons(ClientSetting.useMapsServerBetaFeature);
}
},

LOBBY_URI_OVERRIDE_BINDING("Lobby URI Override", SettingType.TESTING, "Overrides the lobby URI") {
@Override
public SelectionComponent<JComponent> newSelectionComponent() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ private static MapDownloadListing buildDownloadDescription(
.mapName(mapName)
.version(version)
.downloadUrl("url")
.mapCategory("category")
.previewImageUrl("preview-url")
.lastCommitDateEpochMilli(50L)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ void testBasicStartCancel() {
final MapDownloadListing mapDownloadListing =
MapDownloadListing.builder()
.downloadUrl("url")
.previewImageUrl("preview-url")
.description("description")
.mapName("mapName")
.version(0)
.mapCategory("BEST")
.lastCommitDateEpochMilli(60L)
.build();
final DownloadFile testObj = new DownloadFile(mapDownloadListing, mock(DownloadListener.class));
assertThat(testObj.getDownloadState(), is(DownloadState.NOT_STARTED));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ class DownloadMapsWindowMapsListingTest extends AbstractClientSettingTestCase {
private static final MapDownloadListing TEST_MAP =
MapDownloadListing.builder()
.downloadUrl("")
.previewImageUrl("")
.mapName(MAP_NAME)
.version(MAP_VERSION)
.mapCategory("EXPERIMENTAL")
.description("description")
.lastCommitDateEpochMilli(10L)
.build();

@Test
Expand Down Expand Up @@ -61,20 +62,22 @@ void testAvailableExcluding() {
private static MapDownloadListing newDownloadWithUrl(final String url) {
return MapDownloadListing.builder()
.downloadUrl(url)
.previewImageUrl(url)
.description("description")
.mapName("mapName " + url)
.version(MAP_VERSION)
.mapCategory("BEST")
.lastCommitDateEpochMilli(40L)
.build();
}

private static MapDownloadListing newInstalledDownloadWithUrl(final String url) {
return MapDownloadListing.builder()
.downloadUrl(url)
.previewImageUrl(url)
.description("description")
.mapName("mapName " + url)
.version(MAP_VERSION)
.mapCategory("BEST")
.lastCommitDateEpochMilli(30L)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
package org.triplea.http.client.maps.listing;

import java.util.List;
import javax.annotation.Nonnull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

@Builder
@AllArgsConstructor
@Getter
@ToString
@EqualsAndHashCode
public class MapDownloadListing {
/** URL where the map can be downloaded. */
@Nonnull private final String downloadUrl;
/** URL of the preview image of the map. */
private final String previewImageUrl;
@Nonnull private final String previewImageUrl;

@Nonnull private final String mapName;
private final Long lastCommitDateEpochMilli;
@Nonnull private final String mapCategory;
@Nonnull private final Long lastCommitDateEpochMilli;
/** HTML description of the map. */
@Nonnull private final String description;
/** @deprecated use lastCommitDateEpochMilli and file time stamps instead. */
@Deprecated private final Integer version;

/** Mapping of {tag name -> tag value} */
private final List<MapTag> mapTags;

/**
* Finds a tag by name and returns its corresponding value. If the tag is not found or has a null
* value, an empty string is returned instead.
*/
@Nonnull
public String getTagValue(final String tagName) {
return mapTags.stream()
.filter(tag -> tag.getName().equalsIgnoreCase(tagName))
.findAny()
.map(MapTag::getValue)
.orElse("");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.triplea.http.client.maps.listing;

import java.util.Optional;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Value;

@Value
@Builder
@EqualsAndHashCode
public class MapTag {
/** The human readable name of the tag */
String name;

/** The actual value of the tag */
String value;

/**
* Tag type determines how the value is interpreted and rendered. The value should be an element
* of {@code MapTagType}
*/
String type;

/**
* The ordering to display this map tag in relative to other map tags. Lower values should be
* displayed first. displayOrder is greater than zero.
*/
int displayOrder;

// public MapTagType getType() {
// return MapTagType.valueOf(type);
// }

public String getValue() {
return Optional.ofNullable(value).orElse("");
}
}
Loading

0 comments on commit bc7c66a

Please sign in to comment.