Skip to content

Commit

Permalink
Merge branch 'triplea-game:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
WCSumpton authored Jun 19, 2024
2 parents dda4bdc + 70c3294 commit 5f1a345
Show file tree
Hide file tree
Showing 540 changed files with 53 additions and 23,454 deletions.
12 changes: 0 additions & 12 deletions .docker-compose/connect-to-db.sh

This file was deleted.

5 changes: 0 additions & 5 deletions .docker-compose/database/01-init.sql

This file was deleted.

57 changes: 0 additions & 57 deletions .docker-compose/nginx/default.conf

This file was deleted.

38 changes: 0 additions & 38 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ plugins {
id "com.github.ben-manes.versions" version "0.51.0"
id "io.franzbecker.gradle-lombok" version "5.0.0" apply false
id "com.diffplug.spotless" version "6.25.0" apply false
id "com.avast.gradle.docker-compose" version "0.17.7"
}

apply plugin: "eclipse"
apply plugin: "docker-compose"


ext {
schemasDir = file("config/triplea/schemas")
Expand Down Expand Up @@ -199,39 +196,4 @@ subprojects {
removeUnusedImports()
}
}

// "testWithDatabase" runs only the tests that need a database
tasks.register("testWithDatabase", Test) {
description = "Runs integration tests."
group = "verification"

dependsOn(":composeUp")
dependsOn(":spitfire-server:database:flywayMigrateLobbyDb")
dependsOn(":spitfire-server:database:flywayMigrateErrorReportDb")

useJUnitPlatform() {
includeTags "RequiresDatabase"
}
}

// - "testAll" runs all tests
task testAll {
dependsOn testWithDatabase
dependsOn test
}

// - "check" should run ALL validations, tests, spotlessChecks, everything..
check.dependsOn testAll

// composeUp is the same as running => docker compose -f .docker/full-stack.yml --ansi never -p triplea up
// composeBuild is the same as running => docker compose -f .docker/full-stack.yml --ansi never -p triplea build
dockerCompose {
projectName = "triplea"
useComposeFiles = ["docker-compose.yml" ]
}

// compose builds need WAR files for packaging, so we must run the corresponding package (shadowJar) tasks
composeBuild.dependsOn ":servers:game-support:server:shadowJar"
composeBuild.dependsOn ":servers:maps:server:shadowJar"
composeBuild.dependsOn ":spitfire-server:dropwizard-server:shadowJar"
}
69 changes: 0 additions & 69 deletions docker-compose.yml

This file was deleted.

2 changes: 2 additions & 0 deletions format
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

set -eu

./gradlew spotlessApply

find . -name "*.md" -type f | while read -r file; do
Expand Down
2 changes: 1 addition & 1 deletion game-app/game-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ dependencies {
implementation project(":game-app:map-data")
implementation project(":game-app:game-relay-server")
implementation project(":http-clients:lobby-client")
implementation project(":http-clients:maps-server")
implementation project(":lib:http-client-lib")
implementation project(":lib:java-extras")
implementation project(":lib:swing-lib")
implementation project(":lib:websocket-client")
implementation project(":lib:xml-reader")
implementation project(":servers:maps:client")
testImplementation "org.awaitility:awaitility:$awaitilityVersion"
testImplementation "org.sonatype.goodies:goodies-prefs:$sonatypeGoodiesPrefsVersion"
testImplementation project(":lib:swing-lib-test-support")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@
import javax.swing.ImageIcon;
import lombok.Builder;
import lombok.Getter;
import lombok.Synchronized;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;

/** A factory with an image cache for creating unit images. */
/** A factory with a thread-safe image cache for creating unit images. */
@Slf4j
public class UnitImageFactory {
public static final int DEFAULT_UNIT_ICON_SIZE = 48;
Expand Down Expand Up @@ -83,13 +84,15 @@ public UnitImageFactory(
this.mapData = mapData;
}

@Synchronized
public void clearCache() {
images.clear();
icons.clear();
deleteTempFiles();
colorizedTempFiles.clear();
}

@Synchronized
public void deleteTempFiles() {
tempFiles.forEach(File::delete);
tempFiles.clear();
Expand Down Expand Up @@ -222,6 +225,7 @@ public int getUnitCounterOffsetHeight() {
return (int) (scaleFactor * unitCounterOffsetHeight);
}

@Synchronized
public boolean hasImage(final ImageKey imageKey) {
return images.containsKey(imageKey) || getBaseImageUrl(imageKey).isPresent();
}
Expand All @@ -230,32 +234,40 @@ public boolean hasImage(final ImageKey imageKey) {
* Return the appropriate scaled unit image. If an image cannot be found, a placeholder 'no-image'
* image is returned.
*/
@Synchronized
public Image getImage(final ImageKey imageKey) {
return Optional.ofNullable(images.get(imageKey))
.or(
() ->
getTransformedImage(imageKey)
.map(
baseImage -> {
// We want to scale units according to the given scale factor.
// We use smooth scaling since the images are cached to allow to take our
// time in doing the scaling.
// Image observer is null, since the image should have been guaranteed to
// be loaded.
final int baseWidth = baseImage.getWidth(null);
final int baseHeight = baseImage.getHeight(null);
final int width = Math.max(1, (int) (baseWidth * scaleFactor));
final int height = Math.max(1, (int) (baseHeight * scaleFactor));
final Image scaledImage =
baseImage.getScaledInstance(width, height, Image.SCALE_SMOOTH);
// Ensure the scaling is completed.
Util.ensureImageLoaded(scaledImage);
images.put(imageKey, scaledImage);
return scaledImage;
}))
.or(() -> getTransformedScaledImage(imageKey))
.orElseGet(() -> createNoImageImage(imageKey));
}

private Optional<Image> getTransformedScaledImage(final ImageKey imageKey) {
return getTransformedImage(imageKey)
.map(
baseImage -> {
// We want to scale units according to the given scale factor.
// We use smooth scaling since the images are cached to allow to take our
// time in doing the scaling.
// Image observer is null, since the image should have been guaranteed to
// be loaded.
final int baseWidth = baseImage.getWidth(null);
final int baseHeight = baseImage.getHeight(null);
final int width = Math.max(1, (int) (baseWidth * scaleFactor));
final int height = Math.max(1, (int) (baseHeight * scaleFactor));
final Image scaledImage =
baseImage.getScaledInstance(width, height, Image.SCALE_SMOOTH);
// Ensure the scaling is completed.
Util.ensureImageLoaded(scaledImage);
images.put(imageKey, scaledImage);
return scaledImage;
});
}

private Optional<Image> getTransformedImage(final ImageKey imageKey) {
return getBaseImageUrl(imageKey)
.map(imageLocation -> loadImageAndTransform(imageLocation, imageKey));
}

private Image createNoImageImage(ImageKey imageKey) {
BufferedImage image = resourceLoader.getImageOrThrow(FILE_NAME_BASE + "missing_unit_image.png");
Color playerColor = mapData.getPlayerColor(imageKey.getPlayer().getName());
Expand All @@ -270,7 +282,7 @@ private Image createNoImageImage(ImageKey imageKey) {
return image;
}

public Optional<URL> getBaseImageUrl(final ImageKey imageKey) {
private Optional<URL> getBaseImageUrl(final ImageKey imageKey) {
final String baseImageName = imageKey.getBaseImageName();
final GamePlayer gamePlayer = imageKey.getPlayer();
// URL uses '/' not '\'
Expand All @@ -280,6 +292,7 @@ public Optional<URL> getBaseImageUrl(final ImageKey imageKey) {
return Optional.ofNullable(url);
}

@Synchronized
public Optional<URL> getPossiblyTransformedImageUrl(final ImageKey imageKey) {
final Optional<URL> url = getBaseImageUrl(imageKey);
if (url.isEmpty() || !shouldTransformImage(imageKey)) {
Expand Down Expand Up @@ -309,11 +322,6 @@ public Optional<URL> getPossiblyTransformedImageUrl(final ImageKey imageKey) {
}));
}

private Optional<Image> getTransformedImage(final ImageKey imageKey) {
return getBaseImageUrl(imageKey)
.map(imageLocation -> loadImageAndTransform(imageLocation, imageKey));
}

private Image loadImageAndTransform(URL imageLocation, ImageKey imageKey) {
Image image = Toolkit.getDefaultToolkit().getImage(imageLocation);
Util.ensureImageLoaded(image);
Expand Down Expand Up @@ -376,6 +384,7 @@ public Image getHighlightImage(final ImageKey imageKey) {
}

/** Return an _unscaled_ icon image for a unit. */
@Synchronized
public ImageIcon getIcon(final ImageKey imageKey) {
final String fullName = imageKey.getFullName();
return icons.computeIfAbsent(
Expand Down
2 changes: 1 addition & 1 deletion game-app/game-headed/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ dependencies {
implementation project(":game-app:game-core")
implementation project(":game-app:map-data")
implementation project(":http-clients:lobby-client")
implementation project(":http-clients:maps-server")
implementation project(":lib:feign-common")
implementation project(":lib:http-client-lib")
implementation project(":lib:java-extras")
implementation project(":lib:swing-lib")
implementation project(":lib:websocket-client")
implementation project(":servers:maps:client")
testImplementation "org.sonatype.goodies:goodies-prefs:$sonatypeGoodiesPrefsVersion"
testImplementation project(":lib:test-common")
}
Expand Down
File renamed without changes.
9 changes: 0 additions & 9 deletions http-clients/github-client/build.gradle

This file was deleted.

Loading

0 comments on commit 5f1a345

Please sign in to comment.