Tiled Parser and Scene & Palette Management in Studio
This commit is contained in:
@@ -4,6 +4,7 @@ import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.input.MouseButton;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ListCell;
|
||||
@@ -35,6 +36,8 @@ public abstract class StudioDualListView<T> extends HBox {
|
||||
private Consumer<List<T>> onMoveToLeft = ignored -> { };
|
||||
private Consumer<T> onLeftSelectionChanged = ignored -> { };
|
||||
private Consumer<T> onRightSelectionChanged = ignored -> { };
|
||||
private Consumer<T> onLeftItemActivated = ignored -> { };
|
||||
private Consumer<T> onRightItemActivated = ignored -> { };
|
||||
private IntConsumer onMoveUp = ignored -> { };
|
||||
private IntConsumer onMoveDown = ignored -> { };
|
||||
private boolean interactionEnabled = true;
|
||||
@@ -145,6 +148,14 @@ public abstract class StudioDualListView<T> extends HBox {
|
||||
this.onRightSelectionChanged = Objects.requireNonNull(onRightSelectionChanged, "onRightSelectionChanged");
|
||||
}
|
||||
|
||||
public void setOnLeftItemActivated(Consumer<T> onLeftItemActivated) {
|
||||
this.onLeftItemActivated = Objects.requireNonNull(onLeftItemActivated, "onLeftItemActivated");
|
||||
}
|
||||
|
||||
public void setOnRightItemActivated(Consumer<T> onRightItemActivated) {
|
||||
this.onRightItemActivated = Objects.requireNonNull(onRightItemActivated, "onRightItemActivated");
|
||||
}
|
||||
|
||||
public void setOnMoveUp(IntConsumer onMoveUp) {
|
||||
this.onMoveUp = Objects.requireNonNull(onMoveUp, "onMoveUp");
|
||||
}
|
||||
@@ -188,6 +199,19 @@ public abstract class StudioDualListView<T> extends HBox {
|
||||
|
||||
private ListCell<T> createCell(boolean indexed) {
|
||||
return new ListCell<>() {
|
||||
{
|
||||
setOnMouseClicked(event -> {
|
||||
if (event.getButton() != MouseButton.PRIMARY || event.getClickCount() != 2 || getItem() == null) {
|
||||
return;
|
||||
}
|
||||
if (indexed) {
|
||||
onRightItemActivated.accept(getItem());
|
||||
} else {
|
||||
onLeftItemActivated.accept(getItem());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateItem(T item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
|
||||
@@ -145,6 +145,9 @@ public enum I18n {
|
||||
ASSETS_SECTION_SUMMARY("assets.section.summary"),
|
||||
ASSETS_SECTION_RUNTIME_CONTRACT("assets.section.runtimeContract"),
|
||||
ASSETS_SECTION_BANK_COMPOSITION("assets.section.bankComposition"),
|
||||
ASSETS_SECTION_SCENE_LAYERS("assets.section.sceneLayers"),
|
||||
ASSETS_SECTION_COLOR_SCHEMA_GROUPS("assets.section.colorSchemaGroups"),
|
||||
ASSETS_SECTION_LAYER_CONFIGURATION("assets.section.layerConfiguration"),
|
||||
ASSETS_SECTION_PALETTE_OVERHAULING("assets.section.paletteOverhauling"),
|
||||
ASSETS_SUBSECTION_CODEC_CONFIGURATION("assets.subsection.codecConfiguration"),
|
||||
ASSETS_SUBSECTION_METADATA("assets.subsection.metadata"),
|
||||
@@ -158,10 +161,13 @@ public enum I18n {
|
||||
ASSETS_ACTION_GENERATE_TMX("assets.action.generateTmx"),
|
||||
ASSETS_ACTION_VALIDATE_SCENE_BANK("assets.action.validateSceneBank"),
|
||||
ASSETS_ACTION_ACCEPT_SCENE_BANK("assets.action.acceptSceneBank"),
|
||||
ASSETS_ACTION_VALIDATE_LAYER("assets.action.validateLayer"),
|
||||
ASSETS_ACTION_ACCEPT_LAYER("assets.action.acceptLayer"),
|
||||
ASSETS_ACTION_DELETE("assets.action.delete"),
|
||||
ASSETS_ACTION_INCLUDE_IN_BUILD("assets.action.includeInBuild"),
|
||||
ASSETS_ACTION_EXCLUDE_FROM_BUILD("assets.action.excludeFromBuild"),
|
||||
ASSETS_ACTION_RELOCATE("assets.action.relocate"),
|
||||
ASSETS_ACTION_REMOVE("assets.action.remove"),
|
||||
ASSETS_DELETE_DIALOG_TITLE("assets.deleteDialog.title"),
|
||||
ASSETS_DELETE_DIALOG_DESCRIPTION("assets.deleteDialog.description"),
|
||||
ASSETS_DELETE_DIALOG_PROMPT("assets.deleteDialog.prompt"),
|
||||
@@ -197,8 +203,16 @@ public enum I18n {
|
||||
ASSETS_LABEL_STUDIO_ROLE("assets.label.studioRole"),
|
||||
ASSETS_LABEL_SCENE_STATUS("assets.label.sceneStatus"),
|
||||
ASSETS_LABEL_SCENE_LAYERS("assets.label.sceneLayers"),
|
||||
ASSETS_LABEL_SCENE_DIMENSIONS("assets.label.sceneDimensions"),
|
||||
ASSETS_LABEL_LAYER("assets.label.layer"),
|
||||
ASSETS_LABEL_LAYER_OVERVIEW("assets.label.layerOverview"),
|
||||
ASSETS_LABEL_TILEMAPS("assets.label.tilemaps"),
|
||||
ASSETS_LABEL_TILEMAP("assets.label.tilemap"),
|
||||
ASSETS_LABEL_TILESET("assets.label.tileset"),
|
||||
ASSETS_LABEL_SUPPORT_FILE("assets.label.supportFile"),
|
||||
ASSETS_LABEL_USE_LAYER("assets.label.useLayer"),
|
||||
ASSETS_VALUE_NOT_CONFIGURED("assets.value.notConfigured"),
|
||||
ASSETS_VALUE_LAYER_OVERVIEW_PENDING("assets.value.layerOverviewPending"),
|
||||
ASSETS_TYPE_GLYPH_BANK("assets.type.glyphBank"),
|
||||
ASSETS_TYPE_SCENE_BANK("assets.type.sceneBank"),
|
||||
ASSETS_TYPE_PALETTE_BANK("assets.type.paletteBank"),
|
||||
@@ -259,6 +273,22 @@ public enum I18n {
|
||||
ASSETS_PALETTE_OVERHAULING_TILE_SELECTOR("assets.paletteOverhauling.tileSelector"),
|
||||
ASSETS_PALETTE_OVERHAULING_APPLIED_PALETTE("assets.paletteOverhauling.appliedPalette"),
|
||||
ASSETS_PALETTE_OVERHAULING_PREVIEW_EMPTY("assets.paletteOverhauling.previewEmpty"),
|
||||
ASSETS_PALETTE_WIZARD_CREATE_TITLE("assets.paletteWizard.createTitle"),
|
||||
ASSETS_PALETTE_WIZARD_UPDATE_TITLE("assets.paletteWizard.updateTitle"),
|
||||
ASSETS_PALETTE_WIZARD_NAME("assets.paletteWizard.name"),
|
||||
ASSETS_PALETTE_WIZARD_SCHEMA("assets.paletteWizard.schema"),
|
||||
ASSETS_PALETTE_WIZARD_ORIGINAL("assets.paletteWizard.original"),
|
||||
ASSETS_PALETTE_WIZARD_EDITABLE("assets.paletteWizard.editable"),
|
||||
ASSETS_PALETTE_WIZARD_APPLY_COLOR("assets.paletteWizard.applyColor"),
|
||||
ASSETS_PALETTE_WIZARD_DUPLICATE("assets.paletteWizard.duplicate"),
|
||||
ASSETS_PALETTE_WIZARD_READY("assets.paletteWizard.ready"),
|
||||
ASSETS_COLOR_SCHEMA_EMPTY("assets.colorSchema.empty"),
|
||||
ASSETS_COLOR_SCHEMA_SUMMARY("assets.colorSchema.summary"),
|
||||
ASSETS_COLOR_SCHEMA_REMOVE_BLOCKED("assets.colorSchema.removeBlocked"),
|
||||
ASSETS_COLOR_SCHEMA_DIALOG_AVAILABLE_TILES("assets.colorSchema.dialog.availableTiles"),
|
||||
ASSETS_COLOR_SCHEMA_DIALOG_ASSIGNED_TILES("assets.colorSchema.dialog.assignedTiles"),
|
||||
ASSETS_COLOR_SCHEMA_DIALOG_COLOR_COUNT("assets.colorSchema.dialog.colorCount"),
|
||||
ASSETS_COLOR_SCHEMA_DIALOG_TOO_MANY_COLORS("assets.colorSchema.dialog.tooManyColors"),
|
||||
ASSETS_DETAILS_CODEC_CONFIGURATION_EMPTY("assets.details.codecConfiguration.empty"),
|
||||
ASSETS_DETAILS_METADATA_EMPTY("assets.details.metadata.empty"),
|
||||
ASSETS_ADD_WIZARD_TITLE("assets.addWizard.title"),
|
||||
@@ -290,6 +320,7 @@ public enum I18n {
|
||||
ASSETS_ADD_WIZARD_ERROR_ROOT_OUTSIDE_ASSETS("assets.addWizard.error.rootOutsideAssets"),
|
||||
ASSETS_ADD_WIZARD_ERROR_ROOT_ALREADY_ASSET("assets.addWizard.error.rootAlreadyAsset"),
|
||||
ASSETS_ADD_WIZARD_ERROR_TYPE("assets.addWizard.error.type"),
|
||||
ASSETS_ADD_WIZARD_ERROR_SPECIALIZATION("assets.addWizard.error.specialization"),
|
||||
ASSETS_ADD_WIZARD_ERROR_FORMAT("assets.addWizard.error.format"),
|
||||
ASSETS_ADD_WIZARD_ERROR_CODEC("assets.addWizard.error.codec"),
|
||||
ASSETS_ADD_WIZARD_ERROR_UNSUPPORTED_COMBINATION("assets.addWizard.error.unsupportedCombination"),
|
||||
|
||||
+67
-39
@@ -12,6 +12,7 @@ import p.packer.dtos.PackerAssetActionAvailabilityDTO;
|
||||
import p.packer.dtos.PackerAssetDetailsDTO;
|
||||
import p.packer.dtos.PackerDiagnosticDTO;
|
||||
import p.packer.messages.*;
|
||||
import p.packer.messages.assets.AssetFamilyCatalog;
|
||||
import p.studio.Container;
|
||||
import p.studio.controls.forms.StudioFormEditScopeChangedEvent;
|
||||
import p.studio.controls.forms.StudioSection;
|
||||
@@ -22,6 +23,8 @@ import p.studio.workspaces.assets.dialogs.AssetDiagnosticsDialog;
|
||||
import p.studio.workspaces.assets.details.bank.AssetDetailsBankCompositionControl;
|
||||
import p.studio.workspaces.assets.details.contract.AssetDetailsContractControl;
|
||||
import p.studio.workspaces.assets.details.palette.AssetDetailsPaletteOverhaulingControl;
|
||||
import p.studio.workspaces.assets.details.schema.AssetDetailsColorSchemaGroupsControl;
|
||||
import p.studio.workspaces.assets.details.scene.AssetDetailsSceneLayersControl;
|
||||
import p.studio.workspaces.assets.details.summary.AssetDetailsSummaryControl;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioMetadataService;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioMetadataSnapshot;
|
||||
@@ -62,7 +65,9 @@ public final class AssetDetailsControl extends VBox implements StudioEventAware
|
||||
private final AssetDetailsSummaryControl summaryControl;
|
||||
private final AssetDetailsContractControl contractControl;
|
||||
private final AssetDetailsBankCompositionControl bankCompositionControl;
|
||||
private final AssetDetailsColorSchemaGroupsControl colorSchemaGroupsControl;
|
||||
private final AssetDetailsPaletteOverhaulingControl paletteOverhaulingControl;
|
||||
private final AssetDetailsSceneLayersControl sceneLayersControl;
|
||||
private final AssetStudioMetadataService studioMetadataService = new AssetStudioMetadataService();
|
||||
private final TiledAssetGenerationService tiledGenerationService = new TiledAssetGenerationService();
|
||||
private final SceneBankWorkflowService sceneBankWorkflowService = new SceneBankWorkflowService();
|
||||
@@ -85,7 +90,12 @@ public final class AssetDetailsControl extends VBox implements StudioEventAware
|
||||
this.summaryControl = new AssetDetailsSummaryControl(projectReference, workspaceBus);
|
||||
this.contractControl = new AssetDetailsContractControl(projectReference, workspaceBus);
|
||||
this.bankCompositionControl = new AssetDetailsBankCompositionControl(projectReference, workspaceBus);
|
||||
this.colorSchemaGroupsControl = new AssetDetailsColorSchemaGroupsControl(projectReference, workspaceBus);
|
||||
this.paletteOverhaulingControl = new AssetDetailsPaletteOverhaulingControl(projectReference, workspaceBus);
|
||||
this.sceneLayersControl = new AssetDetailsSceneLayersControl(projectReference, workspaceBus);
|
||||
this.sceneLayersControl.setGenerateLayerAction(this::generateTmx);
|
||||
this.sceneLayersControl.setValidateLayerAction(this::validateSceneBank);
|
||||
this.sceneLayersControl.setAcceptLayerAction(this::acceptSceneBank);
|
||||
this.actionsSection = createActionsSection();
|
||||
|
||||
getStyleClass().add("assets-workspace-pane");
|
||||
@@ -269,13 +279,43 @@ public final class AssetDetailsControl extends VBox implements StudioEventAware
|
||||
renderActions();
|
||||
if (!readyMounted) {
|
||||
readyMounted = true;
|
||||
detailsContent.getChildren().setAll(primarySectionsRow, contractControl, bankCompositionControl, paletteOverhaulingControl);
|
||||
detailsContent.getChildren().setAll(buildDetailsSections());
|
||||
}
|
||||
syncActionsSectionHeight(summaryControl.getHeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Node[] buildDetailsSections() {
|
||||
final java.util.List<Node> sections = new java.util.ArrayList<>();
|
||||
sections.add(primarySectionsRow);
|
||||
sections.add(contractControl);
|
||||
if (showsSceneLayers(viewState.selectedAssetDetails())) {
|
||||
sections.add(sceneLayersControl);
|
||||
} else if (!hidesBankComposition(viewState.selectedAssetDetails())) {
|
||||
sections.add(bankCompositionControl);
|
||||
}
|
||||
if (showsColorSchemaGroups(viewState.selectedAssetDetails())) {
|
||||
sections.add(colorSchemaGroupsControl);
|
||||
}
|
||||
sections.add(paletteOverhaulingControl);
|
||||
return sections.toArray(Node[]::new);
|
||||
}
|
||||
|
||||
private boolean hidesBankComposition(AssetWorkspaceAssetDetails details) {
|
||||
return details != null && details.summary().assetFamily() == AssetFamilyCatalog.SCENE_BANK;
|
||||
}
|
||||
|
||||
private boolean showsSceneLayers(AssetWorkspaceAssetDetails details) {
|
||||
return details != null
|
||||
&& details.summary().assetFamily() == AssetFamilyCatalog.SCENE_BANK
|
||||
&& details.sceneBankMetadata() != null;
|
||||
}
|
||||
|
||||
private boolean showsColorSchemaGroups(AssetWorkspaceAssetDetails details) {
|
||||
return details != null && details.summary().assetFamily() == AssetFamilyCatalog.GLYPH_BANK;
|
||||
}
|
||||
|
||||
private VBox createActionsSection() {
|
||||
actionsContent.getStyleClass().add("assets-details-actions-content");
|
||||
actionsScroll.setContent(actionsContent);
|
||||
@@ -316,9 +356,6 @@ public final class AssetDetailsControl extends VBox implements StudioEventAware
|
||||
|
||||
private java.util.List<Node> buildActionNodes() {
|
||||
final java.util.List<Node> nodes = new java.util.ArrayList<>();
|
||||
if (actionFeedbackMessage != null && !actionFeedbackMessage.isBlank()) {
|
||||
nodes.add(AssetDetailsUiSupport.createSectionMessage(actionFeedbackMessage));
|
||||
}
|
||||
if (viewState.selectedAssetDetails() == null) {
|
||||
nodes.add(AssetDetailsUiSupport.createSectionMessage(Container.i18n().text(I18n.ASSETS_ACTIONS_EMPTY)));
|
||||
return nodes;
|
||||
@@ -343,24 +380,6 @@ public final class AssetDetailsControl extends VBox implements StudioEventAware
|
||||
generateTsxButton.setOnAction(ignored -> generateTsx());
|
||||
nodes.add(generateTsxButton);
|
||||
}
|
||||
if (canGenerateTmx()) {
|
||||
final Button generateTmxButton = AssetDetailsUiSupport.createActionButton(Container.i18n().text(I18n.ASSETS_ACTION_GENERATE_TMX));
|
||||
generateTmxButton.setDisable(actionRunning);
|
||||
generateTmxButton.setOnAction(ignored -> generateTmx());
|
||||
nodes.add(generateTmxButton);
|
||||
}
|
||||
if (canValidateSceneBank()) {
|
||||
final Button validateSceneButton = AssetDetailsUiSupport.createActionButton(Container.i18n().text(I18n.ASSETS_ACTION_VALIDATE_SCENE_BANK));
|
||||
validateSceneButton.setDisable(actionRunning);
|
||||
validateSceneButton.setOnAction(ignored -> validateSceneBank());
|
||||
nodes.add(validateSceneButton);
|
||||
|
||||
final Button acceptSceneButton = AssetDetailsUiSupport.createActionButton(Container.i18n().text(I18n.ASSETS_ACTION_ACCEPT_SCENE_BANK));
|
||||
acceptSceneButton.setDisable(actionRunning || !viewState.selectedAssetDetails().sceneBankValidation().canAccept());
|
||||
acceptSceneButton.setOnAction(ignored -> acceptSceneBank());
|
||||
nodes.add(acceptSceneButton);
|
||||
}
|
||||
|
||||
final Button buildParticipationButton = AssetDetailsUiSupport.createActionButton(buildParticipationActionLabel());
|
||||
AssetDetailsUiSupport.applyActionTone(
|
||||
buildParticipationButton,
|
||||
@@ -449,7 +468,16 @@ public final class AssetDetailsControl extends VBox implements StudioEventAware
|
||||
|
||||
private boolean canToggleBuildParticipation() {
|
||||
return viewState.selectedAssetDetails() != null
|
||||
&& viewState.selectedAssetDetails().summary().state() == p.studio.workspaces.assets.messages.AssetWorkspaceAssetState.REGISTERED;
|
||||
&& viewState.selectedAssetDetails().summary().state() == p.studio.workspaces.assets.messages.AssetWorkspaceAssetState.REGISTERED
|
||||
&& (!isSceneBankAwaitingActiveLayerForBuild());
|
||||
}
|
||||
|
||||
private boolean isSceneBankAwaitingActiveLayerForBuild() {
|
||||
return viewState.selectedAssetDetails() != null
|
||||
&& viewState.selectedAssetDetails().summary().assetFamily() == AssetFamilyCatalog.SCENE_BANK
|
||||
&& currentBuildParticipation() != AssetWorkspaceBuildParticipation.INCLUDED
|
||||
&& (viewState.selectedAssetDetails().sceneBankMetadata() == null
|
||||
|| viewState.selectedAssetDetails().sceneBankMetadata().enabledLayerCount() == 0);
|
||||
}
|
||||
|
||||
private AssetWorkspaceBuildParticipation currentBuildParticipation() {
|
||||
@@ -492,13 +520,11 @@ public final class AssetDetailsControl extends VBox implements StudioEventAware
|
||||
}
|
||||
|
||||
private boolean canGenerateTmx() {
|
||||
return viewState.selectedAssetDetails() != null
|
||||
&& viewState.selectedAssetDetails().summary().assetFamily() == p.packer.messages.assets.AssetFamilyCatalog.SCENE_BANK;
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean canValidateSceneBank() {
|
||||
return viewState.selectedAssetDetails() != null
|
||||
&& viewState.selectedAssetDetails().summary().assetFamily() == p.packer.messages.assets.AssetFamilyCatalog.SCENE_BANK;
|
||||
return false;
|
||||
}
|
||||
|
||||
private void generateTsx() {
|
||||
@@ -511,11 +537,11 @@ public final class AssetDetailsControl extends VBox implements StudioEventAware
|
||||
final AssetWorkspaceAssetDetails details = viewState.selectedAssetDetails();
|
||||
Container.backgroundTasks().submit(() -> {
|
||||
final TiledAssetGenerationResult result = tiledGenerationService.generateTilesetTsx(details);
|
||||
Platform.runLater(() -> applyTiledGenerationResult(result));
|
||||
Platform.runLater(() -> applyTiledGenerationResult("glyph-bank-tileset", result));
|
||||
});
|
||||
}
|
||||
|
||||
private void generateTmx() {
|
||||
private void generateTmx(int layerIndex) {
|
||||
if (actionRunning || viewState.selectedAssetDetails() == null) {
|
||||
return;
|
||||
}
|
||||
@@ -524,15 +550,15 @@ public final class AssetDetailsControl extends VBox implements StudioEventAware
|
||||
renderActions();
|
||||
final AssetWorkspaceAssetDetails details = viewState.selectedAssetDetails();
|
||||
Container.backgroundTasks().submit(() -> {
|
||||
final TiledAssetGenerationResult result = tiledGenerationService.generateSceneBankTilemaps(projectReference, details);
|
||||
Platform.runLater(() -> applyTiledGenerationResult(result));
|
||||
final TiledAssetGenerationResult result = tiledGenerationService.generateSceneBankTilemap(projectReference, details, layerIndex);
|
||||
Platform.runLater(() -> applyTiledGenerationResult("scene-bank-layer-" + layerIndex, result));
|
||||
});
|
||||
}
|
||||
|
||||
private void applyTiledGenerationResult(TiledAssetGenerationResult result) {
|
||||
private void applyTiledGenerationResult(String source, TiledAssetGenerationResult result) {
|
||||
actionRunning = false;
|
||||
actionFeedbackMessage = result.message();
|
||||
workspaceBus.publish(new StudioAssetLogEvent("scene-bank", result.message()));
|
||||
workspaceBus.publish(new StudioAssetLogEvent(source, result.message()));
|
||||
renderActions();
|
||||
if (result.success() && viewState.selectedAssetReference() != null) {
|
||||
workspaceBus.publish(new StudioAssetsRefreshRequestedEvent(viewState.selectedAssetReference()));
|
||||
@@ -540,7 +566,7 @@ public final class AssetDetailsControl extends VBox implements StudioEventAware
|
||||
}
|
||||
}
|
||||
|
||||
private void validateSceneBank() {
|
||||
private void validateSceneBank(int layerIndex) {
|
||||
if (actionRunning || viewState.selectedAssetDetails() == null) {
|
||||
return;
|
||||
}
|
||||
@@ -549,12 +575,12 @@ public final class AssetDetailsControl extends VBox implements StudioEventAware
|
||||
renderActions();
|
||||
final AssetWorkspaceAssetDetails details = viewState.selectedAssetDetails();
|
||||
Container.backgroundTasks().submit(() -> {
|
||||
final SceneBankWorkflowResult result = sceneBankWorkflowService.validate(projectReference, details);
|
||||
Platform.runLater(() -> applySceneBankWorkflowResult("scene-bank-validate", result));
|
||||
final SceneBankWorkflowResult result = sceneBankWorkflowService.validateLayer(projectReference, details, layerIndex);
|
||||
Platform.runLater(() -> applySceneBankWorkflowResult("scene-bank-validate-layer-" + layerIndex, result));
|
||||
});
|
||||
}
|
||||
|
||||
private void acceptSceneBank() {
|
||||
private void acceptSceneBank(int layerIndex) {
|
||||
if (actionRunning || viewState.selectedAssetDetails() == null) {
|
||||
return;
|
||||
}
|
||||
@@ -563,8 +589,8 @@ public final class AssetDetailsControl extends VBox implements StudioEventAware
|
||||
renderActions();
|
||||
final AssetWorkspaceAssetDetails details = viewState.selectedAssetDetails();
|
||||
Container.backgroundTasks().submit(() -> {
|
||||
final SceneBankWorkflowResult result = sceneBankWorkflowService.accept(projectReference, details);
|
||||
Platform.runLater(() -> applySceneBankWorkflowResult("scene-bank-accept", result));
|
||||
final SceneBankWorkflowResult result = sceneBankWorkflowService.acceptLayer(projectReference, details, layerIndex);
|
||||
Platform.runLater(() -> applySceneBankWorkflowResult("scene-bank-accept-layer-" + layerIndex, result));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -699,6 +725,7 @@ public final class AssetDetailsControl extends VBox implements StudioEventAware
|
||||
details.outputPipeline(),
|
||||
bankComposition,
|
||||
details.pipelinePalettes(),
|
||||
studioMetadata.glyphMaterialMetadata(),
|
||||
studioMetadata.sceneBankMetadata(),
|
||||
AssetWorkspaceSceneBankValidation.NOT_APPLICABLE,
|
||||
List.of());
|
||||
@@ -725,6 +752,7 @@ public final class AssetDetailsControl extends VBox implements StudioEventAware
|
||||
details.outputPipeline(),
|
||||
bankComposition,
|
||||
details.pipelinePalettes(),
|
||||
studioMetadata.glyphMaterialMetadata(),
|
||||
studioMetadata.sceneBankMetadata(),
|
||||
sceneBankWorkflow.validation(),
|
||||
mergedDiagnostics);
|
||||
|
||||
+13
-1
@@ -31,6 +31,10 @@ public final class AssetDetailsUiSupport {
|
||||
return StudioSection.createSection(title, content);
|
||||
}
|
||||
|
||||
public static VBox createSectionWithoutHeader(Node content) {
|
||||
return StudioSection.createSectionWithoutHeader(content);
|
||||
}
|
||||
|
||||
public static VBox createSection(String title, Node headerActions, Node content) {
|
||||
return StudioFormSection.createEditableSection(title, headerActions, content, StudioFormMode.READ_ONLY);
|
||||
}
|
||||
@@ -76,6 +80,14 @@ public final class AssetDetailsUiSupport {
|
||||
return chip;
|
||||
}
|
||||
|
||||
public static Label createChip(String toneClass, String text, String... extraClasses) {
|
||||
final Label chip = createChip(toneClass, text);
|
||||
if (extraClasses != null && extraClasses.length > 0) {
|
||||
chip.getStyleClass().addAll(extraClasses);
|
||||
}
|
||||
return chip;
|
||||
}
|
||||
|
||||
public static Button createActionButton(String text) {
|
||||
final Button button = new Button(text);
|
||||
button.getStyleClass().addAll("studio-button", "studio-button-primary", "assets-details-action-button");
|
||||
@@ -125,7 +137,7 @@ public final class AssetDetailsUiSupport {
|
||||
public static String typeChipTone(AssetFamilyCatalog assetFamily) {
|
||||
return switch (assetFamily) {
|
||||
case GLYPH_BANK -> "assets-details-chip-image";
|
||||
case SCENE_BANK -> "assets-details-chip-generic";
|
||||
case SCENE_BANK -> "assets-details-chip-scene";
|
||||
case SOUND_BANK -> "assets-details-chip-audio";
|
||||
case UNKNOWN -> "assets-details-chip-generic";
|
||||
};
|
||||
|
||||
+51
-5
@@ -5,7 +5,10 @@ import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.packer.dtos.PackerBankCompositionDetailsDTO;
|
||||
import p.packer.dtos.PackerBankCompositionFileDTO;
|
||||
import p.packer.messages.ApplyBankCompositionRequest;
|
||||
import p.packer.messages.GetAssetDetailsRequest;
|
||||
import p.studio.Container;
|
||||
import p.studio.controls.banks.StudioAssetCapacityMeter;
|
||||
import p.studio.controls.forms.StudioFormEditScopeChangedEvent;
|
||||
@@ -15,12 +18,14 @@ import p.studio.lsp.events.StudioWorkspaceEventBus;
|
||||
import p.studio.projects.ProjectReference;
|
||||
import p.studio.utilities.i18n.I18n;
|
||||
import p.studio.workspaces.assets.messages.AssetWorkspaceDetailsViewState;
|
||||
import p.studio.workspaces.assets.messages.AssetWorkspaceBankCompositionDetails;
|
||||
import p.studio.workspaces.assets.messages.AssetWorkspaceBankCompositionFile;
|
||||
import p.studio.workspaces.assets.messages.events.StudioAssetBankCompositionAppliedEvent;
|
||||
import p.studio.workspaces.assets.messages.events.StudioAssetBankCompositionApplyFailedEvent;
|
||||
import p.studio.workspaces.assets.messages.events.StudioAssetBankCompositionApplyRequestedEvent;
|
||||
import p.studio.workspaces.assets.messages.events.StudioAssetBankCompositionCapacityChangedEvent;
|
||||
import p.studio.workspaces.assets.messages.events.StudioAssetBankCompositionDraftChangedEvent;
|
||||
import p.studio.workspaces.assets.messages.events.StudioAssetsRefreshRequestedEvent;
|
||||
import p.studio.workspaces.assets.messages.events.StudioBankCompositionChangedEvent;
|
||||
import p.studio.workspaces.assets.messages.events.StudioAssetsDetailsViewStateChangedEvent;
|
||||
import p.studio.workspaces.framework.StudioSubscriptionBag;
|
||||
|
||||
@@ -76,6 +81,19 @@ public final class AssetDetailsBankCompositionControl extends StudioFormSection
|
||||
}));
|
||||
subscriptions.add(workspaceBus.subscribe(StudioFormEditScopeChangedEvent.class,
|
||||
event -> handleEditScopeChanged(event, currentScopeKey())));
|
||||
subscriptions.add(workspaceBus.subscribe(StudioBankCompositionChangedEvent.class, event -> {
|
||||
if (viewState == null || !Objects.equals(viewState.selectedAssetReference(), event.assetReference())) {
|
||||
return;
|
||||
}
|
||||
viewState = new AssetWorkspaceDetailsViewState(
|
||||
viewState.detailsStatus(),
|
||||
viewState.selectedAssetReference(),
|
||||
viewState.selectedAssetDetails().withBankComposition(event.bankComposition()),
|
||||
viewState.detailsErrorMessage());
|
||||
coordinator.replaceDetails(viewState.selectedAssetDetails());
|
||||
renderSection();
|
||||
publishStateNotifications();
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -181,12 +199,9 @@ public final class AssetDetailsBankCompositionControl extends StudioFormSection
|
||||
final var response = Container.packer().workspaceService().applyBankComposition(request);
|
||||
Platform.runLater(() -> {
|
||||
if (response.success()) {
|
||||
coordinator.apply();
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
renderSection();
|
||||
publishStateNotifications();
|
||||
workspaceBus.publish(new StudioAssetBankCompositionAppliedEvent(assetReference));
|
||||
workspaceBus.publish(new StudioAssetsRefreshRequestedEvent(assetReference));
|
||||
Container.backgroundTasks().submit(() -> publishAppliedBankComposition(assetReference));
|
||||
} else {
|
||||
workspaceBus.publish(new StudioAssetBankCompositionApplyFailedEvent(
|
||||
assetReference,
|
||||
@@ -201,6 +216,37 @@ public final class AssetDetailsBankCompositionControl extends StudioFormSection
|
||||
});
|
||||
}
|
||||
|
||||
private void publishAppliedBankComposition(p.packer.messages.AssetReference assetReference) {
|
||||
try {
|
||||
final var detailsResult = Container.packer().workspaceService().getAssetDetails(new GetAssetDetailsRequest(
|
||||
projectReference.toPackerProjectContext(),
|
||||
assetReference));
|
||||
final AssetWorkspaceBankCompositionDetails bankComposition = mapBankComposition(detailsResult.details().bankComposition());
|
||||
Platform.runLater(() -> workspaceBus.publish(new StudioBankCompositionChangedEvent(assetReference, bankComposition)));
|
||||
} catch (Exception exception) {
|
||||
Platform.runLater(() -> workspaceBus.publish(new StudioAssetBankCompositionApplyFailedEvent(
|
||||
assetReference,
|
||||
exception.getMessage())));
|
||||
}
|
||||
}
|
||||
|
||||
private AssetWorkspaceBankCompositionDetails mapBankComposition(PackerBankCompositionDetailsDTO details) {
|
||||
return new AssetWorkspaceBankCompositionDetails(
|
||||
details.availableFiles().stream().map(this::mapBankCompositionFile).toList(),
|
||||
details.selectedFiles().stream().map(this::mapBankCompositionFile).toList(),
|
||||
details.measuredBankSizeBytes());
|
||||
}
|
||||
|
||||
private AssetWorkspaceBankCompositionFile mapBankCompositionFile(PackerBankCompositionFileDTO file) {
|
||||
return new AssetWorkspaceBankCompositionFile(
|
||||
file.path(),
|
||||
file.displayName(),
|
||||
file.size(),
|
||||
file.lastModified(),
|
||||
file.fingerprint(),
|
||||
file.metadata());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reset() {
|
||||
coordinator.reset();
|
||||
|
||||
+94
-2
@@ -1,6 +1,7 @@
|
||||
package p.studio.workspaces.assets.details.palette;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.VBox;
|
||||
@@ -18,8 +19,12 @@ import p.studio.workspaces.assets.messages.AssetWorkspaceDetailsViewState;
|
||||
import p.studio.workspaces.assets.messages.events.StudioAssetLogEvent;
|
||||
import p.studio.workspaces.assets.messages.events.StudioAssetsRefreshRequestedEvent;
|
||||
import p.studio.workspaces.assets.messages.events.StudioAssetsDetailsViewStateChangedEvent;
|
||||
import p.studio.workspaces.assets.messages.events.StudioGlyphMaterialMetadataChangedEvent;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioGlyphMaterialMetadata;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioMetadataService;
|
||||
import p.studio.workspaces.framework.StudioSubscriptionBag;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
@@ -31,9 +36,12 @@ public final class AssetDetailsPaletteOverhaulingControl extends StudioFormSecti
|
||||
private final StudioWorkspaceEventBus workspaceBus;
|
||||
private final StudioSubscriptionBag subscriptions = new StudioSubscriptionBag();
|
||||
private final AssetDetailsPaletteOverhaulingCoordinator coordinator = new AssetDetailsPaletteOverhaulingCoordinator();
|
||||
private final AssetStudioMetadataService metadataService = new AssetStudioMetadataService();
|
||||
private final AssetDetailsPaletteOverhaulingDualListView dualListView = new AssetDetailsPaletteOverhaulingDualListView();
|
||||
private final AssetDetailsPaletteOverhaulingPreviewPane previewPane = new AssetDetailsPaletteOverhaulingPreviewPane();
|
||||
private final HBox body = new HBox(16, dualListView, previewPane);
|
||||
private final VBox paletteActions = new VBox(6);
|
||||
private final HBox listWithActions = new HBox(8, paletteActions, dualListView);
|
||||
private final HBox body = new HBox(16, listWithActions, previewPane);
|
||||
private final VBox content = new VBox(12, body);
|
||||
|
||||
private AssetWorkspaceDetailsViewState viewState;
|
||||
@@ -42,9 +50,12 @@ public final class AssetDetailsPaletteOverhaulingControl extends StudioFormSecti
|
||||
this.projectReference = Objects.requireNonNull(projectReference, "projectReference");
|
||||
this.workspaceBus = Objects.requireNonNull(workspaceBus, "workspaceBus");
|
||||
body.getStyleClass().add("assets-details-palette-overhauling-body");
|
||||
paletteActions.getStyleClass().add("assets-details-palette-overhauling-toolbar");
|
||||
listWithActions.getStyleClass().add("assets-details-list-with-actions");
|
||||
content.setFillWidth(true);
|
||||
HBox.setHgrow(dualListView, Priority.ALWAYS);
|
||||
HBox.setHgrow(listWithActions, Priority.ALWAYS);
|
||||
HBox.setHgrow(previewPane, Priority.ALWAYS);
|
||||
HBox.setHgrow(dualListView, Priority.ALWAYS);
|
||||
dualListView.setMaxWidth(Double.MAX_VALUE);
|
||||
previewPane.setMaxWidth(Double.MAX_VALUE);
|
||||
}
|
||||
@@ -61,6 +72,13 @@ public final class AssetDetailsPaletteOverhaulingControl extends StudioFormSecti
|
||||
}));
|
||||
subscriptions.add(workspaceBus.subscribe(StudioFormEditScopeChangedEvent.class,
|
||||
event -> handleEditScopeChanged(event, currentScopeKey())));
|
||||
subscriptions.add(workspaceBus.subscribe(StudioGlyphMaterialMetadataChangedEvent.class, event -> {
|
||||
if (viewState == null || !Objects.equals(viewState.selectedAssetReference(), event.assetReference())) {
|
||||
return;
|
||||
}
|
||||
coordinator.replaceMaterialMetadata(event.metadata());
|
||||
renderSection();
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,6 +128,8 @@ public final class AssetDetailsPaletteOverhaulingControl extends StudioFormSecti
|
||||
coordinator.viewModel().renderableFileCount());
|
||||
}
|
||||
});
|
||||
dualListView.setOnLeftItemActivated(item -> openPaletteWizard(item));
|
||||
dualListView.setOnRightItemActivated(item -> openPaletteWizard(item));
|
||||
if (viewModel.previewPaletteFile() != null) {
|
||||
if (viewModel.selectedFiles().contains(viewModel.previewPaletteFile())) {
|
||||
dualListView.selectRightItem(viewModel.previewPaletteFile());
|
||||
@@ -134,6 +154,17 @@ public final class AssetDetailsPaletteOverhaulingControl extends StudioFormSecti
|
||||
viewModel.previewPaletteFile(),
|
||||
viewModel.renderableFileCount());
|
||||
|
||||
final Button addButton = new Button("+");
|
||||
addButton.getStyleClass().addAll("studio-button", "studio-button-secondary", "assets-details-mini-action-button");
|
||||
addButton.setDisable(!viewModel.editing() || viewState == null || viewState.selectedAssetDetails() == null);
|
||||
addButton.setOnAction(ignored -> openPaletteWizard(null));
|
||||
|
||||
final Button removeButton = new Button("-");
|
||||
removeButton.getStyleClass().addAll("studio-button", "studio-button-secondary", "assets-details-mini-action-button");
|
||||
removeButton.setDisable(!viewModel.editing() || viewModel.previewPaletteFile() == null);
|
||||
removeButton.setOnAction(ignored -> removePalette(coordinator.viewModel().previewPaletteFile()));
|
||||
paletteActions.getChildren().setAll(addButton, removeButton);
|
||||
|
||||
renderFormSection(content);
|
||||
}
|
||||
|
||||
@@ -232,6 +263,67 @@ public final class AssetDetailsPaletteOverhaulingControl extends StudioFormSecti
|
||||
: "asset-details:" + viewState.selectedAssetReference();
|
||||
}
|
||||
|
||||
private void openPaletteWizard(p.studio.workspaces.assets.messages.AssetWorkspaceBankCompositionFile paletteFile) {
|
||||
if (getScene() == null || !coordinator.ready() || viewState == null || viewState.selectedAssetDetails() == null) {
|
||||
return;
|
||||
}
|
||||
if (AssetDetailsPaletteOverhaulingCoordinator.paletteIsOriginal(paletteFile)) {
|
||||
return;
|
||||
}
|
||||
final var result = AssetDetailsPaletteWizardDialog.showAndWait(
|
||||
getScene().getWindow(),
|
||||
coordinator,
|
||||
paletteFile);
|
||||
result.ifPresent(edit -> Container.backgroundTasks().submit(() -> {
|
||||
try {
|
||||
final AssetStudioGlyphMaterialMetadata metadata = coordinator.upsertPalette(
|
||||
edit.paletteId(),
|
||||
edit.displayName(),
|
||||
edit.schemaId(),
|
||||
edit.colors());
|
||||
metadataService.writeGlyphMaterialMetadata(viewState.selectedAssetDetails().summary().assetRoot(), metadata);
|
||||
Platform.runLater(() -> {
|
||||
workspaceBus.publish(new StudioAssetLogEvent("palette-overhauling", "Palette saved: " + edit.paletteId()));
|
||||
workspaceBus.publish(new StudioGlyphMaterialMetadataChangedEvent(viewState.selectedAssetReference(), metadata));
|
||||
});
|
||||
} catch (IOException exception) {
|
||||
Platform.runLater(() -> workspaceBus.publish(new StudioAssetLogEvent(
|
||||
"palette-overhauling",
|
||||
"Unable to save palette: " + Objects.requireNonNullElse(exception.getMessage(), "unknown error"))));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void removePalette(p.studio.workspaces.assets.messages.AssetWorkspaceBankCompositionFile paletteFile) {
|
||||
if (paletteFile == null || viewState == null || viewState.selectedAssetDetails() == null || viewState.selectedAssetReference() == null) {
|
||||
return;
|
||||
}
|
||||
if (AssetDetailsPaletteOverhaulingCoordinator.paletteIsOriginal(paletteFile)) {
|
||||
workspaceBus.publish(new StudioAssetLogEvent(
|
||||
"palette-overhauling",
|
||||
"Original schema palettes cannot be removed."));
|
||||
return;
|
||||
}
|
||||
final Object paletteIdValue = paletteFile.metadata().get("paletteId");
|
||||
if (!(paletteIdValue instanceof String paletteId) || paletteId.isBlank()) {
|
||||
return;
|
||||
}
|
||||
Container.backgroundTasks().submit(() -> {
|
||||
try {
|
||||
final AssetStudioGlyphMaterialMetadata metadata = coordinator.removePalette(paletteId);
|
||||
metadataService.writeGlyphMaterialMetadata(viewState.selectedAssetDetails().summary().assetRoot(), metadata);
|
||||
Platform.runLater(() -> {
|
||||
workspaceBus.publish(new StudioAssetLogEvent("palette-overhauling", "Palette removed: " + paletteId));
|
||||
workspaceBus.publish(new StudioGlyphMaterialMetadataChangedEvent(viewState.selectedAssetReference(), metadata));
|
||||
});
|
||||
} catch (Exception exception) {
|
||||
Platform.runLater(() -> workspaceBus.publish(new StudioAssetLogEvent(
|
||||
"palette-overhauling",
|
||||
"Unable to remove palette: " + Objects.requireNonNullElse(exception.getMessage(), "unknown error"))));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Map<String, Object> palettePayload(Map<String, Object> metadata) {
|
||||
final Object palette = metadata.get("palette");
|
||||
|
||||
+462
-62
@@ -5,24 +5,40 @@ import p.studio.controls.forms.StudioFormMode;
|
||||
import p.studio.controls.forms.StudioFormSession;
|
||||
import p.studio.workspaces.assets.messages.AssetWorkspaceAssetDetails;
|
||||
import p.studio.workspaces.assets.messages.AssetWorkspaceBankCompositionFile;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioGlyphMaterialArtifactBinding;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioGlyphMaterialMetadata;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioGlyphMaterialPalette;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioGlyphMaterialSchema;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioGlyphMaterialSchemaStatus;
|
||||
import p.studio.workspaces.assets.details.schema.AssetDetailsColorSchemaCoordinator;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
public final class AssetDetailsPaletteOverhaulingCoordinator {
|
||||
private StudioFormSession<AssetDetailsPaletteOverhaulingDraft> formSession;
|
||||
private AssetWorkspaceAssetDetails details;
|
||||
private AssetStudioGlyphMaterialMetadata localMaterialMetadata;
|
||||
|
||||
public void replaceDetails(AssetWorkspaceAssetDetails details) {
|
||||
this.details = details;
|
||||
if (details == null || details.summary().assetFamily() != AssetFamilyCatalog.GLYPH_BANK) {
|
||||
formSession = null;
|
||||
localMaterialMetadata = null;
|
||||
return;
|
||||
}
|
||||
localMaterialMetadata = details.glyphMaterialMetadata();
|
||||
rebuildSession();
|
||||
}
|
||||
|
||||
public void replaceMaterialMetadata(AssetStudioGlyphMaterialMetadata metadata) {
|
||||
if (details == null || details.summary().assetFamily() != AssetFamilyCatalog.GLYPH_BANK) {
|
||||
return;
|
||||
}
|
||||
localMaterialMetadata = Objects.requireNonNull(metadata, "metadata");
|
||||
rebuildSession();
|
||||
}
|
||||
|
||||
private void rebuildSession() {
|
||||
final List<AssetWorkspaceBankCompositionFile> allFiles = paletteFiles(details);
|
||||
final List<AssetWorkspaceBankCompositionFile> previewTileFiles = details.bankComposition().selectedFiles().stream()
|
||||
.filter(AssetDetailsPaletteOverhaulingCoordinator::supportsPalettePreview)
|
||||
@@ -37,12 +53,21 @@ public final class AssetDetailsPaletteOverhaulingCoordinator {
|
||||
available,
|
||||
initialSelected,
|
||||
previewTileFiles.isEmpty() ? null : previewTileFiles.getFirst().path(),
|
||||
null);
|
||||
initialSelected.isEmpty()
|
||||
? allFiles.isEmpty() ? null : allFiles.getFirst().path()
|
||||
: initialSelected.getFirst().path());
|
||||
if (formSession == null) {
|
||||
formSession = new StudioFormSession<>(source);
|
||||
return;
|
||||
}
|
||||
if (!Objects.equals(formSession.source(), source)) {
|
||||
if (formSession.mode() == StudioFormMode.EDITING) {
|
||||
final AssetDetailsPaletteOverhaulingDraft currentDraft = formSession.draft();
|
||||
formSession = new StudioFormSession<>(source);
|
||||
formSession.beginEdit();
|
||||
formSession.setDraft(rebindDraft(currentDraft, source));
|
||||
return;
|
||||
}
|
||||
formSession.replaceSource(source);
|
||||
}
|
||||
}
|
||||
@@ -51,6 +76,10 @@ public final class AssetDetailsPaletteOverhaulingCoordinator {
|
||||
return formSession != null;
|
||||
}
|
||||
|
||||
public AssetWorkspaceAssetDetails details() {
|
||||
return details;
|
||||
}
|
||||
|
||||
public void beginEdit() {
|
||||
if (ready()) {
|
||||
formSession.beginEdit();
|
||||
@@ -77,7 +106,10 @@ public final class AssetDetailsPaletteOverhaulingCoordinator {
|
||||
|
||||
public void moveToSelected(List<AssetWorkspaceBankCompositionFile> files) {
|
||||
if (ready() && formSession.mode() == StudioFormMode.EDITING) {
|
||||
formSession.updateDraft(current -> current.moveToSelected(files));
|
||||
final List<AssetWorkspaceBankCompositionFile> validFiles = files.stream()
|
||||
.filter(AssetDetailsPaletteOverhaulingCoordinator::paletteIsValid)
|
||||
.toList();
|
||||
formSession.updateDraft(current -> current.moveToSelected(validFiles));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,27 +137,118 @@ public final class AssetDetailsPaletteOverhaulingCoordinator {
|
||||
}
|
||||
|
||||
final AssetDetailsPaletteOverhaulingDraft draft = formSession.draft();
|
||||
final AssetWorkspaceBankCompositionFile previewPaletteFile = fileByPath(draft.allFiles(), draft.previewPalettePath());
|
||||
final List<AssetWorkspaceBankCompositionFile> schemaPreviewTileFiles = previewTileFilesForPalette(
|
||||
draft.previewTileFiles(),
|
||||
previewPaletteFile);
|
||||
final AssetWorkspaceBankCompositionFile previewTileFile = Optional
|
||||
.ofNullable(fileByPath(schemaPreviewTileFiles, draft.previewTilePath()))
|
||||
.orElse(schemaPreviewTileFiles.isEmpty() ? null : schemaPreviewTileFiles.getFirst());
|
||||
return new AssetDetailsPaletteOverhaulingViewModel(
|
||||
formSession.mode() == StudioFormMode.EDITING,
|
||||
formSession.isDirty(),
|
||||
draft.previewTileFiles(),
|
||||
schemaPreviewTileFiles,
|
||||
draft.allFiles(),
|
||||
draft.availableFiles(),
|
||||
draft.selectedFiles(),
|
||||
fileByPath(draft.previewTileFiles(), draft.previewTilePath()),
|
||||
fileByPath(draft.allFiles(), draft.previewPalettePath()),
|
||||
previewTileFile,
|
||||
previewPaletteFile,
|
||||
draft.allFiles().size());
|
||||
}
|
||||
|
||||
static boolean supportsPalettePreview(AssetWorkspaceBankCompositionFile file) {
|
||||
public List<AssetStudioGlyphMaterialSchema> readySchemas() {
|
||||
return materialMetadata().schemas().stream()
|
||||
.filter(schema -> schema.status() == AssetStudioGlyphMaterialSchemaStatus.OK)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public String nextPaletteId() {
|
||||
int next = 1;
|
||||
final Set<String> ids = materialMetadata().palettes().stream()
|
||||
.map(AssetStudioGlyphMaterialPalette::paletteId)
|
||||
.collect(java.util.stream.Collectors.toSet());
|
||||
while (ids.contains("palette-" + next)) {
|
||||
next += 1;
|
||||
}
|
||||
return "palette-" + next;
|
||||
}
|
||||
|
||||
public boolean duplicatePaletteExists(String paletteId, String schemaId, List<String> colors) {
|
||||
final List<String> normalized = colors.stream().map(AssetDetailsPaletteOverhaulingCoordinator::normalizeHtmlColor).toList();
|
||||
return allPaletteRecords().stream()
|
||||
.filter(record -> !Objects.equals(record.paletteId(), paletteId))
|
||||
.anyMatch(record -> record.schemaId().equals(schemaId) && record.colors().equals(normalized));
|
||||
}
|
||||
|
||||
public AssetStudioGlyphMaterialMetadata upsertPalette(String paletteId, String displayName, String schemaId, List<String> colors) {
|
||||
final AssetStudioGlyphMaterialMetadata current = materialMetadata();
|
||||
final List<String> normalized = colors.stream().map(AssetDetailsPaletteOverhaulingCoordinator::normalizeHtmlColor).toList();
|
||||
final int schemaVersion = current.findSchema(schemaId).map(AssetStudioGlyphMaterialSchema::version).orElse(1);
|
||||
final String resolvedDisplayName = displayName == null || displayName.trim().isBlank()
|
||||
? generatedDisplayName(normalized)
|
||||
: displayName.trim();
|
||||
final AssetStudioGlyphMaterialPalette next = new AssetStudioGlyphMaterialPalette(
|
||||
paletteId,
|
||||
resolvedDisplayName,
|
||||
schemaId,
|
||||
schemaVersion,
|
||||
normalized);
|
||||
final List<AssetStudioGlyphMaterialPalette> palettes = new ArrayList<>();
|
||||
boolean replaced = false;
|
||||
for (AssetStudioGlyphMaterialPalette palette : current.palettes()) {
|
||||
if (palette.paletteId().equals(paletteId)) {
|
||||
palettes.add(next);
|
||||
replaced = true;
|
||||
} else {
|
||||
palettes.add(palette);
|
||||
}
|
||||
}
|
||||
if (!replaced) {
|
||||
palettes.add(next);
|
||||
}
|
||||
palettes.sort(Comparator.comparing(AssetStudioGlyphMaterialPalette::paletteId, String.CASE_INSENSITIVE_ORDER));
|
||||
return new AssetStudioGlyphMaterialMetadata(current.schemas(), palettes, current.supportFile());
|
||||
}
|
||||
|
||||
public AssetStudioGlyphMaterialMetadata removePalette(String paletteId) {
|
||||
final AssetWorkspaceBankCompositionFile paletteFile = paletteFileById(paletteId);
|
||||
if (paletteFile != null && Boolean.TRUE.equals(paletteFile.metadata().get("derivedOriginal"))) {
|
||||
throw new IllegalStateException("Original schema palettes are derived and cannot be removed.");
|
||||
}
|
||||
final AssetStudioGlyphMaterialMetadata current = materialMetadata();
|
||||
final List<AssetStudioGlyphMaterialPalette> palettes = current.palettes().stream()
|
||||
.filter(palette -> !palette.paletteId().equals(paletteId))
|
||||
.toList();
|
||||
return new AssetStudioGlyphMaterialMetadata(current.schemas(), palettes, current.supportFile());
|
||||
}
|
||||
|
||||
public AssetWorkspaceBankCompositionFile paletteFileById(String paletteId) {
|
||||
if (paletteId == null || !ready()) {
|
||||
return null;
|
||||
}
|
||||
return paletteFiles(details).stream()
|
||||
.filter(file -> paletteId.equals(file.metadata().get("paletteId")))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public static boolean supportsPalettePreview(AssetWorkspaceBankCompositionFile file) {
|
||||
if (file == null) {
|
||||
return false;
|
||||
}
|
||||
return nestedMap(file.metadata(), "tile") != null && nestedMap(file.metadata(), "palette") != null;
|
||||
}
|
||||
|
||||
public static boolean paletteIsValid(AssetWorkspaceBankCompositionFile file) {
|
||||
return !Boolean.FALSE.equals(file.metadata().get("valid"));
|
||||
}
|
||||
|
||||
public static boolean paletteIsOriginal(AssetWorkspaceBankCompositionFile file) {
|
||||
return file != null && Boolean.TRUE.equals(file.metadata().get("derivedOriginal"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Map<String, Object> nestedMap(Map<String, Object> metadata, String key) {
|
||||
static Map<String, Object> nestedMap(Map<String, Object> metadata, String key) {
|
||||
final Object value = metadata.get(key);
|
||||
if (value instanceof Map<?, ?> nested) {
|
||||
return (Map<String, Object>) nested;
|
||||
@@ -133,37 +256,236 @@ public final class AssetDetailsPaletteOverhaulingCoordinator {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static List<AssetWorkspaceBankCompositionFile> paletteFiles(AssetWorkspaceAssetDetails details) {
|
||||
final Map<String, AssetWorkspaceBankCompositionFile> ordered = new LinkedHashMap<>();
|
||||
// `bankComposition` files are already projected by the packer read model from the current cache/walk state.
|
||||
for (AssetWorkspaceBankCompositionFile file : details.bankComposition().availableFiles()) {
|
||||
if (supportsPalettePreview(file)) {
|
||||
ordered.putIfAbsent(paletteHash(file), canonicalPaletteFile(file));
|
||||
}
|
||||
private AssetStudioGlyphMaterialMetadata materialMetadata() {
|
||||
if (details == null) {
|
||||
return new AssetStudioGlyphMaterialMetadata(List.of(), List.of(), null);
|
||||
}
|
||||
for (AssetWorkspaceBankCompositionFile file : details.bankComposition().selectedFiles()) {
|
||||
if (supportsPalettePreview(file)) {
|
||||
ordered.putIfAbsent(paletteHash(file), canonicalPaletteFile(file));
|
||||
}
|
||||
return localMaterialMetadata == null
|
||||
? new AssetStudioGlyphMaterialMetadata(List.of(), List.of(), null)
|
||||
: localMaterialMetadata;
|
||||
}
|
||||
|
||||
private List<AssetWorkspaceBankCompositionFile> paletteFiles(AssetWorkspaceAssetDetails details) {
|
||||
final Map<String, AssetWorkspaceBankCompositionFile> ordered = new LinkedHashMap<>();
|
||||
for (PaletteRecord record : allPaletteRecords()) {
|
||||
final AssetWorkspaceBankCompositionFile file = toPaletteFile(record);
|
||||
ordered.putIfAbsent(file.path(), file);
|
||||
}
|
||||
return List.copyOf(ordered.values());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static AssetWorkspaceBankCompositionFile canonicalPaletteFile(AssetWorkspaceBankCompositionFile file) {
|
||||
final String hash = paletteHash(file);
|
||||
final Map<String, Object> metadata = new LinkedHashMap<>(file.metadata());
|
||||
metadata.put("paletteHash", hash);
|
||||
private List<PaletteRecord> allPaletteRecords() {
|
||||
final AssetStudioGlyphMaterialMetadata metadata = materialMetadata();
|
||||
final List<PaletteRecord> records = new ArrayList<>();
|
||||
for (AssetStudioGlyphMaterialSchema schema : metadata.schemas()) {
|
||||
final AssetStudioGlyphMaterialSchemaStatus effectiveSchemaStatus = AssetDetailsColorSchemaCoordinator.effectiveStatus(
|
||||
schema,
|
||||
details.bankComposition().selectedFiles());
|
||||
final List<String> originalColors = schema.materialIndices().entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByKey())
|
||||
.map(Map.Entry::getValue)
|
||||
.toList();
|
||||
records.add(new PaletteRecord(
|
||||
"schema-" + schema.schemaId() + "-original",
|
||||
null,
|
||||
schema.schemaId(),
|
||||
schema.version(),
|
||||
originalColors,
|
||||
schema.materialIndices(),
|
||||
schemaArtifactIds(schema),
|
||||
true,
|
||||
effectiveSchemaStatus == AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
effectiveSchemaStatus == AssetStudioGlyphMaterialSchemaStatus.OK
|
||||
? null
|
||||
: "Schema is inconsistent."));
|
||||
}
|
||||
for (AssetStudioGlyphMaterialPalette palette : metadata.palettes()) {
|
||||
final AssetStudioGlyphMaterialSchema schema = metadata.findSchema(palette.schemaId()).orElse(null);
|
||||
final AssetStudioGlyphMaterialSchemaStatus effectiveSchemaStatus = schema == null
|
||||
? AssetStudioGlyphMaterialSchemaStatus.INCONSISTENT
|
||||
: AssetDetailsColorSchemaCoordinator.effectiveStatus(schema, details.bankComposition().selectedFiles());
|
||||
final boolean valid = schema != null
|
||||
&& effectiveSchemaStatus == AssetStudioGlyphMaterialSchemaStatus.OK
|
||||
&& palette.version() >= schema.version();
|
||||
final String invalidReason;
|
||||
if (schema == null) {
|
||||
invalidReason = "Schema is missing.";
|
||||
} else if (effectiveSchemaStatus != AssetStudioGlyphMaterialSchemaStatus.OK) {
|
||||
invalidReason = "Schema is inconsistent.";
|
||||
} else if (palette.version() < schema.version()) {
|
||||
invalidReason = "Palette is stale and must be updated.";
|
||||
} else {
|
||||
invalidReason = null;
|
||||
}
|
||||
records.add(new PaletteRecord(
|
||||
palette.paletteId(),
|
||||
palette.displayName(),
|
||||
palette.schemaId(),
|
||||
palette.version(),
|
||||
palette.colors(),
|
||||
schema == null ? Map.of() : schema.materialIndices(),
|
||||
schema == null ? Set.of() : schemaArtifactIds(schema),
|
||||
false,
|
||||
valid,
|
||||
invalidReason));
|
||||
}
|
||||
records.sort(Comparator.comparing(PaletteRecord::paletteId, String.CASE_INSENSITIVE_ORDER));
|
||||
return List.copyOf(records);
|
||||
}
|
||||
|
||||
private AssetWorkspaceBankCompositionFile toPaletteFile(PaletteRecord record) {
|
||||
final List<Integer> argb = record.colors().stream()
|
||||
.map(AssetDetailsPaletteOverhaulingCoordinator::htmlToArgb8888)
|
||||
.toList();
|
||||
final List<Integer> rgb565 = record.colors().stream()
|
||||
.map(AssetDetailsPaletteOverhaulingCoordinator::htmlToRgb565)
|
||||
.toList();
|
||||
final Map<String, Object> palette = Map.of(
|
||||
"originalArgb8888", argb,
|
||||
"convertedRgb565", rgb565);
|
||||
final Map<String, Object> metadata = new LinkedHashMap<>();
|
||||
metadata.put("palette", palette);
|
||||
metadata.put("paletteId", record.paletteId());
|
||||
metadata.put("paletteDisplayName", displayName(record));
|
||||
if (record.displayName() != null) {
|
||||
metadata.put("explicitPaletteDisplayName", record.displayName());
|
||||
}
|
||||
metadata.put("schemaId", record.schemaId());
|
||||
metadata.put("schemaMaterialIndices", record.materialIndices());
|
||||
metadata.put("schemaArtifactIds", List.copyOf(record.artifactIds()));
|
||||
metadata.put("paletteVersion", record.version());
|
||||
metadata.put("derivedOriginal", record.derivedOriginal());
|
||||
metadata.put("valid", record.valid());
|
||||
if (record.invalidReason() != null) {
|
||||
metadata.put("invalidReason", record.invalidReason());
|
||||
}
|
||||
return new AssetWorkspaceBankCompositionFile(
|
||||
hash,
|
||||
hash,
|
||||
file.size(),
|
||||
file.lastModified(),
|
||||
file.fingerprint(),
|
||||
record.paletteId(),
|
||||
displayName(record),
|
||||
0L,
|
||||
0L,
|
||||
null,
|
||||
metadata);
|
||||
}
|
||||
|
||||
private static List<AssetWorkspaceBankCompositionFile> initialSelectedPaletteFiles(
|
||||
static String generatedDisplayName(List<String> colors) {
|
||||
final List<ColorSample> samples = colors.stream()
|
||||
.map(AssetDetailsPaletteOverhaulingCoordinator::toColorSample)
|
||||
.toList();
|
||||
if (samples.isEmpty()) {
|
||||
return "quiet shade";
|
||||
}
|
||||
final ColorSample anchor = samples.stream()
|
||||
.min(Comparator.comparingDouble(sample -> sample.saturation < 0.16 ? sample.lightness : -sample.saturation))
|
||||
.orElse(samples.getFirst());
|
||||
final double averageLightness = samples.stream()
|
||||
.mapToDouble(sample -> sample.lightness)
|
||||
.average()
|
||||
.orElse(anchor.lightness);
|
||||
final double averageSaturation = samples.stream()
|
||||
.mapToDouble(sample -> sample.saturation)
|
||||
.average()
|
||||
.orElse(anchor.saturation);
|
||||
final double lightnessRange = samples.stream().mapToDouble(sample -> sample.lightness).max().orElse(anchor.lightness)
|
||||
- samples.stream().mapToDouble(sample -> sample.lightness).min().orElse(anchor.lightness);
|
||||
return baseName(anchor, averageLightness, averageSaturation) + " " + moodName(averageLightness, averageSaturation, lightnessRange, samples.size());
|
||||
}
|
||||
|
||||
private static String baseName(ColorSample sample, double averageLightness, double averageSaturation) {
|
||||
if (averageSaturation < 0.12) {
|
||||
if (averageLightness > 0.88) {
|
||||
return "snow";
|
||||
}
|
||||
if (averageLightness > 0.68) {
|
||||
return "fog";
|
||||
}
|
||||
if (averageLightness < 0.24) {
|
||||
return "ink";
|
||||
}
|
||||
return "ash";
|
||||
}
|
||||
final double hue = sample.hue;
|
||||
if (hue < 18 || hue >= 345) {
|
||||
return sample.lightness > 0.62 ? "rose" : "ember";
|
||||
}
|
||||
if (hue < 42) {
|
||||
return sample.lightness > 0.62 ? "honey" : "copper";
|
||||
}
|
||||
if (hue < 72) {
|
||||
return sample.lightness > 0.68 ? "sun" : "ochre";
|
||||
}
|
||||
if (hue < 155) {
|
||||
return sample.lightness > 0.58 ? "moss" : "pine";
|
||||
}
|
||||
if (hue < 195) {
|
||||
return sample.lightness > 0.62 ? "mint" : "jade";
|
||||
}
|
||||
if (hue < 245) {
|
||||
return sample.lightness > 0.62 ? "sky" : "cobalt";
|
||||
}
|
||||
if (hue < 290) {
|
||||
return sample.lightness > 0.62 ? "lilac" : "violet";
|
||||
}
|
||||
return sample.lightness > 0.62 ? "orchid" : "plum";
|
||||
}
|
||||
|
||||
private static String moodName(double averageLightness, double averageSaturation, double lightnessRange, int colorCount) {
|
||||
if (averageSaturation < 0.12 && averageLightness > 0.86) {
|
||||
return "white";
|
||||
}
|
||||
if (colorCount > 1 && lightnessRange > 0.42) {
|
||||
return "twist";
|
||||
}
|
||||
if (averageLightness > 0.78) {
|
||||
return averageSaturation > 0.45 ? "glow" : "veil";
|
||||
}
|
||||
if (averageLightness < 0.26) {
|
||||
return averageSaturation > 0.34 ? "deep" : "shade";
|
||||
}
|
||||
if (averageSaturation > 0.62) {
|
||||
return "bloom";
|
||||
}
|
||||
if (averageSaturation < 0.22) {
|
||||
return "haze";
|
||||
}
|
||||
return "drift";
|
||||
}
|
||||
|
||||
private static ColorSample toColorSample(String htmlColor) {
|
||||
final int rgb = Integer.parseInt(normalizeHtmlColor(htmlColor).substring(1), 16);
|
||||
final double red = ((rgb >> 16) & 0xFF) / 255.0;
|
||||
final double green = ((rgb >> 8) & 0xFF) / 255.0;
|
||||
final double blue = (rgb & 0xFF) / 255.0;
|
||||
final double max = Math.max(red, Math.max(green, blue));
|
||||
final double min = Math.min(red, Math.min(green, blue));
|
||||
final double delta = max - min;
|
||||
final double lightness = (max + min) / 2.0;
|
||||
final double saturation = delta == 0.0
|
||||
? 0.0
|
||||
: delta / (1.0 - Math.abs((2.0 * lightness) - 1.0));
|
||||
final double hue;
|
||||
if (delta == 0.0) {
|
||||
hue = 0.0;
|
||||
} else if (max == red) {
|
||||
hue = 60.0 * (((green - blue) / delta) % 6.0);
|
||||
} else if (max == green) {
|
||||
hue = 60.0 * (((blue - red) / delta) + 2.0);
|
||||
} else {
|
||||
hue = 60.0 * (((red - green) / delta) + 4.0);
|
||||
}
|
||||
return new ColorSample(hue < 0.0 ? hue + 360.0 : hue, saturation, lightness);
|
||||
}
|
||||
|
||||
private static String displayName(PaletteRecord record) {
|
||||
if (record.derivedOriginal()) {
|
||||
return record.schemaId() + " / original";
|
||||
}
|
||||
return record.displayName() == null || record.displayName().isBlank()
|
||||
? generatedDisplayName(record.colors())
|
||||
: record.displayName();
|
||||
}
|
||||
|
||||
private List<AssetWorkspaceBankCompositionFile> initialSelectedPaletteFiles(
|
||||
AssetWorkspaceAssetDetails details,
|
||||
List<AssetWorkspaceBankCompositionFile> allFiles) {
|
||||
final List<AssetWorkspaceBankCompositionFile> selected = new ArrayList<>();
|
||||
@@ -186,32 +508,21 @@ public final class AssetDetailsPaletteOverhaulingCoordinator {
|
||||
&& Objects.equals(left.get("convertedRgb565"), right.get("convertedRgb565"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static String paletteHash(AssetWorkspaceBankCompositionFile file) {
|
||||
final Map<String, Object> palette = nestedMap(file.metadata(), "palette");
|
||||
final Object convertedValue = palette == null ? null : palette.get("convertedRgb565");
|
||||
final List<Integer> colors = convertedValue instanceof List<?> converted
|
||||
? (List<Integer>) converted
|
||||
: List.of();
|
||||
try {
|
||||
final MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
for (int index = 0; index < 15; index++) {
|
||||
final int color = index < colors.size() && colors.get(index) != null ? colors.get(index) : 0;
|
||||
digest.update(ByteBuffer.allocate(4).putInt(color).array());
|
||||
}
|
||||
long value = 0L;
|
||||
final byte[] bytes = digest.digest();
|
||||
for (int index = 0; index < 8; index++) {
|
||||
value = (value << 8) | Byte.toUnsignedLong(bytes[index]);
|
||||
}
|
||||
value &= 0x0FFFFFFFFFFFFFFFL;
|
||||
final String base36 = Long.toUnsignedString(value, 36).toUpperCase();
|
||||
return base36.length() >= 10
|
||||
? base36.substring(0, 10)
|
||||
: "0".repeat(10 - base36.length()) + base36;
|
||||
} catch (Exception exception) {
|
||||
throw new IllegalStateException("Unable to hash palette colors", exception);
|
||||
}
|
||||
private static int htmlToArgb8888(String htmlColor) {
|
||||
final int rgb = Integer.parseInt(normalizeHtmlColor(htmlColor).substring(1), 16);
|
||||
return 0xFF000000 | rgb;
|
||||
}
|
||||
|
||||
private static int htmlToRgb565(String htmlColor) {
|
||||
final int rgb = Integer.parseInt(normalizeHtmlColor(htmlColor).substring(1), 16);
|
||||
final int red = (rgb >> 16) & 0xFF;
|
||||
final int green = (rgb >> 8) & 0xFF;
|
||||
final int blue = rgb & 0xFF;
|
||||
return ((red >> 3) << 11) | ((green >> 2) << 5) | (blue >> 3);
|
||||
}
|
||||
|
||||
private static String normalizeHtmlColor(String color) {
|
||||
return Objects.requireNonNull(color, "color").trim().toUpperCase();
|
||||
}
|
||||
|
||||
private static AssetWorkspaceBankCompositionFile fileByPath(List<AssetWorkspaceBankCompositionFile> files, String path) {
|
||||
@@ -223,4 +534,93 @@ public final class AssetDetailsPaletteOverhaulingCoordinator {
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private static AssetDetailsPaletteOverhaulingDraft rebindDraft(
|
||||
AssetDetailsPaletteOverhaulingDraft draft,
|
||||
AssetDetailsPaletteOverhaulingDraft source) {
|
||||
final Set<String> selectedPaths = draft.selectedFiles().stream()
|
||||
.map(AssetWorkspaceBankCompositionFile::path)
|
||||
.collect(java.util.stream.Collectors.toCollection(LinkedHashSet::new));
|
||||
final List<AssetWorkspaceBankCompositionFile> selected = source.allFiles().stream()
|
||||
.filter(file -> selectedPaths.contains(file.path()))
|
||||
.toList();
|
||||
final List<AssetWorkspaceBankCompositionFile> available = source.allFiles().stream()
|
||||
.filter(file -> !selectedPaths.contains(file.path()))
|
||||
.toList();
|
||||
final String previewPalettePath = fileByPath(source.allFiles(), draft.previewPalettePath()) == null
|
||||
? source.previewPalettePath()
|
||||
: draft.previewPalettePath();
|
||||
final String previewTilePath = fileByPath(source.previewTileFiles(), draft.previewTilePath()) == null
|
||||
? source.previewTilePath()
|
||||
: draft.previewTilePath();
|
||||
return new AssetDetailsPaletteOverhaulingDraft(
|
||||
source.previewTileFiles(),
|
||||
source.allFiles(),
|
||||
available,
|
||||
selected,
|
||||
previewTilePath,
|
||||
previewPalettePath);
|
||||
}
|
||||
|
||||
private static Set<String> schemaArtifactIds(AssetStudioGlyphMaterialSchema schema) {
|
||||
return schema.artifactBindings().stream()
|
||||
.map(AssetStudioGlyphMaterialArtifactBinding::artifactId)
|
||||
.collect(java.util.stream.Collectors.toCollection(LinkedHashSet::new));
|
||||
}
|
||||
|
||||
private static List<AssetWorkspaceBankCompositionFile> previewTileFilesForPalette(
|
||||
List<AssetWorkspaceBankCompositionFile> previewTileFiles,
|
||||
AssetWorkspaceBankCompositionFile previewPaletteFile) {
|
||||
if (previewPaletteFile == null) {
|
||||
return previewTileFiles;
|
||||
}
|
||||
final Set<String> schemaArtifactIds = schemaArtifactIds(previewPaletteFile);
|
||||
if (schemaArtifactIds.isEmpty()) {
|
||||
return previewTileFiles;
|
||||
}
|
||||
return previewTileFiles.stream()
|
||||
.filter(file -> schemaArtifactIds.contains(artifactId(file)))
|
||||
.toList();
|
||||
}
|
||||
|
||||
private static Set<String> schemaArtifactIds(AssetWorkspaceBankCompositionFile previewPaletteFile) {
|
||||
final Object artifactIds = previewPaletteFile.metadata().get("schemaArtifactIds");
|
||||
if (!(artifactIds instanceof Iterable<?> iterable)) {
|
||||
return Set.of();
|
||||
}
|
||||
final Set<String> ids = new LinkedHashSet<>();
|
||||
for (Object artifactId : iterable) {
|
||||
if (artifactId instanceof String value && !value.isBlank()) {
|
||||
ids.add(value.trim());
|
||||
}
|
||||
}
|
||||
return Set.copyOf(ids);
|
||||
}
|
||||
|
||||
private static String artifactId(AssetWorkspaceBankCompositionFile file) {
|
||||
if (file == null) {
|
||||
return null;
|
||||
}
|
||||
final Object artifactId = file.metadata().get("artifactId");
|
||||
if (artifactId instanceof String value && !value.isBlank()) {
|
||||
return value.trim();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private record PaletteRecord(
|
||||
String paletteId,
|
||||
String displayName,
|
||||
String schemaId,
|
||||
int version,
|
||||
List<String> colors,
|
||||
Map<Integer, String> materialIndices,
|
||||
Set<String> artifactIds,
|
||||
boolean derivedOriginal,
|
||||
boolean valid,
|
||||
String invalidReason) {
|
||||
}
|
||||
|
||||
private record ColorSample(double hue, double saturation, double lightness) {
|
||||
}
|
||||
}
|
||||
|
||||
+10
-2
@@ -4,6 +4,7 @@ import javafx.scene.Node;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.Container;
|
||||
import p.studio.controls.banks.StudioDualListView;
|
||||
import p.studio.utilities.i18n.I18n;
|
||||
@@ -28,8 +29,15 @@ public final class AssetDetailsPaletteOverhaulingDualListView extends StudioDual
|
||||
final Label hashLabel = new Label(item.displayName());
|
||||
hashLabel.getStyleClass().add("assets-details-palette-hash");
|
||||
final HBox strip = createPaletteStrip(item);
|
||||
final HBox root = new HBox(8, hashLabel, strip);
|
||||
root.getStyleClass().add("assets-details-palette-item");
|
||||
final HBox top = new HBox(8, hashLabel, strip);
|
||||
top.getStyleClass().add("assets-details-palette-item");
|
||||
final Object invalidReason = item.metadata().get("invalidReason");
|
||||
if (!(invalidReason instanceof String reason) || reason.isBlank()) {
|
||||
return top;
|
||||
}
|
||||
final Label invalidLabel = new Label(reason);
|
||||
invalidLabel.getStyleClass().add("assets-details-palette-invalid");
|
||||
final VBox root = new VBox(4, top, invalidLabel);
|
||||
return root;
|
||||
}
|
||||
|
||||
|
||||
+43
-1
@@ -146,6 +146,8 @@ public final class AssetDetailsPaletteOverhaulingPreviewPane extends VBox {
|
||||
final Integer height = asInteger(tile.get("height"));
|
||||
final List<Integer> indices = paletteIndices(tile.get("paletteIndices"));
|
||||
final List<Integer> colors = paletteDisplayColors(paletteFile.metadata());
|
||||
final List<Integer> sourceColors = tileDisplayColors(tileFile.metadata());
|
||||
final Map<String, Integer> schemaIndicesByColor = schemaIndicesByColor(paletteFile.metadata());
|
||||
if (width == null || height == null || width <= 0 || height <= 0 || indices.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@@ -153,7 +155,7 @@ public final class AssetDetailsPaletteOverhaulingPreviewPane extends VBox {
|
||||
final double pixelWidth = PREVIEW_SIZE / width;
|
||||
final double pixelHeight = PREVIEW_SIZE / height;
|
||||
for (int index = 0; index < indices.size(); index++) {
|
||||
final int paletteIndex = indices.get(index);
|
||||
final int paletteIndex = schemaPaletteIndex(indices.get(index), sourceColors, schemaIndicesByColor);
|
||||
final int x = index % width;
|
||||
final int y = index / width;
|
||||
graphics.setFill(toFxColor(paletteIndexToArgb(colors, paletteIndex)));
|
||||
@@ -206,6 +208,35 @@ public final class AssetDetailsPaletteOverhaulingPreviewPane extends VBox {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Integer> tileDisplayColors(Map<String, Object> metadata) {
|
||||
final Map<String, Object> palette = nestedMap(metadata, "palette");
|
||||
if (palette == null) {
|
||||
return List.of();
|
||||
}
|
||||
final Object original = palette.get("originalArgb8888");
|
||||
if (original instanceof List<?> list) {
|
||||
return (List<Integer>) list;
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
private Map<String, Integer> schemaIndicesByColor(Map<String, Object> metadata) {
|
||||
final Object materialIndices = metadata.get("schemaMaterialIndices");
|
||||
if (!(materialIndices instanceof Map<?, ?> map)) {
|
||||
return Map.of();
|
||||
}
|
||||
final Map<String, Integer> indicesByColor = new java.util.LinkedHashMap<>();
|
||||
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
||||
final Integer index = asInteger(entry.getKey());
|
||||
if (index == null || index <= 0 || !(entry.getValue() instanceof String color) || color.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
indicesByColor.put(color.trim().toUpperCase(), index);
|
||||
}
|
||||
return Map.copyOf(indicesByColor);
|
||||
}
|
||||
|
||||
private Integer asInteger(Object value) {
|
||||
if (value instanceof Number number) {
|
||||
return number.intValue();
|
||||
@@ -220,6 +251,17 @@ public final class AssetDetailsPaletteOverhaulingPreviewPane extends VBox {
|
||||
return colorAt(colors, paletteIndex - 1);
|
||||
}
|
||||
|
||||
private int schemaPaletteIndex(int tilePaletteIndex, List<Integer> sourceColors, Map<String, Integer> schemaIndicesByColor) {
|
||||
if (tilePaletteIndex <= 0 || sourceColors.isEmpty() || schemaIndicesByColor.isEmpty()) {
|
||||
return tilePaletteIndex;
|
||||
}
|
||||
final int sourceColorIndex = tilePaletteIndex - 1;
|
||||
if (sourceColorIndex < 0 || sourceColorIndex >= sourceColors.size()) {
|
||||
return 0;
|
||||
}
|
||||
return schemaIndicesByColor.getOrDefault(cssColor(sourceColors.get(sourceColorIndex)), 0);
|
||||
}
|
||||
|
||||
private int colorAt(List<Integer> colors, int index) {
|
||||
if (index < 0 || index >= colors.size()) {
|
||||
return 0x00000000;
|
||||
|
||||
+281
@@ -0,0 +1,281 @@
|
||||
package p.studio.workspaces.assets.details.palette;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ColorPicker;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.Window;
|
||||
import p.studio.Container;
|
||||
import p.studio.utilities.i18n.I18n;
|
||||
import p.studio.workspaces.assets.messages.AssetWorkspaceBankCompositionFile;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioGlyphMaterialSchema;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class AssetDetailsPaletteWizardDialog {
|
||||
private final Stage stage = new Stage();
|
||||
private final ComboBox<AssetStudioGlyphMaterialSchema> schemaComboBox = new ComboBox<>();
|
||||
private final TextField nameField = new TextField();
|
||||
private final ObservableList<String> editableColors = FXCollections.observableArrayList();
|
||||
private final ObservableList<String> indexItems = FXCollections.observableArrayList();
|
||||
private final ListView<String> indexListView = new ListView<>(indexItems);
|
||||
private final ColorPicker colorPicker = new ColorPicker(Color.WHITE);
|
||||
private final Label summaryLabel = new Label();
|
||||
private final HBox originalStrip = new HBox(4);
|
||||
private final HBox editableStrip = new HBox(4);
|
||||
|
||||
private PaletteEditResult result;
|
||||
private final String paletteId;
|
||||
private final boolean editing;
|
||||
|
||||
private AssetDetailsPaletteWizardDialog(
|
||||
Window owner,
|
||||
AssetDetailsPaletteOverhaulingCoordinator coordinator,
|
||||
AssetWorkspaceBankCompositionFile paletteFile) {
|
||||
this.editing = paletteFile != null;
|
||||
this.paletteId = editing && paletteFile.metadata().get("paletteId") instanceof String id && !id.isBlank()
|
||||
? id
|
||||
: coordinator.nextPaletteId();
|
||||
stage.initOwner(owner);
|
||||
stage.initModality(Modality.WINDOW_MODAL);
|
||||
stage.setTitle(Container.i18n().text(editing
|
||||
? I18n.ASSETS_PALETTE_WIZARD_UPDATE_TITLE
|
||||
: I18n.ASSETS_PALETTE_WIZARD_CREATE_TITLE));
|
||||
|
||||
final List<AssetStudioGlyphMaterialSchema> schemas = coordinator.readySchemas();
|
||||
schemaComboBox.getItems().setAll(schemas);
|
||||
schemaComboBox.setCellFactory(ignored -> new javafx.scene.control.ListCell<>() {
|
||||
@Override
|
||||
protected void updateItem(AssetStudioGlyphMaterialSchema item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
setText(empty || item == null ? null : item.schemaId());
|
||||
}
|
||||
});
|
||||
schemaComboBox.setButtonCell(schemaComboBox.getCellFactory().call(null));
|
||||
|
||||
final AssetStudioGlyphMaterialSchema initialSchema = resolveInitialSchema(coordinator, paletteFile, schemas);
|
||||
if (initialSchema != null) {
|
||||
schemaComboBox.getSelectionModel().select(initialSchema);
|
||||
}
|
||||
editableColors.setAll(initialEditableColors(paletteFile, initialSchema));
|
||||
nameField.setText(initialDisplayName(paletteFile));
|
||||
nameField.setPromptText(AssetDetailsPaletteOverhaulingCoordinator.generatedDisplayName(editableColors));
|
||||
schemaComboBox.valueProperty().addListener((ignored, previous, current) -> {
|
||||
if (current == null) {
|
||||
editableColors.clear();
|
||||
} else if (!editing || previous == null || !Objects.equals(previous.schemaId(), current.schemaId())) {
|
||||
editableColors.setAll(current.materialIndices().entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByKey())
|
||||
.map(Map.Entry::getValue)
|
||||
.toList());
|
||||
}
|
||||
refreshPreview(coordinator);
|
||||
});
|
||||
nameField.textProperty().addListener((ignored, previous, current) -> refreshPreview(coordinator));
|
||||
indexListView.getSelectionModel().selectedIndexProperty().addListener((ignored, previous, current) -> {
|
||||
final int selected = current == null ? -1 : current.intValue();
|
||||
if (selected >= 0 && selected < editableColors.size()) {
|
||||
colorPicker.setValue(Color.web(editableColors.get(selected)));
|
||||
}
|
||||
});
|
||||
|
||||
final Button applyColorButton = new Button(Container.i18n().text(I18n.ASSETS_PALETTE_WIZARD_APPLY_COLOR));
|
||||
applyColorButton.getStyleClass().addAll("studio-button", "studio-button-secondary");
|
||||
applyColorButton.setOnAction(ignored -> {
|
||||
final int index = indexListView.getSelectionModel().getSelectedIndex();
|
||||
if (index < 0 || index >= editableColors.size()) {
|
||||
return;
|
||||
}
|
||||
editableColors.set(index, toHtmlColor(colorPicker.getValue()));
|
||||
refreshPreview(coordinator);
|
||||
indexListView.getSelectionModel().select(index);
|
||||
});
|
||||
|
||||
final Button cancelButton = new Button(Container.i18n().text(I18n.FORM_ACTION_CANCEL));
|
||||
cancelButton.getStyleClass().addAll("studio-button", "studio-button-secondary");
|
||||
cancelButton.setOnAction(ignored -> {
|
||||
result = null;
|
||||
stage.close();
|
||||
});
|
||||
final Button applyButton = new Button(Container.i18n().text(I18n.FORM_ACTION_APPLY));
|
||||
applyButton.getStyleClass().addAll("studio-button", "studio-button-primary");
|
||||
applyButton.setOnAction(ignored -> {
|
||||
final AssetStudioGlyphMaterialSchema selectedSchema = schemaComboBox.getSelectionModel().getSelectedItem();
|
||||
if (selectedSchema == null || coordinator.duplicatePaletteExists(paletteId, selectedSchema.schemaId(), editableColors)) {
|
||||
return;
|
||||
}
|
||||
result = new PaletteEditResult(paletteId, normalizedDisplayName(), selectedSchema.schemaId(), List.copyOf(editableColors));
|
||||
stage.close();
|
||||
});
|
||||
final Region spacer = new Region();
|
||||
HBox.setHgrow(spacer, Priority.ALWAYS);
|
||||
final HBox actions = new HBox(8, spacer, cancelButton, applyButton);
|
||||
actions.getStyleClass().add("assets-details-palette-wizard-actions");
|
||||
|
||||
final Label schemaLabel = fieldLabel(I18n.ASSETS_PALETTE_WIZARD_SCHEMA);
|
||||
final Label nameLabel = fieldLabel(I18n.ASSETS_PALETTE_WIZARD_NAME);
|
||||
final Label originalLabel = fieldLabel(I18n.ASSETS_PALETTE_WIZARD_ORIGINAL);
|
||||
final Label editableLabel = fieldLabel(I18n.ASSETS_PALETTE_WIZARD_EDITABLE);
|
||||
final VBox colorEditor = new VBox(8, colorPicker, applyColorButton);
|
||||
colorEditor.getStyleClass().add("assets-details-palette-wizard-color-editor");
|
||||
final HBox editorBody = new HBox(12, indexListView, colorEditor);
|
||||
editorBody.getStyleClass().add("assets-details-palette-wizard-editor");
|
||||
final VBox root = new VBox(
|
||||
12,
|
||||
nameLabel,
|
||||
nameField,
|
||||
schemaLabel,
|
||||
schemaComboBox,
|
||||
originalLabel,
|
||||
originalStrip,
|
||||
editableLabel,
|
||||
editableStrip,
|
||||
editorBody,
|
||||
summaryLabel,
|
||||
actions);
|
||||
root.setPadding(new Insets(16));
|
||||
root.getStyleClass().add("assets-details-palette-wizard");
|
||||
originalStrip.getStyleClass().add("assets-details-palette-wizard-strip");
|
||||
editableStrip.getStyleClass().add("assets-details-palette-wizard-strip");
|
||||
summaryLabel.getStyleClass().add("assets-details-palette-wizard-summary");
|
||||
HBox.setHgrow(indexListView, Priority.ALWAYS);
|
||||
HBox.setHgrow(schemaComboBox, Priority.ALWAYS);
|
||||
HBox.setHgrow(nameField, Priority.ALWAYS);
|
||||
refreshPreview(coordinator);
|
||||
final Scene scene = new Scene(root, 620, 570);
|
||||
scene.getStylesheets().add(Container.theme().getDefaultTheme());
|
||||
stage.setScene(scene);
|
||||
stage.setOnShown(ignored -> stage.centerOnScreen());
|
||||
}
|
||||
|
||||
public static Optional<PaletteEditResult> showAndWait(
|
||||
Window owner,
|
||||
AssetDetailsPaletteOverhaulingCoordinator coordinator,
|
||||
AssetWorkspaceBankCompositionFile paletteFile) {
|
||||
final AssetDetailsPaletteWizardDialog dialog = new AssetDetailsPaletteWizardDialog(owner, coordinator, paletteFile);
|
||||
dialog.stage.showAndWait();
|
||||
return Optional.ofNullable(dialog.result);
|
||||
}
|
||||
|
||||
private Label fieldLabel(I18n label) {
|
||||
final Label node = new Label(Container.i18n().text(label));
|
||||
node.getStyleClass().add("assets-details-palette-wizard-label");
|
||||
return node;
|
||||
}
|
||||
|
||||
private AssetStudioGlyphMaterialSchema resolveInitialSchema(
|
||||
AssetDetailsPaletteOverhaulingCoordinator coordinator,
|
||||
AssetWorkspaceBankCompositionFile paletteFile,
|
||||
List<AssetStudioGlyphMaterialSchema> schemas) {
|
||||
if (paletteFile != null && paletteFile.metadata().get("schemaId") instanceof String schemaId) {
|
||||
return coordinator.readySchemas().stream()
|
||||
.filter(schema -> schema.schemaId().equals(schemaId))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
return schemas.isEmpty() ? null : schemas.getFirst();
|
||||
}
|
||||
|
||||
private List<String> initialEditableColors(
|
||||
AssetWorkspaceBankCompositionFile paletteFile,
|
||||
AssetStudioGlyphMaterialSchema initialSchema) {
|
||||
if (paletteFile != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
final Map<String, Object> palette = (Map<String, Object>) paletteFile.metadata().get("palette");
|
||||
final Object original = palette == null ? null : palette.get("originalArgb8888");
|
||||
if (original instanceof Iterable<?> iterable) {
|
||||
final List<String> colors = new ArrayList<>();
|
||||
for (Object value : iterable) {
|
||||
if (value instanceof Number number) {
|
||||
colors.add(String.format("#%06X", number.intValue() & 0x00FFFFFF));
|
||||
}
|
||||
}
|
||||
return List.copyOf(colors);
|
||||
}
|
||||
}
|
||||
if (initialSchema == null) {
|
||||
return List.of();
|
||||
}
|
||||
return initialSchema.materialIndices().entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByKey())
|
||||
.map(Map.Entry::getValue)
|
||||
.toList();
|
||||
}
|
||||
|
||||
private String initialDisplayName(AssetWorkspaceBankCompositionFile paletteFile) {
|
||||
if (paletteFile == null) {
|
||||
return "";
|
||||
}
|
||||
final Object explicitName = paletteFile.metadata().get("explicitPaletteDisplayName");
|
||||
return explicitName instanceof String value ? value : "";
|
||||
}
|
||||
|
||||
private void refreshPreview(AssetDetailsPaletteOverhaulingCoordinator coordinator) {
|
||||
final AssetStudioGlyphMaterialSchema schema = schemaComboBox.getSelectionModel().getSelectedItem();
|
||||
final List<String> originalColors = schema == null
|
||||
? List.of()
|
||||
: schema.materialIndices().entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByKey())
|
||||
.map(Map.Entry::getValue)
|
||||
.toList();
|
||||
originalStrip.getChildren().setAll(originalColors.stream().map(this::swatch).toList());
|
||||
editableStrip.getChildren().setAll(editableColors.stream().map(this::swatch).toList());
|
||||
nameField.setPromptText(AssetDetailsPaletteOverhaulingCoordinator.generatedDisplayName(editableColors));
|
||||
indexItems.setAll(java.util.stream.IntStream.range(0, editableColors.size())
|
||||
.mapToObj(index -> (index + 1) + " -> " + editableColors.get(index))
|
||||
.toList());
|
||||
final boolean duplicate = schema != null && coordinator.duplicatePaletteExists(paletteId, schema.schemaId(), editableColors);
|
||||
summaryLabel.setText(duplicate
|
||||
? Container.i18n().text(I18n.ASSETS_PALETTE_WIZARD_DUPLICATE)
|
||||
: Container.i18n().text(I18n.ASSETS_PALETTE_WIZARD_READY));
|
||||
}
|
||||
|
||||
private String normalizedDisplayName() {
|
||||
final String value = nameField.getText();
|
||||
return value == null || value.trim().isBlank()
|
||||
? AssetDetailsPaletteOverhaulingCoordinator.generatedDisplayName(editableColors)
|
||||
: value.trim();
|
||||
}
|
||||
|
||||
private Region swatch(String color) {
|
||||
final Region swatch = new Region();
|
||||
swatch.setMinSize(22, 22);
|
||||
swatch.setPrefSize(22, 22);
|
||||
swatch.setMaxSize(22, 22);
|
||||
swatch.getStyleClass().add("assets-details-palette-wizard-swatch");
|
||||
swatch.setStyle("-fx-background-color: " + color + ";");
|
||||
return swatch;
|
||||
}
|
||||
|
||||
private String toHtmlColor(Color color) {
|
||||
return String.format(
|
||||
"#%02X%02X%02X",
|
||||
(int) Math.round(color.getRed() * 255),
|
||||
(int) Math.round(color.getGreen() * 255),
|
||||
(int) Math.round(color.getBlue() * 255));
|
||||
}
|
||||
|
||||
public record PaletteEditResult(
|
||||
String paletteId,
|
||||
String displayName,
|
||||
String schemaId,
|
||||
List<String> colors) {
|
||||
}
|
||||
}
|
||||
+545
@@ -0,0 +1,545 @@
|
||||
package p.studio.workspaces.assets.details.scene;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ListCell;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.Container;
|
||||
import p.studio.controls.forms.StudioFormMode;
|
||||
import p.studio.controls.lifecycle.StudioControlLifecycle;
|
||||
import p.studio.controls.lifecycle.StudioControlLifecycleSupport;
|
||||
import p.studio.lsp.events.StudioWorkspaceEventBus;
|
||||
import p.studio.projects.ProjectReference;
|
||||
import p.studio.utilities.i18n.I18n;
|
||||
import p.studio.workspaces.assets.details.AssetDetailsUiSupport;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioMetadataService;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioSceneBankMetadata;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioSceneLayerBinding;
|
||||
import p.studio.workspaces.assets.messages.AssetWorkspaceDetailsViewState;
|
||||
import p.studio.workspaces.assets.messages.events.StudioAssetLogEvent;
|
||||
import p.studio.workspaces.assets.messages.events.StudioAssetsRefreshRequestedEvent;
|
||||
import p.studio.workspaces.assets.messages.events.StudioAssetsDetailsViewStateChangedEvent;
|
||||
import p.studio.workspaces.assets.messages.events.StudioAssetsWorkspaceSelectionRequestedEvent;
|
||||
import p.studio.workspaces.framework.StudioSubscriptionBag;
|
||||
import p.packer.messages.ListAssetsRequest;
|
||||
import p.packer.messages.assets.AssetFamilyCatalog;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
public final class AssetDetailsSceneLayersControl extends VBox implements StudioControlLifecycle {
|
||||
private final ProjectReference projectReference;
|
||||
private final StudioWorkspaceEventBus workspaceBus;
|
||||
private final StudioSubscriptionBag subscriptions = new StudioSubscriptionBag();
|
||||
private final AssetStudioMetadataService metadataService = new AssetStudioMetadataService();
|
||||
|
||||
private AssetWorkspaceDetailsViewState viewState;
|
||||
private IntConsumer generateLayerAction = ignored -> {
|
||||
};
|
||||
private IntConsumer validateLayerAction = ignored -> {
|
||||
};
|
||||
private IntConsumer acceptLayerAction = ignored -> {
|
||||
};
|
||||
private Integer editingLayerIndex;
|
||||
private LayerDraft editingDraft;
|
||||
private int selectedLayerIndex = 1;
|
||||
|
||||
public AssetDetailsSceneLayersControl(ProjectReference projectReference, StudioWorkspaceEventBus workspaceBus) {
|
||||
StudioControlLifecycleSupport.install(this, this);
|
||||
this.projectReference = Objects.requireNonNull(projectReference, "projectReference");
|
||||
this.workspaceBus = Objects.requireNonNull(workspaceBus, "workspaceBus");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribe() {
|
||||
subscriptions.add(workspaceBus.subscribe(StudioAssetsDetailsViewStateChangedEvent.class, event -> {
|
||||
viewState = event.viewState();
|
||||
render();
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribe() {
|
||||
subscriptions.clear();
|
||||
}
|
||||
|
||||
public void setGenerateLayerAction(IntConsumer generateLayerAction) {
|
||||
this.generateLayerAction = Objects.requireNonNull(generateLayerAction, "generateLayerAction");
|
||||
}
|
||||
|
||||
public void setValidateLayerAction(IntConsumer validateLayerAction) {
|
||||
this.validateLayerAction = Objects.requireNonNull(validateLayerAction, "validateLayerAction");
|
||||
}
|
||||
|
||||
public void setAcceptLayerAction(IntConsumer acceptLayerAction) {
|
||||
this.acceptLayerAction = Objects.requireNonNull(acceptLayerAction, "acceptLayerAction");
|
||||
}
|
||||
|
||||
private void render() {
|
||||
final AssetStudioSceneBankMetadata metadata = viewState == null || viewState.selectedAssetDetails() == null
|
||||
? null
|
||||
: viewState.selectedAssetDetails().sceneBankMetadata();
|
||||
if (metadata == null || viewState.selectedAssetDetails() == null) {
|
||||
getChildren().clear();
|
||||
return;
|
||||
}
|
||||
|
||||
final VBox content = new VBox(10);
|
||||
content.getChildren().add(createLayerSelector(
|
||||
viewState.selectedAssetDetails().summary().assetRoot(),
|
||||
metadata));
|
||||
content.getStyleClass().add("assets-scene-layer-shell");
|
||||
|
||||
getChildren().setAll(AssetDetailsUiSupport.createSectionWithoutHeader(content));
|
||||
}
|
||||
|
||||
private Node createLayerSelector(Path sceneAssetRoot, AssetStudioSceneBankMetadata metadata) {
|
||||
if (selectedLayerIndex < 1 || selectedLayerIndex > metadata.layerCount()) {
|
||||
selectedLayerIndex = 1;
|
||||
}
|
||||
final HBox selector = new HBox(8);
|
||||
selector.getStyleClass().add("assets-scene-layer-selector");
|
||||
for (int index = 1; index <= 4; index += 1) {
|
||||
final int layerIndex = index;
|
||||
final Button button = new Button(Container.i18n().text(I18n.ASSETS_LABEL_LAYER) + " " + layerIndex);
|
||||
button.getStyleClass().addAll("studio-button", "assets-scene-layer-selector-button");
|
||||
if (layerIndex == selectedLayerIndex) {
|
||||
button.getStyleClass().add("assets-scene-layer-selector-button-active");
|
||||
}
|
||||
button.setOnAction(ignored -> {
|
||||
selectedLayerIndex = layerIndex;
|
||||
render();
|
||||
});
|
||||
selector.getChildren().add(button);
|
||||
}
|
||||
|
||||
final AssetStudioSceneLayerBinding binding = metadata.layerBindings().stream()
|
||||
.filter(candidate -> candidate.index() == selectedLayerIndex)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
final VBox container = new VBox(10);
|
||||
container.getChildren().addAll(selector, createLayerCard(sceneAssetRoot, selectedLayerIndex, binding));
|
||||
return container;
|
||||
}
|
||||
|
||||
private Node createLayerCard(Path sceneAssetRoot, int layerIndex, AssetStudioSceneLayerBinding binding) {
|
||||
final boolean editing = Objects.equals(editingLayerIndex, layerIndex) && binding != null && editingDraft != null;
|
||||
final LayerDraft draft = editing ? editingDraft : LayerDraft.from(binding);
|
||||
final VBox formContent = buildLayerFormContent(sceneAssetRoot, binding, draft, editing);
|
||||
final VBox formSection = AssetDetailsUiSupport.createEditableSection(
|
||||
Container.i18n().text(I18n.ASSETS_SECTION_LAYER_CONFIGURATION),
|
||||
createLayerFormHeaderActions(layerIndex, binding, editing),
|
||||
formContent,
|
||||
editing ? StudioFormMode.EDITING : StudioFormMode.READ_ONLY);
|
||||
formSection.getStyleClass().add("assets-scene-layer-config-section");
|
||||
|
||||
final VBox leftColumn = new VBox(10);
|
||||
leftColumn.getStyleClass().add("assets-scene-layer-config-column");
|
||||
leftColumn.getChildren().addAll(
|
||||
formSection,
|
||||
createLayerActions(sceneAssetRoot, layerIndex, draft));
|
||||
|
||||
final VBox overview = createLayerOverviewPlaceholder();
|
||||
final HBox layout = new HBox(12, leftColumn, overview);
|
||||
layout.getStyleClass().add("assets-scene-layer-layout");
|
||||
HBox.setHgrow(leftColumn, Priority.ALWAYS);
|
||||
return layout;
|
||||
}
|
||||
|
||||
private VBox buildLayerFormContent(Path sceneAssetRoot, AssetStudioSceneLayerBinding binding, LayerDraft draft, boolean editing) {
|
||||
final VBox card = new VBox(8);
|
||||
card.getStyleClass().addAll("assets-scene-layer-card", "assets-scene-layer-config");
|
||||
|
||||
final CheckBox enabledCheckBox = new CheckBox(Container.i18n().text(I18n.ASSETS_LABEL_USE_LAYER));
|
||||
enabledCheckBox.setSelected(draft != null && draft.enabled());
|
||||
enabledCheckBox.getStyleClass().add("assets-scene-layer-enabled");
|
||||
enabledCheckBox.setDisable(!editing);
|
||||
enabledCheckBox.setOnAction(ignored -> {
|
||||
if (draft != null) {
|
||||
draft.setEnabled(enabledCheckBox.isSelected());
|
||||
}
|
||||
});
|
||||
card.getChildren().add(enabledCheckBox);
|
||||
|
||||
card.getChildren().addAll(
|
||||
AssetDetailsUiSupport.createKeyValueRow(
|
||||
Container.i18n().text(I18n.ASSETS_LABEL_SCENE_DIMENSIONS),
|
||||
editing ? createLayerSizeEditor(draft) : new Label(draft.widthText() + " x " + draft.heightText())),
|
||||
AssetDetailsUiSupport.createKeyValueRow(
|
||||
Container.i18n().text(I18n.ASSETS_LABEL_TILEMAP),
|
||||
binding == null
|
||||
? Container.i18n().text(I18n.ASSETS_VALUE_NOT_CONFIGURED)
|
||||
: AssetDetailsUiSupport.projectRelativePath(projectReference, sceneAssetRoot.resolve(binding.tilemap()))),
|
||||
AssetDetailsUiSupport.createKeyValueRow(
|
||||
Container.i18n().text(I18n.ASSETS_LABEL_TILESET),
|
||||
editing ? createTilesetCombo(draft, true) : createTilesetReadOnlyValue(binding, draft)));
|
||||
return card;
|
||||
}
|
||||
|
||||
private VBox createLayerOverviewPlaceholder() {
|
||||
final VBox overview = new VBox(10);
|
||||
overview.getStyleClass().add("assets-scene-layer-overview");
|
||||
|
||||
final Label title = new Label(Container.i18n().text(I18n.ASSETS_LABEL_LAYER_OVERVIEW));
|
||||
title.getStyleClass().add("assets-scene-layer-overview-title");
|
||||
|
||||
final Region surface = new Region();
|
||||
surface.getStyleClass().add("assets-scene-layer-overview-surface");
|
||||
VBox.setVgrow(surface, Priority.ALWAYS);
|
||||
|
||||
overview.getChildren().addAll(
|
||||
title,
|
||||
surface,
|
||||
AssetDetailsUiSupport.createSectionMessage(Container.i18n().text(I18n.ASSETS_VALUE_LAYER_OVERVIEW_PENDING)));
|
||||
return overview;
|
||||
}
|
||||
|
||||
private Node createLayerFormHeaderActions(int layerIndex, AssetStudioSceneLayerBinding binding, boolean editing) {
|
||||
final HBox actions = new HBox(8);
|
||||
actions.getStyleClass().add("assets-scene-layer-form-actions");
|
||||
if (!editing) {
|
||||
final Button changeButton = createFormActionButton(I18n.FORM_ACTION_CHANGE);
|
||||
changeButton.setDisable(binding == null);
|
||||
changeButton.setOnAction(ignored -> beginEdit(layerIndex, binding));
|
||||
actions.getChildren().add(changeButton);
|
||||
return actions;
|
||||
}
|
||||
|
||||
final Button applyButton = createFormActionButton(I18n.FORM_ACTION_APPLY);
|
||||
applyButton.setOnAction(ignored -> applyEdit(layerIndex, binding));
|
||||
final Button resetButton = createFormActionButton(I18n.FORM_ACTION_RESET);
|
||||
resetButton.setOnAction(ignored -> resetEdit(binding));
|
||||
final Button cancelButton = createFormActionButton(I18n.FORM_ACTION_CANCEL);
|
||||
cancelButton.setOnAction(ignored -> cancelEdit());
|
||||
actions.getChildren().addAll(applyButton, resetButton, cancelButton);
|
||||
return actions;
|
||||
}
|
||||
|
||||
private Node createLayerActions(Path sceneAssetRoot, int layerIndex, LayerDraft draft) {
|
||||
final HBox actions = new HBox(8);
|
||||
actions.setAlignment(Pos.CENTER_LEFT);
|
||||
actions.getStyleClass().add("assets-scene-layer-actions");
|
||||
final boolean enabled = draft != null && draft.enabled();
|
||||
final boolean hasTmx = hasLayerTilemap(sceneAssetRoot, layerIndex);
|
||||
|
||||
final Button generateButton = AssetDetailsUiSupport.createActionButton(Container.i18n().text(I18n.ASSETS_ACTION_GENERATE_TMX));
|
||||
generateButton.getStyleClass().add("assets-scene-layer-action");
|
||||
generateButton.setDisable(!enabled || hasTmx);
|
||||
generateButton.setOnAction(ignored -> generateLayerAction.accept(layerIndex));
|
||||
|
||||
final Button validateButton = AssetDetailsUiSupport.createActionButton(Container.i18n().text(I18n.ASSETS_ACTION_VALIDATE_LAYER));
|
||||
validateButton.getStyleClass().add("assets-scene-layer-action");
|
||||
validateButton.setDisable(!enabled || !hasTmx);
|
||||
validateButton.setOnAction(ignored -> validateLayerAction.accept(layerIndex));
|
||||
|
||||
final Button acceptButton = AssetDetailsUiSupport.createActionButton(Container.i18n().text(I18n.ASSETS_ACTION_ACCEPT_LAYER));
|
||||
acceptButton.getStyleClass().add("assets-scene-layer-action");
|
||||
acceptButton.setDisable(!enabled || !hasTmx);
|
||||
acceptButton.setOnAction(ignored -> acceptLayerAction.accept(layerIndex));
|
||||
|
||||
final Region spacer = new Region();
|
||||
HBox.setHgrow(spacer, Priority.ALWAYS);
|
||||
actions.getChildren().addAll(generateButton, validateButton, acceptButton, spacer);
|
||||
return actions;
|
||||
}
|
||||
|
||||
private Node createLayerSizeEditor(LayerDraft draft) {
|
||||
final HBox editor = new HBox(8);
|
||||
editor.getStyleClass().add("assets-scene-layer-size-editor");
|
||||
|
||||
final TextField widthField = createSizeField(draft.widthText(), draft::setWidthText);
|
||||
final Label separator = new Label("x");
|
||||
separator.getStyleClass().add("assets-scene-layer-size-separator");
|
||||
final TextField heightField = createSizeField(draft.heightText(), draft::setHeightText);
|
||||
|
||||
editor.getChildren().addAll(widthField, separator, heightField);
|
||||
return editor;
|
||||
}
|
||||
|
||||
private TextField createSizeField(String value, java.util.function.Consumer<String> updater) {
|
||||
final TextField textField = new TextField(value);
|
||||
textField.getStyleClass().add("assets-scene-layer-size-field");
|
||||
textField.textProperty().addListener((ignored, oldValue, newValue) -> updater.accept(newValue));
|
||||
return textField;
|
||||
}
|
||||
|
||||
private ComboBox<TilesetOption> createTilesetCombo(LayerDraft draft, boolean editing) {
|
||||
final ComboBox<TilesetOption> combo = new ComboBox<>();
|
||||
combo.setMaxWidth(Double.MAX_VALUE);
|
||||
combo.getStyleClass().add("assets-details-combo");
|
||||
final List<TilesetOption> options = loadTilesetOptions();
|
||||
combo.setItems(FXCollections.observableArrayList(options));
|
||||
combo.setCellFactory(ignored -> new ListCell<>() {
|
||||
@Override
|
||||
protected void updateItem(TilesetOption item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
setText(empty || item == null ? null : item.label());
|
||||
}
|
||||
});
|
||||
combo.setButtonCell(new ListCell<>() {
|
||||
@Override
|
||||
protected void updateItem(TilesetOption item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
setText(empty || item == null ? null : item.label());
|
||||
}
|
||||
});
|
||||
final String currentTileset = draft == null ? "" : draft.tilesetAssetRoot();
|
||||
options.stream()
|
||||
.filter(option -> option.relativeAssetRoot().equals(currentTileset))
|
||||
.findFirst()
|
||||
.ifPresentOrElse(
|
||||
combo.getSelectionModel()::select,
|
||||
() -> combo.getSelectionModel().clearSelection());
|
||||
combo.setDisable(!editing || draft == null);
|
||||
if (draft == null) {
|
||||
combo.setDisable(true);
|
||||
return combo;
|
||||
}
|
||||
combo.valueProperty().addListener((ignored, oldValue, newValue) -> {
|
||||
if (Objects.equals(oldValue, newValue)) {
|
||||
return;
|
||||
}
|
||||
draft.setTilesetAssetRoot(newValue == null ? "" : newValue.relativeAssetRoot());
|
||||
});
|
||||
return combo;
|
||||
}
|
||||
|
||||
private Node createTilesetReadOnlyValue(AssetStudioSceneLayerBinding binding, LayerDraft draft) {
|
||||
final String value = binding == null || draft == null || draft.tilesetAssetRoot().isBlank()
|
||||
? Container.i18n().text(I18n.ASSETS_VALUE_NOT_CONFIGURED)
|
||||
: tilesetPath(draft.tilesetAssetRoot());
|
||||
return new Label(value);
|
||||
}
|
||||
|
||||
private List<TilesetOption> loadTilesetOptions() {
|
||||
try {
|
||||
final var response = Container.packer().workspaceService().listAssets(new ListAssetsRequest(projectReference.toPackerProjectContext()));
|
||||
return response.assets().stream()
|
||||
.filter(asset -> asset.assetFamily() == AssetFamilyCatalog.GLYPH_BANK)
|
||||
.filter(asset -> metadataService.read(asset.identity().assetRoot(), AssetFamilyCatalog.GLYPH_BANK).glyphSpecialization()
|
||||
== p.studio.workspaces.assets.metadata.AssetStudioGlyphSpecialization.TILESET)
|
||||
.map(asset -> {
|
||||
final String relativeAssetRoot = projectReference.rootPath()
|
||||
.resolve("assets")
|
||||
.relativize(asset.identity().assetRoot())
|
||||
.toString()
|
||||
.replace('\\', '/');
|
||||
return new TilesetOption(asset.identity().assetName(), relativeAssetRoot);
|
||||
})
|
||||
.sorted(Comparator.comparing(TilesetOption::label, String.CASE_INSENSITIVE_ORDER))
|
||||
.toList();
|
||||
} catch (RuntimeException exception) {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateLayerBinding(
|
||||
int layerIndex,
|
||||
java.util.function.Function<AssetStudioSceneLayerBinding, AssetStudioSceneLayerBinding> mutator,
|
||||
String successMessage) {
|
||||
if (viewState == null || viewState.selectedAssetDetails() == null || viewState.selectedAssetDetails().sceneBankMetadata() == null) {
|
||||
return;
|
||||
}
|
||||
final AssetStudioSceneBankMetadata metadata = viewState.selectedAssetDetails().sceneBankMetadata();
|
||||
final java.util.List<AssetStudioSceneLayerBinding> updatedBindings = new ArrayList<>();
|
||||
for (AssetStudioSceneLayerBinding binding : metadata.layerBindings()) {
|
||||
if (binding.index() == layerIndex) {
|
||||
updatedBindings.add(mutator.apply(binding));
|
||||
} else {
|
||||
updatedBindings.add(binding);
|
||||
}
|
||||
}
|
||||
final AssetStudioSceneLayerBinding firstBinding = updatedBindings.getFirst();
|
||||
final AssetStudioSceneBankMetadata updatedMetadata = new AssetStudioSceneBankMetadata(
|
||||
firstBinding.width(),
|
||||
firstBinding.height(),
|
||||
metadata.layerCount(),
|
||||
updatedBindings,
|
||||
metadata.supportFile());
|
||||
Container.backgroundTasks().submit(() -> {
|
||||
try {
|
||||
metadataService.writeSceneBankMetadata(viewState.selectedAssetDetails().summary().assetRoot(), updatedMetadata);
|
||||
Platform.runLater(() -> {
|
||||
workspaceBus.publish(new StudioAssetLogEvent("scene-bank-layer", successMessage));
|
||||
workspaceBus.publish(new StudioAssetsRefreshRequestedEvent(viewState.selectedAssetReference()));
|
||||
workspaceBus.publish(new StudioAssetsWorkspaceSelectionRequestedEvent(viewState.selectedAssetReference(), true));
|
||||
});
|
||||
} catch (IOException exception) {
|
||||
Platform.runLater(() -> workspaceBus.publish(
|
||||
new StudioAssetLogEvent("scene-bank-layer", "Unable to update layer " + layerIndex + ": " + exception.getMessage())));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String tilesetPath(AssetStudioSceneLayerBinding binding) {
|
||||
return tilesetPath(binding.tilesetAssetRoot());
|
||||
}
|
||||
|
||||
private String tilesetPath(String tilesetAssetRoot) {
|
||||
if (tilesetAssetRoot.isBlank()) {
|
||||
return "—";
|
||||
}
|
||||
return AssetDetailsUiSupport.projectRelativePath(
|
||||
projectReference,
|
||||
projectReference.rootPath().resolve("assets").resolve(tilesetAssetRoot));
|
||||
}
|
||||
|
||||
private void beginEdit(int layerIndex, AssetStudioSceneLayerBinding binding) {
|
||||
editingLayerIndex = layerIndex;
|
||||
editingDraft = LayerDraft.from(binding);
|
||||
render();
|
||||
}
|
||||
|
||||
private void applyEdit(int layerIndex, AssetStudioSceneLayerBinding binding) {
|
||||
if (binding == null || editingDraft == null || !editingDraft.hasValidDimensions()) {
|
||||
workspaceBus.publish(new StudioAssetLogEvent(
|
||||
"scene-bank-layer",
|
||||
"Layer size must use positive integer values before applying changes."));
|
||||
return;
|
||||
}
|
||||
final LayerDraft draft = editingDraft.copy();
|
||||
editingLayerIndex = null;
|
||||
editingDraft = null;
|
||||
render();
|
||||
updateLayerBinding(layerIndex, current -> new AssetStudioSceneLayerBinding(
|
||||
draft.enabled(),
|
||||
current.index(),
|
||||
current.layerName(),
|
||||
draft.widthValue(),
|
||||
draft.heightValue(),
|
||||
current.tilemap(),
|
||||
draft.tilesetAssetRoot()),
|
||||
"Updated layer " + layerIndex + " configuration.");
|
||||
}
|
||||
|
||||
private void resetEdit(AssetStudioSceneLayerBinding binding) {
|
||||
editingDraft = LayerDraft.from(binding);
|
||||
render();
|
||||
}
|
||||
|
||||
private void cancelEdit() {
|
||||
editingLayerIndex = null;
|
||||
editingDraft = null;
|
||||
render();
|
||||
}
|
||||
|
||||
private Button createFormActionButton(I18n textKey) {
|
||||
final Button button = new Button(Container.i18n().text(textKey));
|
||||
button.getStyleClass().addAll("studio-button", "studio-button-secondary");
|
||||
return button;
|
||||
}
|
||||
|
||||
private boolean hasLayerTilemap(Path sceneAssetRoot, int layerIndex) {
|
||||
if (viewState == null || viewState.selectedAssetDetails() == null || viewState.selectedAssetDetails().sceneBankMetadata() == null) {
|
||||
return false;
|
||||
}
|
||||
return viewState.selectedAssetDetails().sceneBankMetadata().layerBindings().stream()
|
||||
.filter(binding -> binding.index() == layerIndex)
|
||||
.findFirst()
|
||||
.map(binding -> Files.isRegularFile(sceneAssetRoot.resolve(binding.tilemap())))
|
||||
.orElse(false);
|
||||
}
|
||||
|
||||
private record TilesetOption(String assetName, String relativeAssetRoot) {
|
||||
String label() {
|
||||
return assetName + " [" + relativeAssetRoot + "]";
|
||||
}
|
||||
}
|
||||
|
||||
private static final class LayerDraft {
|
||||
private boolean enabled;
|
||||
private String widthText;
|
||||
private String heightText;
|
||||
private String tilesetAssetRoot;
|
||||
|
||||
private LayerDraft(boolean enabled, String widthText, String heightText, String tilesetAssetRoot) {
|
||||
this.enabled = enabled;
|
||||
this.widthText = widthText;
|
||||
this.heightText = heightText;
|
||||
this.tilesetAssetRoot = Objects.requireNonNullElse(tilesetAssetRoot, "").trim();
|
||||
}
|
||||
|
||||
static LayerDraft from(AssetStudioSceneLayerBinding binding) {
|
||||
if (binding == null) {
|
||||
return new LayerDraft(false, "16", "16", "");
|
||||
}
|
||||
return new LayerDraft(
|
||||
binding.enabled(),
|
||||
Integer.toString(binding.width()),
|
||||
Integer.toString(binding.height()),
|
||||
binding.tilesetAssetRoot());
|
||||
}
|
||||
|
||||
LayerDraft copy() {
|
||||
return new LayerDraft(enabled, widthText, heightText, tilesetAssetRoot);
|
||||
}
|
||||
|
||||
boolean enabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
String widthText() {
|
||||
return widthText;
|
||||
}
|
||||
|
||||
void setWidthText(String widthText) {
|
||||
this.widthText = Objects.requireNonNullElse(widthText, "").trim();
|
||||
}
|
||||
|
||||
String heightText() {
|
||||
return heightText;
|
||||
}
|
||||
|
||||
void setHeightText(String heightText) {
|
||||
this.heightText = Objects.requireNonNullElse(heightText, "").trim();
|
||||
}
|
||||
|
||||
String tilesetAssetRoot() {
|
||||
return tilesetAssetRoot;
|
||||
}
|
||||
|
||||
void setTilesetAssetRoot(String tilesetAssetRoot) {
|
||||
this.tilesetAssetRoot = Objects.requireNonNullElse(tilesetAssetRoot, "").trim();
|
||||
}
|
||||
|
||||
boolean hasValidDimensions() {
|
||||
return parsePositiveInt(widthText) > 0 && parsePositiveInt(heightText) > 0;
|
||||
}
|
||||
|
||||
int widthValue() {
|
||||
return parsePositiveInt(widthText);
|
||||
}
|
||||
|
||||
int heightValue() {
|
||||
return parsePositiveInt(heightText);
|
||||
}
|
||||
|
||||
private static int parsePositiveInt(String value) {
|
||||
try {
|
||||
return Integer.parseInt(Objects.requireNonNullElse(value, "").trim());
|
||||
} catch (NumberFormatException exception) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+250
@@ -0,0 +1,250 @@
|
||||
package p.studio.workspaces.assets.details.schema;
|
||||
|
||||
import p.packer.messages.assets.AssetFamilyCatalog;
|
||||
import p.studio.workspaces.assets.messages.AssetWorkspaceAssetDetails;
|
||||
import p.studio.workspaces.assets.messages.AssetWorkspaceBankCompositionFile;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioGlyphMaterialArtifactBinding;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioGlyphMaterialMetadata;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioGlyphMaterialPalette;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioGlyphMaterialSchema;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioGlyphMaterialSchemaStatus;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public final class AssetDetailsColorSchemaCoordinator {
|
||||
private AssetWorkspaceAssetDetails details;
|
||||
private AssetStudioGlyphMaterialMetadata localMaterialMetadata;
|
||||
|
||||
public void replaceDetails(AssetWorkspaceAssetDetails details) {
|
||||
this.details = details;
|
||||
this.localMaterialMetadata = details == null ? null : details.glyphMaterialMetadata();
|
||||
}
|
||||
|
||||
public void replaceMaterialMetadata(AssetStudioGlyphMaterialMetadata metadata) {
|
||||
this.localMaterialMetadata = Objects.requireNonNull(metadata, "metadata");
|
||||
}
|
||||
|
||||
public boolean ready() {
|
||||
return details != null && details.summary().assetFamily() == AssetFamilyCatalog.GLYPH_BANK;
|
||||
}
|
||||
|
||||
public AssetStudioGlyphMaterialMetadata metadata() {
|
||||
if (!ready() || localMaterialMetadata == null) {
|
||||
return new AssetStudioGlyphMaterialMetadata(List.of(), List.of(), null);
|
||||
}
|
||||
return localMaterialMetadata;
|
||||
}
|
||||
|
||||
public List<AssetStudioGlyphMaterialSchema> schemas() {
|
||||
return metadata().schemas();
|
||||
}
|
||||
|
||||
public List<AssetWorkspaceBankCompositionFile> selectedTiles() {
|
||||
if (!ready()) {
|
||||
return List.of();
|
||||
}
|
||||
return details.bankComposition().selectedFiles().stream()
|
||||
.filter(AssetDetailsColorSchemaCoordinator::supportsSchemaAuthoring)
|
||||
.filter(file -> artifactId(file) != null)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public List<AssetWorkspaceBankCompositionFile> availableTilesForCreate() {
|
||||
final Set<String> reservedArtifactIds = new HashSet<>();
|
||||
for (AssetStudioGlyphMaterialSchema schema : schemas()) {
|
||||
schema.artifactBindings().forEach(binding -> reservedArtifactIds.add(binding.artifactId()));
|
||||
}
|
||||
return selectedTiles().stream()
|
||||
.filter(file -> !reservedArtifactIds.contains(artifactId(file)))
|
||||
.toList();
|
||||
}
|
||||
|
||||
public List<AssetWorkspaceBankCompositionFile> availableTilesForEdit(String schemaId) {
|
||||
final AssetStudioGlyphMaterialSchema schema = findSchema(schemaId).orElse(null);
|
||||
if (schema == null) {
|
||||
return availableTilesForCreate();
|
||||
}
|
||||
final Set<String> current = schema.artifactBindings().stream()
|
||||
.map(AssetStudioGlyphMaterialArtifactBinding::artifactId)
|
||||
.collect(java.util.stream.Collectors.toCollection(LinkedHashSet::new));
|
||||
final Set<String> reservedElsewhere = new HashSet<>();
|
||||
for (AssetStudioGlyphMaterialSchema candidate : schemas()) {
|
||||
if (candidate.schemaId().equals(schemaId)) {
|
||||
continue;
|
||||
}
|
||||
candidate.artifactBindings().forEach(binding -> reservedElsewhere.add(binding.artifactId()));
|
||||
}
|
||||
return selectedTiles().stream()
|
||||
.filter(file -> current.contains(artifactId(file)) || !reservedElsewhere.contains(artifactId(file)))
|
||||
.toList();
|
||||
}
|
||||
|
||||
public boolean canRemove(String schemaId) {
|
||||
return metadata().palettes().stream().noneMatch(palette -> palette.schemaId().equals(schemaId));
|
||||
}
|
||||
|
||||
public Optional<AssetStudioGlyphMaterialSchema> findSchema(String schemaId) {
|
||||
return schemas().stream().filter(schema -> schema.schemaId().equals(schemaId)).findFirst();
|
||||
}
|
||||
|
||||
public AssetStudioGlyphMaterialMetadata upsertSchema(
|
||||
String schemaId,
|
||||
List<AssetWorkspaceBankCompositionFile> assignedTiles,
|
||||
List<String> orderedColors) {
|
||||
final AssetStudioGlyphMaterialMetadata current = metadata();
|
||||
final AssetStudioGlyphMaterialSchema existing = current.findSchema(schemaId).orElse(null);
|
||||
final AssetStudioGlyphMaterialSchema next = buildSchema(schemaId, existing, assignedTiles, orderedColors);
|
||||
final List<AssetStudioGlyphMaterialSchema> schemas = new ArrayList<>();
|
||||
boolean replaced = false;
|
||||
for (AssetStudioGlyphMaterialSchema schema : current.schemas()) {
|
||||
if (schema.schemaId().equals(schemaId)) {
|
||||
schemas.add(next);
|
||||
replaced = true;
|
||||
} else {
|
||||
schemas.add(schema);
|
||||
}
|
||||
}
|
||||
if (!replaced) {
|
||||
schemas.add(next);
|
||||
}
|
||||
schemas.sort(Comparator.comparing(AssetStudioGlyphMaterialSchema::schemaId, String.CASE_INSENSITIVE_ORDER));
|
||||
return new AssetStudioGlyphMaterialMetadata(schemas, current.palettes(), current.supportFile());
|
||||
}
|
||||
|
||||
public AssetStudioGlyphMaterialMetadata removeSchema(String schemaId) {
|
||||
if (!canRemove(schemaId)) {
|
||||
throw new IllegalStateException("Schema is still referenced by one or more palettes.");
|
||||
}
|
||||
final AssetStudioGlyphMaterialMetadata current = metadata();
|
||||
final List<AssetStudioGlyphMaterialSchema> schemas = current.schemas().stream()
|
||||
.filter(schema -> !schema.schemaId().equals(schemaId))
|
||||
.toList();
|
||||
return new AssetStudioGlyphMaterialMetadata(schemas, current.palettes(), current.supportFile());
|
||||
}
|
||||
|
||||
public String nextSchemaId() {
|
||||
int next = 1;
|
||||
final Set<String> ids = schemas().stream().map(AssetStudioGlyphMaterialSchema::schemaId).collect(java.util.stream.Collectors.toSet());
|
||||
while (ids.contains("schema-" + next)) {
|
||||
next += 1;
|
||||
}
|
||||
return "schema-" + next;
|
||||
}
|
||||
|
||||
public int unassignedTileCount() {
|
||||
return availableTilesForCreate().size();
|
||||
}
|
||||
|
||||
public static AssetStudioGlyphMaterialSchemaStatus effectiveStatus(
|
||||
AssetStudioGlyphMaterialSchema schema,
|
||||
List<AssetWorkspaceBankCompositionFile> selectedTiles) {
|
||||
if (schema.status() == AssetStudioGlyphMaterialSchemaStatus.INCONSISTENT) {
|
||||
return AssetStudioGlyphMaterialSchemaStatus.INCONSISTENT;
|
||||
}
|
||||
final Map<String, AssetWorkspaceBankCompositionFile> selectedByArtifactId = new HashMap<>();
|
||||
for (AssetWorkspaceBankCompositionFile tile : selectedTiles) {
|
||||
final String artifactId = artifactId(tile);
|
||||
if (artifactId != null) {
|
||||
selectedByArtifactId.put(artifactId, tile);
|
||||
}
|
||||
}
|
||||
for (AssetStudioGlyphMaterialArtifactBinding binding : schema.artifactBindings()) {
|
||||
final AssetWorkspaceBankCompositionFile selectedTile = selectedByArtifactId.get(binding.artifactId());
|
||||
if (selectedTile == null || !Objects.equals(binding.fingerprint(), fingerprint(selectedTile))) {
|
||||
return AssetStudioGlyphMaterialSchemaStatus.INCONSISTENT;
|
||||
}
|
||||
}
|
||||
return AssetStudioGlyphMaterialSchemaStatus.OK;
|
||||
}
|
||||
|
||||
private AssetStudioGlyphMaterialSchema buildSchema(
|
||||
String schemaId,
|
||||
AssetStudioGlyphMaterialSchema existing,
|
||||
List<AssetWorkspaceBankCompositionFile> assignedTiles,
|
||||
List<String> orderedColors) {
|
||||
final Map<Integer, String> materialIndices = new LinkedHashMap<>();
|
||||
for (int index = 0; index < orderedColors.size(); index += 1) {
|
||||
materialIndices.put(index + 1, normalizeHtmlColor(orderedColors.get(index)));
|
||||
}
|
||||
final List<AssetStudioGlyphMaterialArtifactBinding> bindings = assignedTiles.stream()
|
||||
.map(file -> new AssetStudioGlyphMaterialArtifactBinding(artifactId(file), fingerprint(file)))
|
||||
.toList();
|
||||
final boolean unchanged = existing != null
|
||||
&& existing.materialIndices().equals(materialIndices)
|
||||
&& existing.artifactBindings().equals(bindings);
|
||||
final int version = existing == null
|
||||
? 1
|
||||
: unchanged ? existing.version() : existing.version() + 1;
|
||||
final AssetStudioGlyphMaterialSchemaStatus status = existing == null || !unchanged
|
||||
? AssetStudioGlyphMaterialSchemaStatus.OK
|
||||
: existing.status();
|
||||
return new AssetStudioGlyphMaterialSchema(schemaId, status, version, materialIndices, bindings);
|
||||
}
|
||||
|
||||
static boolean supportsSchemaAuthoring(AssetWorkspaceBankCompositionFile file) {
|
||||
return file != null
|
||||
&& artifactId(file) != null
|
||||
&& fingerprint(file) != null;
|
||||
}
|
||||
|
||||
static String artifactId(AssetWorkspaceBankCompositionFile file) {
|
||||
if (file == null) {
|
||||
return null;
|
||||
}
|
||||
final Object artifactId = file.metadata().get("artifactId");
|
||||
if (artifactId instanceof String value && !value.isBlank()) {
|
||||
return value.trim();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static String fingerprint(AssetWorkspaceBankCompositionFile file) {
|
||||
if (file == null) {
|
||||
return null;
|
||||
}
|
||||
if (file.fingerprint() != null && !file.fingerprint().isBlank()) {
|
||||
return file.fingerprint().trim();
|
||||
}
|
||||
final Object selectedFingerprint = file.metadata().get("selectedFingerprint");
|
||||
if (selectedFingerprint instanceof String value && !value.isBlank()) {
|
||||
return value.trim();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static List<String> tileColors(AssetWorkspaceBankCompositionFile file) {
|
||||
final Map<String, Object> palette = nestedMap(file.metadata(), "palette");
|
||||
if (palette == null) {
|
||||
return List.of();
|
||||
}
|
||||
final Object originalColors = palette.get("originalArgb8888");
|
||||
if (!(originalColors instanceof Iterable<?> iterable)) {
|
||||
return List.of();
|
||||
}
|
||||
final List<String> colors = new ArrayList<>();
|
||||
for (Object item : iterable) {
|
||||
if (!(item instanceof Number number)) {
|
||||
continue;
|
||||
}
|
||||
colors.add(String.format(
|
||||
"#%02X%02X%02X",
|
||||
(number.intValue() >> 16) & 0xFF,
|
||||
(number.intValue() >> 8) & 0xFF,
|
||||
number.intValue() & 0xFF));
|
||||
}
|
||||
return List.copyOf(colors);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Map<String, Object> nestedMap(Map<String, Object> metadata, String key) {
|
||||
final Object value = metadata.get(key);
|
||||
if (value instanceof Map<?, ?> nested) {
|
||||
return (Map<String, Object>) nested;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String normalizeHtmlColor(String color) {
|
||||
return Objects.requireNonNull(color, "color").trim().toUpperCase();
|
||||
}
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
package p.studio.workspaces.assets.details.schema;
|
||||
|
||||
import p.studio.workspaces.assets.messages.AssetWorkspaceBankCompositionFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
record AssetDetailsColorSchemaDraft(
|
||||
String schemaId,
|
||||
boolean existingSchema,
|
||||
boolean removeRequested,
|
||||
List<AssetWorkspaceBankCompositionFile> availableTiles,
|
||||
List<AssetWorkspaceBankCompositionFile> assignedTiles,
|
||||
List<String> preferredColors,
|
||||
boolean deriveColorsFromTiles) {
|
||||
|
||||
AssetDetailsColorSchemaDraft {
|
||||
availableTiles = List.copyOf(availableTiles);
|
||||
assignedTiles = List.copyOf(assignedTiles);
|
||||
preferredColors = normalize(preferredColors);
|
||||
}
|
||||
|
||||
static AssetDetailsColorSchemaDraft noSelection() {
|
||||
return new AssetDetailsColorSchemaDraft(null, false, false, List.of(), List.of(), List.of(), false);
|
||||
}
|
||||
|
||||
boolean selected() {
|
||||
return schemaId != null && !schemaId.isBlank();
|
||||
}
|
||||
|
||||
AssetDetailsColorSchemaDraft moveToAssigned(List<AssetWorkspaceBankCompositionFile> files) {
|
||||
final List<AssetWorkspaceBankCompositionFile> nextAvailable = new ArrayList<>(availableTiles);
|
||||
final List<AssetWorkspaceBankCompositionFile> nextAssigned = new ArrayList<>(assignedTiles);
|
||||
for (AssetWorkspaceBankCompositionFile file : files) {
|
||||
if (nextAvailable.remove(file) && !nextAssigned.contains(file)) {
|
||||
nextAssigned.add(file);
|
||||
}
|
||||
}
|
||||
return withTiles(nextAvailable, nextAssigned);
|
||||
}
|
||||
|
||||
AssetDetailsColorSchemaDraft moveToAvailable(List<AssetWorkspaceBankCompositionFile> files) {
|
||||
final List<AssetWorkspaceBankCompositionFile> nextAvailable = new ArrayList<>(availableTiles);
|
||||
final List<AssetWorkspaceBankCompositionFile> nextAssigned = new ArrayList<>(assignedTiles);
|
||||
for (AssetWorkspaceBankCompositionFile file : files) {
|
||||
if (nextAssigned.remove(file) && !nextAvailable.contains(file)) {
|
||||
nextAvailable.add(file);
|
||||
}
|
||||
}
|
||||
return withTiles(nextAvailable, nextAssigned);
|
||||
}
|
||||
|
||||
AssetDetailsColorSchemaDraft moveAssignedUp(int index) {
|
||||
if (index <= 0 || index >= assignedTiles.size()) {
|
||||
return this;
|
||||
}
|
||||
final List<AssetWorkspaceBankCompositionFile> nextAssigned = new ArrayList<>(assignedTiles);
|
||||
final AssetWorkspaceBankCompositionFile file = nextAssigned.remove(index);
|
||||
nextAssigned.add(index - 1, file);
|
||||
return withTiles(availableTiles, nextAssigned);
|
||||
}
|
||||
|
||||
AssetDetailsColorSchemaDraft moveAssignedDown(int index) {
|
||||
if (index < 0 || index >= assignedTiles.size() - 1) {
|
||||
return this;
|
||||
}
|
||||
final List<AssetWorkspaceBankCompositionFile> nextAssigned = new ArrayList<>(assignedTiles);
|
||||
final AssetWorkspaceBankCompositionFile file = nextAssigned.remove(index);
|
||||
nextAssigned.add(index + 1, file);
|
||||
return withTiles(availableTiles, nextAssigned);
|
||||
}
|
||||
|
||||
AssetDetailsColorSchemaDraft markForRemoval() {
|
||||
if (!selected()) {
|
||||
return this;
|
||||
}
|
||||
return new AssetDetailsColorSchemaDraft(schemaId, existingSchema, true, availableTiles, assignedTiles, preferredColors, deriveColorsFromTiles);
|
||||
}
|
||||
|
||||
AssetDetailsColorSchemaDraft asUpdateDraft() {
|
||||
return new AssetDetailsColorSchemaDraft(schemaId, existingSchema, false, availableTiles, assignedTiles, orderedColors(), true);
|
||||
}
|
||||
|
||||
List<String> orderedColors() {
|
||||
if (!deriveColorsFromTiles) {
|
||||
return preferredColors;
|
||||
}
|
||||
final LinkedHashSet<String> active = new LinkedHashSet<>();
|
||||
for (AssetWorkspaceBankCompositionFile tile : assignedTiles) {
|
||||
AssetDetailsColorSchemaCoordinator.tileColors(tile).stream()
|
||||
.map(AssetDetailsColorSchemaDraft::normalize)
|
||||
.forEach(active::add);
|
||||
}
|
||||
final List<String> ordered = new ArrayList<>();
|
||||
for (String preferredColor : preferredColors) {
|
||||
if (active.contains(preferredColor) && !ordered.contains(preferredColor)) {
|
||||
ordered.add(preferredColor);
|
||||
}
|
||||
}
|
||||
for (String color : active) {
|
||||
if (!ordered.contains(color)) {
|
||||
ordered.add(color);
|
||||
}
|
||||
}
|
||||
return List.copyOf(ordered);
|
||||
}
|
||||
|
||||
private AssetDetailsColorSchemaDraft withTiles(
|
||||
List<AssetWorkspaceBankCompositionFile> nextAvailable,
|
||||
List<AssetWorkspaceBankCompositionFile> nextAssigned) {
|
||||
return new AssetDetailsColorSchemaDraft(schemaId, existingSchema, false, nextAvailable, nextAssigned, orderedColors(), true);
|
||||
}
|
||||
|
||||
private static List<String> normalize(List<String> colors) {
|
||||
final List<String> normalized = new ArrayList<>();
|
||||
for (String color : colors) {
|
||||
if (color == null || color.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
normalized.add(normalize(color));
|
||||
}
|
||||
return List.copyOf(normalized);
|
||||
}
|
||||
|
||||
private static String normalize(String color) {
|
||||
return color.trim().toUpperCase();
|
||||
}
|
||||
}
|
||||
+521
@@ -0,0 +1,521 @@
|
||||
package p.studio.workspaces.assets.details.schema;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ListCell;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.Container;
|
||||
import p.studio.controls.banks.StudioDualListView;
|
||||
import p.studio.controls.forms.StudioFormEditScopeChangedEvent;
|
||||
import p.studio.controls.forms.StudioFormMode;
|
||||
import p.studio.controls.forms.StudioFormSection;
|
||||
import p.studio.controls.forms.StudioFormSession;
|
||||
import p.studio.lsp.events.StudioWorkspaceEventBus;
|
||||
import p.studio.projects.ProjectReference;
|
||||
import p.studio.utilities.i18n.I18n;
|
||||
import p.studio.workspaces.assets.messages.AssetWorkspaceBankCompositionFile;
|
||||
import p.studio.workspaces.assets.messages.AssetWorkspaceDetailsViewState;
|
||||
import p.studio.workspaces.assets.messages.events.StudioAssetLogEvent;
|
||||
import p.studio.workspaces.assets.messages.events.StudioAssetsDetailsViewStateChangedEvent;
|
||||
import p.studio.workspaces.assets.messages.events.StudioGlyphMaterialMetadataChangedEvent;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioGlyphMaterialArtifactBinding;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioGlyphMaterialMetadata;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioGlyphMaterialSchema;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioGlyphMaterialSchemaStatus;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioMetadataService;
|
||||
import p.studio.workspaces.framework.StudioSubscriptionBag;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public final class AssetDetailsColorSchemaGroupsControl extends StudioFormSection {
|
||||
private static final String SECTION_ID = "asset-details.color-schema-groups";
|
||||
|
||||
private final StudioWorkspaceEventBus workspaceBus;
|
||||
private final StudioSubscriptionBag subscriptions = new StudioSubscriptionBag();
|
||||
private final AssetStudioMetadataService metadataService = new AssetStudioMetadataService();
|
||||
private final AssetDetailsColorSchemaCoordinator coordinator = new AssetDetailsColorSchemaCoordinator();
|
||||
private final ListView<SchemaListItem> schemaListView = new ListView<>();
|
||||
private final SchemaTileDualListView tileDualListView = new SchemaTileDualListView();
|
||||
private final VBox schemaActions = new VBox(6);
|
||||
private final HBox schemaListPane = new HBox(8, schemaActions, schemaListView);
|
||||
private final HBox paletteStrip = new HBox(4);
|
||||
private final Label summaryLabel = new Label();
|
||||
private final Label schemaTitleLabel = new Label();
|
||||
private final Label paletteCounterLabel = new Label();
|
||||
private final Label warningLabel = new Label();
|
||||
private final VBox editorPane = new VBox(10);
|
||||
private final HBox body = new HBox(16);
|
||||
private final VBox content = new VBox(12, body, summaryLabel);
|
||||
|
||||
private AssetWorkspaceDetailsViewState viewState;
|
||||
private StudioFormSession<AssetDetailsColorSchemaDraft> formSession;
|
||||
private String selectedSchemaId;
|
||||
private boolean selectingSchema;
|
||||
|
||||
public AssetDetailsColorSchemaGroupsControl(ProjectReference projectReference, StudioWorkspaceEventBus workspaceBus) {
|
||||
Objects.requireNonNull(projectReference, "projectReference");
|
||||
this.workspaceBus = Objects.requireNonNull(workspaceBus, "workspaceBus");
|
||||
schemaListView.getStyleClass().add("assets-details-color-schema-list");
|
||||
schemaListView.setCellFactory(ignored -> createSchemaCell());
|
||||
schemaListView.getSelectionModel().selectedItemProperty().addListener((ignored, previous, current) -> {
|
||||
if (selectingSchema) {
|
||||
return;
|
||||
}
|
||||
selectedSchemaId = current == null ? null : current.schemaId();
|
||||
if (formMode() == StudioFormMode.EDITING) {
|
||||
formSession.setDraft(selectedSchemaId == null
|
||||
? AssetDetailsColorSchemaDraft.noSelection()
|
||||
: sourceDraft(selectedSchemaId).asUpdateDraft());
|
||||
} else {
|
||||
replaceFormSource();
|
||||
}
|
||||
renderSection();
|
||||
});
|
||||
schemaActions.getStyleClass().add("assets-details-color-schema-toolbar");
|
||||
schemaListPane.getStyleClass().add("assets-details-list-with-actions");
|
||||
content.getStyleClass().add("assets-details-color-schema-content");
|
||||
body.getStyleClass().add("assets-details-color-schema-body");
|
||||
paletteStrip.getStyleClass().add("assets-details-color-schema-strip");
|
||||
schemaTitleLabel.getStyleClass().add("assets-details-color-schema-title");
|
||||
paletteCounterLabel.getStyleClass().add("assets-details-color-schema-summary");
|
||||
summaryLabel.getStyleClass().add("assets-details-color-schema-summary");
|
||||
warningLabel.getStyleClass().add("assets-details-color-schema-warning");
|
||||
HBox.setHgrow(schemaListPane, Priority.ALWAYS);
|
||||
HBox.setHgrow(schemaListView, Priority.ALWAYS);
|
||||
HBox.setHgrow(editorPane, Priority.ALWAYS);
|
||||
schemaListView.setMaxWidth(Double.MAX_VALUE);
|
||||
editorPane.setMaxWidth(Double.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribe() {
|
||||
subscriptions.add(workspaceBus.subscribe(StudioAssetsDetailsViewStateChangedEvent.class, event -> {
|
||||
viewState = event.viewState();
|
||||
coordinator.replaceDetails(viewState == null ? null : viewState.selectedAssetDetails());
|
||||
normalizeSelectedSchema();
|
||||
replaceFormSource();
|
||||
if (viewState == null || viewState.selectedAssetReference() == null) {
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
}
|
||||
renderSection();
|
||||
}));
|
||||
subscriptions.add(workspaceBus.subscribe(StudioFormEditScopeChangedEvent.class,
|
||||
event -> handleEditScopeChanged(event, currentScopeKey())));
|
||||
subscriptions.add(workspaceBus.subscribe(StudioGlyphMaterialMetadataChangedEvent.class, event -> {
|
||||
if (viewState == null || !Objects.equals(viewState.selectedAssetReference(), event.assetReference())) {
|
||||
return;
|
||||
}
|
||||
coordinator.replaceMaterialMetadata(event.metadata());
|
||||
if (formMode() != StudioFormMode.EDITING) {
|
||||
replaceFormSource();
|
||||
}
|
||||
renderSection();
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribe() {
|
||||
subscriptions.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderSection() {
|
||||
if (viewState == null || viewState.selectedAssetDetails() == null || !coordinator.ready()) {
|
||||
formSession = null;
|
||||
clearRenderedSection();
|
||||
return;
|
||||
}
|
||||
if (formSession == null) {
|
||||
replaceFormSource();
|
||||
}
|
||||
|
||||
final AssetDetailsColorSchemaDraft draft = formSession.draft();
|
||||
renderSchemaList();
|
||||
renderSchemaActions(draft);
|
||||
renderEditor(draft);
|
||||
summaryLabel.setText(Container.i18n().format(
|
||||
I18n.ASSETS_COLOR_SCHEMA_SUMMARY,
|
||||
coordinator.schemas().size(),
|
||||
coordinator.unassignedTileCount()));
|
||||
body.getChildren().setAll(schemaListPane, editorPane);
|
||||
renderFormSection(content);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String sectionTitle() {
|
||||
return Container.i18n().text(I18n.ASSETS_SECTION_COLOR_SCHEMA_GROUPS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StudioFormMode formMode() {
|
||||
return formSession == null ? StudioFormMode.READ_ONLY : formSession.mode();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isDirty() {
|
||||
return formSession != null && formSession.isDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void beginEdit() {
|
||||
if (formSession == null) {
|
||||
replaceFormSource();
|
||||
}
|
||||
selectedSchemaId = null;
|
||||
formSession.replaceSource(AssetDetailsColorSchemaDraft.noSelection());
|
||||
formSession.beginEdit();
|
||||
publishEditScope(workspaceBus, currentScopeKey(), SECTION_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void apply() {
|
||||
if (viewState == null || viewState.selectedAssetDetails() == null || viewState.selectedAssetReference() == null || formSession == null) {
|
||||
return;
|
||||
}
|
||||
final AssetDetailsColorSchemaDraft draft = formSession.draft();
|
||||
if (!draft.selected()) {
|
||||
workspaceBus.publish(new StudioAssetLogEvent("color-schema-groups", "Apply failed: select or create a schema first."));
|
||||
return;
|
||||
}
|
||||
if (!draft.removeRequested()) {
|
||||
final List<String> orderedColors = draft.orderedColors();
|
||||
if (draft.assignedTiles().isEmpty() || orderedColors.isEmpty()) {
|
||||
workspaceBus.publish(new StudioAssetLogEvent("color-schema-groups", "Apply failed: schema must contain at least one tile."));
|
||||
return;
|
||||
}
|
||||
if (orderedColors.size() > 15) {
|
||||
workspaceBus.publish(new StudioAssetLogEvent(
|
||||
"color-schema-groups",
|
||||
Container.i18n().text(I18n.ASSETS_COLOR_SCHEMA_DIALOG_TOO_MANY_COLORS)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final var assetDetails = viewState.selectedAssetDetails();
|
||||
final var assetReference = viewState.selectedAssetReference();
|
||||
Container.backgroundTasks().submit(() -> {
|
||||
try {
|
||||
final AssetStudioGlyphMaterialMetadata metadata = draft.removeRequested()
|
||||
? coordinator.removeSchema(draft.schemaId())
|
||||
: coordinator.upsertSchema(draft.schemaId(), draft.assignedTiles(), draft.orderedColors());
|
||||
metadataService.writeGlyphMaterialMetadata(assetDetails.summary().assetRoot(), metadata);
|
||||
Platform.runLater(() -> {
|
||||
formSession.apply();
|
||||
selectedSchemaId = draft.removeRequested() ? null : draft.schemaId();
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
workspaceBus.publish(new StudioAssetLogEvent(
|
||||
"color-schema-groups",
|
||||
draft.removeRequested() ? "Schema removed: " + draft.schemaId() : "Schema saved: " + draft.schemaId()));
|
||||
workspaceBus.publish(new StudioGlyphMaterialMetadataChangedEvent(assetReference, metadata));
|
||||
renderSection();
|
||||
});
|
||||
} catch (IOException | RuntimeException exception) {
|
||||
Platform.runLater(() -> workspaceBus.publish(new StudioAssetLogEvent(
|
||||
"color-schema-groups",
|
||||
"Unable to save schema: " + Objects.requireNonNullElse(exception.getMessage(), "unknown error"))));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reset() {
|
||||
if (formSession == null) {
|
||||
return;
|
||||
}
|
||||
formSession.resetDraft();
|
||||
selectedSchemaId = formSession.draft().selected() ? formSession.draft().schemaId() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cancel() {
|
||||
if (formSession == null) {
|
||||
return;
|
||||
}
|
||||
formSession.cancelEdit();
|
||||
selectedSchemaId = formSession.draft().selected() ? formSession.draft().schemaId() : null;
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String sectionStyleClass() {
|
||||
return "assets-details-color-schema-section";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String formSectionId() {
|
||||
return SECTION_ID;
|
||||
}
|
||||
|
||||
private void renderSchemaList() {
|
||||
selectingSchema = true;
|
||||
schemaListView.getItems().setAll(schemaListItems());
|
||||
schemaListView.setDisable(false);
|
||||
if (selectedSchemaId != null) {
|
||||
schemaListView.getItems().stream()
|
||||
.filter(schema -> schema.schemaId().equals(selectedSchemaId))
|
||||
.findFirst()
|
||||
.ifPresentOrElse(
|
||||
schema -> schemaListView.getSelectionModel().select(schema),
|
||||
() -> schemaListView.getSelectionModel().clearSelection());
|
||||
} else {
|
||||
schemaListView.getSelectionModel().clearSelection();
|
||||
}
|
||||
selectingSchema = false;
|
||||
}
|
||||
|
||||
private void renderSchemaActions(AssetDetailsColorSchemaDraft draft) {
|
||||
final Button newButton = new Button("+");
|
||||
newButton.getStyleClass().addAll("studio-button", "studio-button-secondary", "assets-details-mini-action-button");
|
||||
newButton.setDisable(formMode() != StudioFormMode.EDITING);
|
||||
newButton.setOnAction(ignored -> {
|
||||
selectedSchemaId = coordinator.nextSchemaId();
|
||||
formSession.setDraft(sourceDraft(selectedSchemaId).asUpdateDraft());
|
||||
rerenderPreservingScrollPosition();
|
||||
});
|
||||
|
||||
final Button removeButton = new Button("-");
|
||||
removeButton.getStyleClass().addAll("studio-button", "studio-button-secondary", "assets-details-mini-action-button");
|
||||
removeButton.setDisable(formMode() != StudioFormMode.EDITING || !draft.selected() || (draft.existingSchema() && !coordinator.canRemove(draft.schemaId())));
|
||||
removeButton.setOnAction(ignored -> {
|
||||
if (draft.existingSchema()) {
|
||||
formSession.updateDraft(AssetDetailsColorSchemaDraft::markForRemoval);
|
||||
} else {
|
||||
selectedSchemaId = null;
|
||||
formSession.setDraft(AssetDetailsColorSchemaDraft.noSelection());
|
||||
}
|
||||
rerenderPreservingScrollPosition();
|
||||
});
|
||||
if (draft.existingSchema() && !coordinator.canRemove(draft.schemaId())) {
|
||||
removeButton.setTooltip(new javafx.scene.control.Tooltip(
|
||||
Container.i18n().format(I18n.ASSETS_COLOR_SCHEMA_REMOVE_BLOCKED, draft.schemaId())));
|
||||
}
|
||||
|
||||
schemaActions.getChildren().setAll(newButton, removeButton);
|
||||
}
|
||||
|
||||
private void renderEditor(AssetDetailsColorSchemaDraft draft) {
|
||||
editorPane.getChildren().clear();
|
||||
if (!draft.selected()) {
|
||||
tileDualListView.setLeftItems(List.of());
|
||||
tileDualListView.setRightItems(List.of());
|
||||
tileDualListView.setInteractionEnabled(false);
|
||||
paletteStrip.getChildren().clear();
|
||||
paletteCounterLabel.setText(Container.i18n().format(I18n.ASSETS_COLOR_SCHEMA_DIALOG_COLOR_COUNT, 0));
|
||||
editorPane.getChildren().addAll(
|
||||
emptyMessage("Select a schema or create a new one to edit its tile group."),
|
||||
tileDualListView,
|
||||
paletteCounterLabel,
|
||||
paletteStrip);
|
||||
return;
|
||||
}
|
||||
if (draft.removeRequested()) {
|
||||
editorPane.getChildren().add(emptyMessage("Schema " + draft.schemaId() + " will be removed when you apply this form."));
|
||||
return;
|
||||
}
|
||||
|
||||
final List<String> orderedColors = draft.orderedColors();
|
||||
schemaTitleLabel.setText(draft.schemaId() + (draft.existingSchema() ? "" : " (new)"));
|
||||
paletteCounterLabel.setText(Container.i18n().format(I18n.ASSETS_COLOR_SCHEMA_DIALOG_COLOR_COUNT, orderedColors.size()));
|
||||
warningLabel.setText(orderedColors.size() > 15
|
||||
? Container.i18n().text(I18n.ASSETS_COLOR_SCHEMA_DIALOG_TOO_MANY_COLORS)
|
||||
: "");
|
||||
paletteStrip.getChildren().setAll(orderedColors.stream().map(this::swatch).toList());
|
||||
|
||||
tileDualListView.setLeftItems(draft.availableTiles());
|
||||
tileDualListView.setRightItems(draft.assignedTiles());
|
||||
tileDualListView.setInteractionEnabled(formMode() == StudioFormMode.EDITING && draft.selected());
|
||||
tileDualListView.setMoveToRightAllowed(true);
|
||||
tileDualListView.setOnMoveToRight(items -> updateDraft(current -> current.moveToAssigned(items)));
|
||||
tileDualListView.setOnMoveToLeft(items -> updateDraft(current -> current.moveToAvailable(items)));
|
||||
tileDualListView.setOnMoveUp(index -> updateDraft(current -> current.moveAssignedUp(index)));
|
||||
tileDualListView.setOnMoveDown(index -> updateDraft(current -> current.moveAssignedDown(index)));
|
||||
|
||||
editorPane.getChildren().addAll(schemaTitleLabel, tileDualListView, paletteCounterLabel, paletteStrip, warningLabel);
|
||||
VBox.setVgrow(tileDualListView, Priority.ALWAYS);
|
||||
}
|
||||
|
||||
private void updateDraft(java.util.function.UnaryOperator<AssetDetailsColorSchemaDraft> update) {
|
||||
if (formMode() != StudioFormMode.EDITING || formSession == null) {
|
||||
return;
|
||||
}
|
||||
formSession.updateDraft(update);
|
||||
rerenderPreservingScrollPosition();
|
||||
}
|
||||
|
||||
private AssetDetailsColorSchemaDraft sourceDraft(String schemaId) {
|
||||
final AssetStudioGlyphMaterialSchema schema = coordinator.findSchema(schemaId).orElse(null);
|
||||
final List<AssetWorkspaceBankCompositionFile> selectableTiles = schema == null
|
||||
? coordinator.availableTilesForCreate()
|
||||
: coordinator.availableTilesForEdit(schema.schemaId());
|
||||
final Set<String> assignedArtifactIds = schema == null
|
||||
? Set.of()
|
||||
: schema.artifactBindings().stream()
|
||||
.map(AssetStudioGlyphMaterialArtifactBinding::artifactId)
|
||||
.collect(java.util.stream.Collectors.toCollection(LinkedHashSet::new));
|
||||
final List<AssetWorkspaceBankCompositionFile> assignedTiles = selectableTiles.stream()
|
||||
.filter(file -> assignedArtifactIds.contains(AssetDetailsColorSchemaCoordinator.artifactId(file)))
|
||||
.toList();
|
||||
final List<AssetWorkspaceBankCompositionFile> availableTiles = selectableTiles.stream()
|
||||
.filter(file -> !assignedArtifactIds.contains(AssetDetailsColorSchemaCoordinator.artifactId(file)))
|
||||
.toList();
|
||||
final List<String> preferredColors = schema == null
|
||||
? List.of()
|
||||
: schema.materialIndices().entrySet().stream()
|
||||
.sorted(java.util.Map.Entry.comparingByKey())
|
||||
.map(java.util.Map.Entry::getValue)
|
||||
.toList();
|
||||
return new AssetDetailsColorSchemaDraft(schemaId, schema != null, false, availableTiles, assignedTiles, preferredColors, schema == null);
|
||||
}
|
||||
|
||||
private void replaceFormSource() {
|
||||
if (!coordinator.ready()) {
|
||||
formSession = null;
|
||||
return;
|
||||
}
|
||||
if (formSession != null && formSession.mode() == StudioFormMode.EDITING) {
|
||||
return;
|
||||
}
|
||||
final String schemaId = selectedSchemaId != null ? selectedSchemaId : defaultSchemaId();
|
||||
selectedSchemaId = schemaId;
|
||||
final AssetDetailsColorSchemaDraft source = schemaId == null
|
||||
? AssetDetailsColorSchemaDraft.noSelection()
|
||||
: sourceDraft(schemaId);
|
||||
if (formSession == null) {
|
||||
formSession = new StudioFormSession<>(source);
|
||||
} else {
|
||||
formSession.replaceSource(source);
|
||||
}
|
||||
}
|
||||
|
||||
private void normalizeSelectedSchema() {
|
||||
if (selectedSchemaId == null || coordinator.findSchema(selectedSchemaId).isPresent()) {
|
||||
return;
|
||||
}
|
||||
selectedSchemaId = null;
|
||||
}
|
||||
|
||||
private String defaultSchemaId() {
|
||||
return coordinator.schemas().stream()
|
||||
.map(AssetStudioGlyphMaterialSchema::schemaId)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private List<SchemaListItem> schemaListItems() {
|
||||
final List<SchemaListItem> items = new java.util.ArrayList<>(coordinator.schemas().stream()
|
||||
.map(schema -> SchemaListItem.fromSchema(schema, coordinator.selectedTiles()))
|
||||
.toList());
|
||||
if (formSession != null
|
||||
&& formSession.draft().selected()
|
||||
&& !formSession.draft().existingSchema()
|
||||
&& items.stream().noneMatch(item -> item.schemaId().equals(formSession.draft().schemaId()))) {
|
||||
items.add(SchemaListItem.fromDraft(formSession.draft()));
|
||||
}
|
||||
return List.copyOf(items);
|
||||
}
|
||||
|
||||
private ListCell<SchemaListItem> createSchemaCell() {
|
||||
return new ListCell<>() {
|
||||
@Override
|
||||
protected void updateItem(SchemaListItem item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (empty || item == null) {
|
||||
setGraphic(null);
|
||||
setText(null);
|
||||
return;
|
||||
}
|
||||
final Label title = new Label(item.schemaId());
|
||||
title.getStyleClass().add("assets-details-color-schema-title");
|
||||
final Label version = new Label(item.existing() ? "v" + item.version() : "new");
|
||||
version.getStyleClass().add("assets-details-color-schema-version");
|
||||
final Label status = new Label(item.status());
|
||||
status.getStyleClass().addAll("studio-chip", Objects.equals(item.status(), AssetStudioGlyphMaterialSchemaStatus.OK.manifestValue())
|
||||
? "assets-details-color-schema-status-ok"
|
||||
: "assets-details-color-schema-status-inconsistent");
|
||||
final Region spacer = new Region();
|
||||
HBox.setHgrow(spacer, Priority.ALWAYS);
|
||||
final HBox top = new HBox(8, title, version, spacer, status);
|
||||
|
||||
final Label meta = new Label(item.tileCount() + " tiles · " + item.indexCount() + " indices");
|
||||
meta.getStyleClass().add("assets-details-color-schema-meta");
|
||||
final VBox root = new VBox(6, top, meta);
|
||||
root.getStyleClass().add("assets-details-color-schema-item");
|
||||
setGraphic(root);
|
||||
setText(null);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Region swatch(String color) {
|
||||
final Region swatch = new Region();
|
||||
swatch.getStyleClass().add("assets-details-color-schema-swatch");
|
||||
swatch.setMinSize(20, 20);
|
||||
swatch.setPrefSize(20, 20);
|
||||
swatch.setMaxSize(20, 20);
|
||||
swatch.setStyle("-fx-background-color: " + color + ";");
|
||||
return swatch;
|
||||
}
|
||||
|
||||
private Node emptyMessage(String text) {
|
||||
final Label label = new Label(text);
|
||||
label.getStyleClass().add("assets-details-color-schema-empty");
|
||||
return label;
|
||||
}
|
||||
|
||||
private String currentScopeKey() {
|
||||
return viewState == null || viewState.selectedAssetReference() == null
|
||||
? null
|
||||
: "asset-details:" + viewState.selectedAssetReference();
|
||||
}
|
||||
|
||||
private static final class SchemaTileDualListView extends StudioDualListView<AssetWorkspaceBankCompositionFile> {
|
||||
private SchemaTileDualListView() {
|
||||
setLeftTitle(Container.i18n().text(I18n.ASSETS_COLOR_SCHEMA_DIALOG_AVAILABLE_TILES));
|
||||
setRightTitle(Container.i18n().text(I18n.ASSETS_COLOR_SCHEMA_DIALOG_ASSIGNED_TILES));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String itemText(AssetWorkspaceBankCompositionFile item) {
|
||||
return item.displayName();
|
||||
}
|
||||
}
|
||||
|
||||
private record SchemaListItem(
|
||||
String schemaId,
|
||||
boolean existing,
|
||||
int version,
|
||||
String status,
|
||||
int tileCount,
|
||||
int indexCount) {
|
||||
|
||||
private static SchemaListItem fromSchema(AssetStudioGlyphMaterialSchema schema, List<AssetWorkspaceBankCompositionFile> selectedTiles) {
|
||||
return new SchemaListItem(
|
||||
schema.schemaId(),
|
||||
true,
|
||||
schema.version(),
|
||||
AssetDetailsColorSchemaCoordinator.effectiveStatus(schema, selectedTiles).manifestValue(),
|
||||
schema.artifactBindings().size(),
|
||||
schema.materialIndices().size());
|
||||
}
|
||||
|
||||
private static SchemaListItem fromDraft(AssetDetailsColorSchemaDraft draft) {
|
||||
return new SchemaListItem(
|
||||
draft.schemaId(),
|
||||
false,
|
||||
0,
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK.manifestValue(),
|
||||
draft.assignedTiles().size(),
|
||||
draft.orderedColors().size());
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-26
@@ -1,5 +1,6 @@
|
||||
package p.studio.workspaces.assets.details.summary;
|
||||
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.Container;
|
||||
import p.studio.controls.lifecycle.StudioControlLifecycle;
|
||||
@@ -10,7 +11,6 @@ import p.studio.utilities.i18n.I18n;
|
||||
import p.studio.workspaces.assets.details.AssetDetailsUiSupport;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioGlyphSpecialization;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioSceneBankMetadata;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioSceneLayerBinding;
|
||||
import p.studio.workspaces.assets.messages.AssetWorkspaceAssetSummary;
|
||||
import p.studio.workspaces.assets.messages.AssetWorkspaceDetailsViewState;
|
||||
import p.studio.workspaces.assets.messages.events.StudioAssetsDetailsViewStateChangedEvent;
|
||||
@@ -56,43 +56,23 @@ public final class AssetDetailsSummaryControl extends VBox implements StudioCont
|
||||
}
|
||||
|
||||
final VBox content = new VBox(8);
|
||||
final AssetStudioSceneBankMetadata sceneBankMetadata = viewState.selectedAssetDetails().sceneBankMetadata();
|
||||
content.getChildren().setAll(
|
||||
AssetDetailsUiSupport.createKeyValueRow(Container.i18n().text(I18n.ASSETS_LABEL_ASSET_ID), summary.assetId() == null ? "—" : String.valueOf(summary.assetId())),
|
||||
AssetDetailsUiSupport.createKeyValueRow(Container.i18n().text(I18n.ASSETS_LABEL_LOCATION), AssetDetailsUiSupport.projectRelativePath(projectReference, summary.assetRoot())));
|
||||
final VBox typeBox = new VBox(6);
|
||||
final HBox typeBox = new HBox(8);
|
||||
typeBox.getStyleClass().add("assets-details-chips");
|
||||
typeBox.getChildren().add(AssetDetailsUiSupport.createChip(
|
||||
AssetDetailsUiSupport.typeChipTone(summary.assetFamily()),
|
||||
AssetDetailsUiSupport.typeLabel(summary.assetFamily())));
|
||||
if (summary.glyphSpecialization() != AssetStudioGlyphSpecialization.NONE) {
|
||||
typeBox.getChildren().add(AssetDetailsUiSupport.createChip(
|
||||
"assets-details-chip-generic",
|
||||
AssetDetailsUiSupport.specializationLabel(summary.glyphSpecialization())));
|
||||
AssetDetailsUiSupport.typeChipTone(summary.assetFamily()),
|
||||
AssetDetailsUiSupport.specializationLabel(summary.glyphSpecialization()),
|
||||
"assets-details-chip-fixed"));
|
||||
}
|
||||
content.getChildren().add(AssetDetailsUiSupport.createKeyValueRow(
|
||||
Container.i18n().text(I18n.ASSETS_LABEL_TYPE),
|
||||
typeBox));
|
||||
if (summary.glyphSpecialization() != AssetStudioGlyphSpecialization.NONE) {
|
||||
content.getChildren().add(AssetDetailsUiSupport.createKeyValueRow(
|
||||
Container.i18n().text(I18n.ASSETS_LABEL_STUDIO_ROLE),
|
||||
AssetDetailsUiSupport.specializationLabel(summary.glyphSpecialization())));
|
||||
}
|
||||
if (sceneBankMetadata != null) {
|
||||
content.getChildren().add(AssetDetailsUiSupport.createKeyValueRow(
|
||||
Container.i18n().text(I18n.ASSETS_LABEL_SCENE_STATUS),
|
||||
AssetDetailsUiSupport.sceneBankStatusLabel(viewState.selectedAssetDetails().sceneBankValidation().status())));
|
||||
content.getChildren().add(AssetDetailsUiSupport.createKeyValueRow(
|
||||
Container.i18n().text(I18n.ASSETS_LABEL_SCENE_LAYERS),
|
||||
String.valueOf(sceneBankMetadata.layerCount())));
|
||||
content.getChildren().add(AssetDetailsUiSupport.createKeyValueRow(
|
||||
Container.i18n().text(I18n.ASSETS_LABEL_TILEMAPS),
|
||||
sceneBankMetadata.layerBindings().stream()
|
||||
.map(AssetStudioSceneLayerBinding::tilemap)
|
||||
.collect(java.util.stream.Collectors.joining(", "))));
|
||||
content.getChildren().add(AssetDetailsUiSupport.createKeyValueRow(
|
||||
Container.i18n().text(I18n.ASSETS_LABEL_SUPPORT_FILE),
|
||||
AssetDetailsUiSupport.projectRelativePath(projectReference, sceneBankMetadata.supportFile())));
|
||||
}
|
||||
content.getChildren().add(AssetDetailsUiSupport.createKeyValueRow(
|
||||
Container.i18n().text(I18n.ASSETS_LABEL_REGISTRATION),
|
||||
AssetDetailsUiSupport.createChip(
|
||||
|
||||
+2
-2
@@ -113,7 +113,7 @@ public final class AssetListItemControl extends VBox {
|
||||
private String assetRowToneClass(AssetFamilyCatalog assetFamily) {
|
||||
return switch (assetFamily) {
|
||||
case GLYPH_BANK -> "assets-workspace-asset-row-tone-image";
|
||||
case SCENE_BANK -> "assets-workspace-asset-row-tone-generic";
|
||||
case SCENE_BANK -> "assets-workspace-asset-row-tone-scene";
|
||||
case SOUND_BANK -> "assets-workspace-asset-row-tone-audio";
|
||||
default -> "assets-workspace-asset-row-tone-generic";
|
||||
};
|
||||
@@ -122,7 +122,7 @@ public final class AssetListItemControl extends VBox {
|
||||
private String assetNameToneClass(AssetFamilyCatalog assetFamily) {
|
||||
return switch (assetFamily) {
|
||||
case GLYPH_BANK -> "assets-workspace-asset-name-tone-image";
|
||||
case SCENE_BANK -> "assets-workspace-asset-name-tone-generic";
|
||||
case SCENE_BANK -> "assets-workspace-asset-name-tone-scene";
|
||||
case SOUND_BANK -> "assets-workspace-asset-name-tone-audio";
|
||||
default -> "assets-workspace-asset-name-tone-generic";
|
||||
};
|
||||
|
||||
+38
@@ -4,6 +4,7 @@ import p.packer.dtos.PackerCodecConfigurationFieldDTO;
|
||||
import p.packer.dtos.PackerDiagnosticDTO;
|
||||
import p.packer.messages.assets.OutputCodecCatalog;
|
||||
import p.packer.messages.assets.OutputFormatCatalog;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioGlyphMaterialMetadata;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioSceneBankMetadata;
|
||||
|
||||
import java.util.List;
|
||||
@@ -21,6 +22,7 @@ public record AssetWorkspaceAssetDetails(
|
||||
Map<String, Object> outputPipeline,
|
||||
AssetWorkspaceBankCompositionDetails bankComposition,
|
||||
List<Map<String, Object>> pipelinePalettes,
|
||||
AssetStudioGlyphMaterialMetadata glyphMaterialMetadata,
|
||||
AssetStudioSceneBankMetadata sceneBankMetadata,
|
||||
AssetWorkspaceSceneBankValidation sceneBankValidation,
|
||||
List<PackerDiagnosticDTO> diagnostics) {
|
||||
@@ -39,4 +41,40 @@ public record AssetWorkspaceAssetDetails(
|
||||
sceneBankValidation = Objects.requireNonNullElse(sceneBankValidation, AssetWorkspaceSceneBankValidation.NOT_APPLICABLE);
|
||||
diagnostics = List.copyOf(Objects.requireNonNull(diagnostics, "diagnostics"));
|
||||
}
|
||||
|
||||
public AssetWorkspaceAssetDetails withBankComposition(AssetWorkspaceBankCompositionDetails bankComposition) {
|
||||
return new AssetWorkspaceAssetDetails(
|
||||
summary,
|
||||
actions,
|
||||
outputFormat,
|
||||
outputCodec,
|
||||
availableOutputCodecs,
|
||||
codecConfigurationFieldsByCodec,
|
||||
metadataFields,
|
||||
outputPipeline,
|
||||
bankComposition,
|
||||
pipelinePalettes,
|
||||
glyphMaterialMetadata,
|
||||
sceneBankMetadata,
|
||||
sceneBankValidation,
|
||||
diagnostics);
|
||||
}
|
||||
|
||||
public AssetWorkspaceAssetDetails withGlyphMaterialMetadata(AssetStudioGlyphMaterialMetadata glyphMaterialMetadata) {
|
||||
return new AssetWorkspaceAssetDetails(
|
||||
summary,
|
||||
actions,
|
||||
outputFormat,
|
||||
outputCodec,
|
||||
availableOutputCodecs,
|
||||
codecConfigurationFieldsByCodec,
|
||||
metadataFields,
|
||||
outputPipeline,
|
||||
bankComposition,
|
||||
pipelinePalettes,
|
||||
glyphMaterialMetadata,
|
||||
sceneBankMetadata,
|
||||
sceneBankValidation,
|
||||
diagnostics);
|
||||
}
|
||||
}
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package p.studio.workspaces.assets.messages.events;
|
||||
|
||||
import p.packer.messages.AssetReference;
|
||||
import p.studio.lsp.events.StudioEvent;
|
||||
import p.studio.workspaces.assets.messages.AssetWorkspaceBankCompositionDetails;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record StudioBankCompositionChangedEvent(
|
||||
AssetReference assetReference,
|
||||
AssetWorkspaceBankCompositionDetails bankComposition) implements StudioEvent {
|
||||
|
||||
public StudioBankCompositionChangedEvent {
|
||||
assetReference = Objects.requireNonNull(assetReference, "assetReference");
|
||||
bankComposition = Objects.requireNonNull(bankComposition, "bankComposition");
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package p.studio.workspaces.assets.messages.events;
|
||||
|
||||
import p.packer.messages.AssetReference;
|
||||
import p.studio.lsp.events.StudioEvent;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioGlyphMaterialMetadata;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record StudioGlyphMaterialMetadataChangedEvent(
|
||||
AssetReference assetReference,
|
||||
AssetStudioGlyphMaterialMetadata metadata) implements StudioEvent {
|
||||
|
||||
public StudioGlyphMaterialMetadataChangedEvent {
|
||||
assetReference = Objects.requireNonNull(assetReference, "assetReference");
|
||||
metadata = Objects.requireNonNull(metadata, "metadata");
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package p.studio.workspaces.assets.metadata;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record AssetStudioGlyphMaterialArtifactBinding(
|
||||
String artifactId,
|
||||
String fingerprint) {
|
||||
|
||||
public AssetStudioGlyphMaterialArtifactBinding {
|
||||
artifactId = Objects.requireNonNull(artifactId, "artifactId").trim();
|
||||
fingerprint = Objects.requireNonNull(Objects.requireNonNullElse(fingerprint, ""), "fingerprint").trim();
|
||||
if (artifactId.isBlank()) {
|
||||
throw new IllegalArgumentException("artifactId must not be blank");
|
||||
}
|
||||
if (fingerprint.isBlank()) {
|
||||
throw new IllegalArgumentException("fingerprint must not be blank");
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package p.studio.workspaces.assets.metadata;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
public record AssetStudioGlyphMaterialMetadata(
|
||||
List<AssetStudioGlyphMaterialSchema> schemas,
|
||||
List<AssetStudioGlyphMaterialPalette> palettes,
|
||||
Path supportFile) {
|
||||
|
||||
public AssetStudioGlyphMaterialMetadata {
|
||||
schemas = List.copyOf(Objects.requireNonNull(schemas, "schemas"));
|
||||
palettes = List.copyOf(Objects.requireNonNull(palettes, "palettes"));
|
||||
supportFile = supportFile == null ? null : supportFile.toAbsolutePath().normalize();
|
||||
}
|
||||
|
||||
public Optional<AssetStudioGlyphMaterialSchema> findSchema(String schemaId) {
|
||||
return schemas.stream().filter(schema -> schema.schemaId().equals(schemaId)).findFirst();
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package p.studio.workspaces.assets.metadata;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public record AssetStudioGlyphMaterialPalette(
|
||||
String paletteId,
|
||||
String displayName,
|
||||
String schemaId,
|
||||
int version,
|
||||
List<String> colors) {
|
||||
|
||||
public AssetStudioGlyphMaterialPalette(String paletteId, String schemaId, int version, List<String> colors) {
|
||||
this(paletteId, null, schemaId, version, colors);
|
||||
}
|
||||
|
||||
public AssetStudioGlyphMaterialPalette {
|
||||
paletteId = Objects.requireNonNull(paletteId, "paletteId").trim();
|
||||
displayName = displayName == null || displayName.trim().isBlank() ? null : displayName.trim();
|
||||
schemaId = Objects.requireNonNull(schemaId, "schemaId").trim();
|
||||
if (paletteId.isBlank()) {
|
||||
throw new IllegalArgumentException("paletteId must not be blank");
|
||||
}
|
||||
if (schemaId.isBlank()) {
|
||||
throw new IllegalArgumentException("schemaId must not be blank");
|
||||
}
|
||||
if (version <= 0) {
|
||||
throw new IllegalArgumentException("version must be positive");
|
||||
}
|
||||
colors = List.copyOf(Objects.requireNonNull(colors, "colors"));
|
||||
}
|
||||
|
||||
public List<Integer> convertedRgb565Colors() {
|
||||
final List<Integer> converted = new ArrayList<>(colors.size());
|
||||
for (String color : colors) {
|
||||
converted.add(convertHtmlRgbToRgb565(color));
|
||||
}
|
||||
return List.copyOf(converted);
|
||||
}
|
||||
|
||||
static int convertHtmlRgbToRgb565(String htmlRgb) {
|
||||
final String value = Objects.requireNonNull(htmlRgb, "htmlRgb").trim();
|
||||
if (!value.matches("^#[0-9A-Fa-f]{6}$")) {
|
||||
throw new IllegalArgumentException("htmlRgb must use #RRGGBB format");
|
||||
}
|
||||
final int rgb = Integer.parseInt(value.substring(1), 16);
|
||||
final int red = (rgb >> 16) & 0xFF;
|
||||
final int green = (rgb >> 8) & 0xFF;
|
||||
final int blue = rgb & 0xFF;
|
||||
return ((red >> 3) << 11) | ((green >> 2) << 5) | (blue >> 3);
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package p.studio.workspaces.assets.metadata;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public record AssetStudioGlyphMaterialSchema(
|
||||
String schemaId,
|
||||
AssetStudioGlyphMaterialSchemaStatus status,
|
||||
int version,
|
||||
Map<Integer, String> materialIndices,
|
||||
List<AssetStudioGlyphMaterialArtifactBinding> artifactBindings) {
|
||||
|
||||
public AssetStudioGlyphMaterialSchema {
|
||||
schemaId = Objects.requireNonNull(schemaId, "schemaId").trim();
|
||||
status = Objects.requireNonNull(status, "status");
|
||||
if (schemaId.isBlank()) {
|
||||
throw new IllegalArgumentException("schemaId must not be blank");
|
||||
}
|
||||
if (version <= 0) {
|
||||
throw new IllegalArgumentException("version must be positive");
|
||||
}
|
||||
materialIndices = Map.copyOf(new LinkedHashMap<>(Objects.requireNonNull(materialIndices, "materialIndices")));
|
||||
artifactBindings = List.copyOf(Objects.requireNonNull(artifactBindings, "artifactBindings"));
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package p.studio.workspaces.assets.metadata;
|
||||
|
||||
public enum AssetStudioGlyphMaterialSchemaStatus {
|
||||
OK("ok"),
|
||||
INCONSISTENT("inconsistent");
|
||||
|
||||
private final String manifestValue;
|
||||
|
||||
AssetStudioGlyphMaterialSchemaStatus(String manifestValue) {
|
||||
this.manifestValue = manifestValue;
|
||||
}
|
||||
|
||||
public String manifestValue() {
|
||||
return manifestValue;
|
||||
}
|
||||
|
||||
public static AssetStudioGlyphMaterialSchemaStatus fromManifestValue(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
for (AssetStudioGlyphMaterialSchemaStatus candidate : values()) {
|
||||
if (candidate.manifestValue.equalsIgnoreCase(value.trim())) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+186
-4
@@ -12,12 +12,14 @@ import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public final class AssetStudioMetadataService {
|
||||
public static final String STUDIO_ASSET_METADATA_FILE = "studio.asset.json";
|
||||
public static final String SCENE_BANK_SUPPORT_FILE = "scene-bank.studio.json";
|
||||
public static final String GLYPH_MATERIAL_SUPPORT_FILE = "glyph-material.json";
|
||||
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@@ -25,7 +27,32 @@ public final class AssetStudioMetadataService {
|
||||
final Path normalizedAssetRoot = Objects.requireNonNull(assetRoot, "assetRoot").toAbsolutePath().normalize();
|
||||
return new AssetStudioMetadataSnapshot(
|
||||
readGlyphSpecialization(normalizedAssetRoot, assetFamily),
|
||||
readSceneBankMetadata(normalizedAssetRoot, assetFamily));
|
||||
readSceneBankMetadata(normalizedAssetRoot, assetFamily),
|
||||
readGlyphMaterialMetadata(normalizedAssetRoot, assetFamily));
|
||||
}
|
||||
|
||||
public void writeSceneBankMetadata(Path assetRoot, AssetStudioSceneBankMetadata metadata) throws IOException {
|
||||
final Path normalizedAssetRoot = Objects.requireNonNull(assetRoot, "assetRoot").toAbsolutePath().normalize();
|
||||
final AssetStudioSceneBankMetadata normalized = Objects.requireNonNull(metadata, "metadata");
|
||||
final var root = mapper.createObjectNode();
|
||||
root.put("schema_version", 1);
|
||||
root.put("map_width", normalized.mapWidth());
|
||||
root.put("map_height", normalized.mapHeight());
|
||||
root.put("layer_count", normalized.layerCount());
|
||||
final ArrayNode layers = root.putArray("layers");
|
||||
for (AssetStudioSceneLayerBinding binding : normalized.layerBindings()) {
|
||||
final var layer = layers.addObject();
|
||||
layer.put("index", binding.index());
|
||||
layer.put("enabled", binding.enabled());
|
||||
layer.put("name", binding.layerName());
|
||||
layer.put("width", binding.width());
|
||||
layer.put("height", binding.height());
|
||||
layer.put("tilemap", binding.tilemap());
|
||||
layer.put("tileset_asset_root", binding.tilesetAssetRoot());
|
||||
}
|
||||
mapper.writerWithDefaultPrettyPrinter().writeValue(
|
||||
normalizedAssetRoot.resolve(SCENE_BANK_SUPPORT_FILE).toFile(),
|
||||
root);
|
||||
}
|
||||
|
||||
public void writeGlyphSpecialization(Path assetRoot, AssetStudioGlyphSpecialization specialization) throws IOException {
|
||||
@@ -46,6 +73,45 @@ public final class AssetStudioMetadataService {
|
||||
mapper.writerWithDefaultPrettyPrinter().writeValue(metadataPath.toFile(), root);
|
||||
}
|
||||
|
||||
public void writeGlyphMaterialMetadata(Path assetRoot, AssetStudioGlyphMaterialMetadata metadata) throws IOException {
|
||||
final Path normalizedAssetRoot = Objects.requireNonNull(assetRoot, "assetRoot").toAbsolutePath().normalize();
|
||||
final AssetStudioGlyphMaterialMetadata normalized = Objects.requireNonNull(metadata, "metadata");
|
||||
final var root = mapper.createObjectNode();
|
||||
root.put("schema_version", 1);
|
||||
final ArrayNode schemas = root.putArray("schemas");
|
||||
for (AssetStudioGlyphMaterialSchema schema : normalized.schemas()) {
|
||||
final var schemaNode = schemas.addObject();
|
||||
schemaNode.put("schema_id", schema.schemaId());
|
||||
schemaNode.put("status", schema.status().manifestValue());
|
||||
schemaNode.put("version", schema.version());
|
||||
final var materialIndicesNode = schemaNode.putObject("material_indices");
|
||||
schema.materialIndices().entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByKey())
|
||||
.forEach(entry -> materialIndicesNode.put(String.valueOf(entry.getKey()), entry.getValue()));
|
||||
final ArrayNode bindingsNode = schemaNode.putArray("artifact_bindings");
|
||||
for (AssetStudioGlyphMaterialArtifactBinding binding : schema.artifactBindings()) {
|
||||
final var bindingNode = bindingsNode.addObject();
|
||||
bindingNode.put("artifact_id", binding.artifactId());
|
||||
bindingNode.put("fingerprint", binding.fingerprint());
|
||||
}
|
||||
}
|
||||
final ArrayNode palettes = root.putArray("palettes");
|
||||
for (AssetStudioGlyphMaterialPalette palette : normalized.palettes()) {
|
||||
final var paletteNode = palettes.addObject();
|
||||
paletteNode.put("palette_id", palette.paletteId());
|
||||
if (palette.displayName() != null) {
|
||||
paletteNode.put("name", palette.displayName());
|
||||
}
|
||||
paletteNode.put("schema_id", palette.schemaId());
|
||||
paletteNode.put("version", palette.version());
|
||||
final ArrayNode colorsNode = paletteNode.putArray("colors");
|
||||
palette.colors().forEach(colorsNode::add);
|
||||
}
|
||||
mapper.writerWithDefaultPrettyPrinter().writeValue(
|
||||
normalizedAssetRoot.resolve(GLYPH_MATERIAL_SUPPORT_FILE).toFile(),
|
||||
root);
|
||||
}
|
||||
|
||||
private AssetStudioGlyphSpecialization readGlyphSpecialization(Path assetRoot, AssetFamilyCatalog assetFamily) {
|
||||
if (assetFamily != AssetFamilyCatalog.GLYPH_BANK) {
|
||||
return AssetStudioGlyphSpecialization.NONE;
|
||||
@@ -81,7 +147,7 @@ public final class AssetStudioMetadataService {
|
||||
final int mapWidth = root.path("map_width").asInt(0);
|
||||
final int mapHeight = root.path("map_height").asInt(0);
|
||||
final int layerCount = root.path("layer_count").asInt(0);
|
||||
if (mapWidth <= 0 || mapHeight <= 0 || layerCount < 1 || layerCount > 4) {
|
||||
if (mapWidth <= 0 || mapHeight <= 0 || layerCount != 4) {
|
||||
return null;
|
||||
}
|
||||
if (!(root.path("layers") instanceof ArrayNode layersNode) || layersNode.size() != layerCount) {
|
||||
@@ -91,13 +157,16 @@ public final class AssetStudioMetadataService {
|
||||
final Set<Integer> indexes = new HashSet<>();
|
||||
for (JsonNode layerNode : layersNode) {
|
||||
final int index = layerNode.path("index").asInt(0);
|
||||
final boolean enabled = layerNode.path("enabled").asBoolean(false);
|
||||
final String layerName = layerNode.path("name").asText("").trim();
|
||||
final int width = layerNode.path("width").asInt(mapWidth);
|
||||
final int height = layerNode.path("height").asInt(mapHeight);
|
||||
final String tilemap = layerNode.path("tilemap").asText("").trim();
|
||||
final String tilesetAssetRoot = layerNode.path("tileset_asset_root").asText("").trim();
|
||||
if (index < 1 || index > layerCount || layerName.isBlank() || tilemap.isBlank() || !indexes.add(index)) {
|
||||
if (index < 1 || index > layerCount || layerName.isBlank() || width <= 0 || height <= 0 || tilemap.isBlank() || !indexes.add(index)) {
|
||||
return null;
|
||||
}
|
||||
bindings.add(new AssetStudioSceneLayerBinding(index, layerName, tilemap, tilesetAssetRoot));
|
||||
bindings.add(new AssetStudioSceneLayerBinding(enabled, index, layerName, width, height, tilemap, tilesetAssetRoot));
|
||||
}
|
||||
bindings.sort(Comparator.comparingInt(AssetStudioSceneLayerBinding::index));
|
||||
return new AssetStudioSceneBankMetadata(mapWidth, mapHeight, layerCount, bindings, supportFile);
|
||||
@@ -105,4 +174,117 @@ public final class AssetStudioMetadataService {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private AssetStudioGlyphMaterialMetadata readGlyphMaterialMetadata(Path assetRoot, AssetFamilyCatalog assetFamily) {
|
||||
if (assetFamily != AssetFamilyCatalog.GLYPH_BANK) {
|
||||
return null;
|
||||
}
|
||||
final Path supportFile = assetRoot.resolve(GLYPH_MATERIAL_SUPPORT_FILE);
|
||||
if (!Files.isRegularFile(supportFile)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
final JsonNode root = mapper.readTree(supportFile.toFile());
|
||||
if (root == null || !root.isObject()) {
|
||||
return null;
|
||||
}
|
||||
if (!(root.path("schemas") instanceof ArrayNode schemasNode) || !(root.path("palettes") instanceof ArrayNode palettesNode)) {
|
||||
return null;
|
||||
}
|
||||
final List<AssetStudioGlyphMaterialSchema> schemas = new ArrayList<>();
|
||||
final Set<String> schemaIds = new HashSet<>();
|
||||
for (JsonNode schemaNode : schemasNode) {
|
||||
final String schemaId = schemaNode.path("schema_id").asText("").trim();
|
||||
final AssetStudioGlyphMaterialSchemaStatus status = AssetStudioGlyphMaterialSchemaStatus.fromManifestValue(
|
||||
schemaNode.path("status").asText(null));
|
||||
final int version = schemaNode.path("version").asInt(0);
|
||||
if (schemaId.isBlank() || status == null || version <= 0 || !schemaIds.add(schemaId)) {
|
||||
return null;
|
||||
}
|
||||
final JsonNode materialIndicesNode = schemaNode.path("material_indices");
|
||||
if (!materialIndicesNode.isObject()) {
|
||||
return null;
|
||||
}
|
||||
final Map<Integer, String> materialIndices = new java.util.TreeMap<>();
|
||||
materialIndicesNode.fields().forEachRemaining(entry -> {
|
||||
try {
|
||||
final int index = Integer.parseInt(entry.getKey());
|
||||
final String color = normalizeHtmlColor(entry.getValue().asText(null));
|
||||
if (index >= 1 && index <= 15 && color != null) {
|
||||
materialIndices.put(index, color);
|
||||
}
|
||||
} catch (NumberFormatException ignored) {
|
||||
// handled below through validation
|
||||
}
|
||||
});
|
||||
if (materialIndices.isEmpty()
|
||||
|| materialIndices.size() != materialIndicesNode.size()
|
||||
|| !denseIndices(materialIndices.keySet())) {
|
||||
return null;
|
||||
}
|
||||
if (!(schemaNode.path("artifact_bindings") instanceof ArrayNode bindingsNode) || bindingsNode.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
final List<AssetStudioGlyphMaterialArtifactBinding> bindings = new ArrayList<>();
|
||||
final Set<String> artifactIds = new HashSet<>();
|
||||
for (JsonNode bindingNode : bindingsNode) {
|
||||
final String artifactId = bindingNode.path("artifact_id").asText("").trim();
|
||||
final String fingerprint = bindingNode.path("fingerprint").asText("").trim();
|
||||
if (artifactId.isBlank() || fingerprint.isBlank() || !artifactIds.add(artifactId)) {
|
||||
return null;
|
||||
}
|
||||
bindings.add(new AssetStudioGlyphMaterialArtifactBinding(artifactId, fingerprint));
|
||||
}
|
||||
schemas.add(new AssetStudioGlyphMaterialSchema(schemaId, status, version, materialIndices, bindings));
|
||||
}
|
||||
final List<AssetStudioGlyphMaterialPalette> palettes = new ArrayList<>();
|
||||
final Set<String> paletteIds = new HashSet<>();
|
||||
for (JsonNode paletteNode : palettesNode) {
|
||||
final String paletteId = paletteNode.path("palette_id").asText("").trim();
|
||||
final String displayName = paletteNode.path("name").asText(null);
|
||||
final String schemaId = paletteNode.path("schema_id").asText("").trim();
|
||||
final int version = paletteNode.path("version").asInt(0);
|
||||
if (paletteId.isBlank() || schemaId.isBlank() || version <= 0 || !paletteIds.add(paletteId) || !schemaIds.contains(schemaId)) {
|
||||
return null;
|
||||
}
|
||||
if (!(paletteNode.path("colors") instanceof ArrayNode colorsNode)) {
|
||||
return null;
|
||||
}
|
||||
final List<String> colors = new ArrayList<>();
|
||||
for (JsonNode colorNode : colorsNode) {
|
||||
final String color = normalizeHtmlColor(colorNode.asText(null));
|
||||
if (color == null) {
|
||||
return null;
|
||||
}
|
||||
colors.add(color);
|
||||
}
|
||||
palettes.add(new AssetStudioGlyphMaterialPalette(paletteId, displayName, schemaId, version, colors));
|
||||
}
|
||||
return new AssetStudioGlyphMaterialMetadata(schemas, palettes, supportFile);
|
||||
} catch (IOException ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean denseIndices(Set<Integer> indices) {
|
||||
if (indices.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
int expected = 1;
|
||||
for (Integer index : new java.util.TreeSet<>(indices)) {
|
||||
if (index == null || index != expected) {
|
||||
return false;
|
||||
}
|
||||
expected += 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private String normalizeHtmlColor(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
final String normalized = value.trim().toUpperCase();
|
||||
return normalized.matches("^#[0-9A-F]{6}$") ? normalized : null;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -4,7 +4,8 @@ import java.util.Objects;
|
||||
|
||||
public record AssetStudioMetadataSnapshot(
|
||||
AssetStudioGlyphSpecialization glyphSpecialization,
|
||||
AssetStudioSceneBankMetadata sceneBankMetadata) {
|
||||
AssetStudioSceneBankMetadata sceneBankMetadata,
|
||||
AssetStudioGlyphMaterialMetadata glyphMaterialMetadata) {
|
||||
|
||||
public AssetStudioMetadataSnapshot {
|
||||
glyphSpecialization = Objects.requireNonNullElse(glyphSpecialization, AssetStudioGlyphSpecialization.NONE);
|
||||
|
||||
+6
-2
@@ -17,11 +17,15 @@ public record AssetStudioSceneBankMetadata(
|
||||
if (mapWidth <= 0 || mapHeight <= 0) {
|
||||
throw new IllegalArgumentException("map dimensions must be positive");
|
||||
}
|
||||
if (layerCount < 1 || layerCount > 4) {
|
||||
throw new IllegalArgumentException("layerCount must stay between 1 and 4");
|
||||
if (layerCount != 4) {
|
||||
throw new IllegalArgumentException("layerCount must stay fixed at 4");
|
||||
}
|
||||
if (layerBindings.size() != layerCount) {
|
||||
throw new IllegalArgumentException("layerBindings must match layerCount");
|
||||
}
|
||||
}
|
||||
|
||||
public long enabledLayerCount() {
|
||||
return layerBindings.stream().filter(AssetStudioSceneLayerBinding::enabled).count();
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -3,8 +3,11 @@ package p.studio.workspaces.assets.metadata;
|
||||
import java.util.Objects;
|
||||
|
||||
public record AssetStudioSceneLayerBinding(
|
||||
boolean enabled,
|
||||
int index,
|
||||
String layerName,
|
||||
int width,
|
||||
int height,
|
||||
String tilemap,
|
||||
String tilesetAssetRoot) {
|
||||
public AssetStudioSceneLayerBinding {
|
||||
@@ -17,6 +20,9 @@ public record AssetStudioSceneLayerBinding(
|
||||
if (layerName.isBlank()) {
|
||||
throw new IllegalArgumentException("layerName must not be blank");
|
||||
}
|
||||
if (width <= 0 || height <= 0) {
|
||||
throw new IllegalArgumentException("layer dimensions must be positive");
|
||||
}
|
||||
if (tilemap.isBlank()) {
|
||||
throw new IllegalArgumentException("tilemap must not be blank");
|
||||
}
|
||||
|
||||
+115
-3
@@ -39,7 +39,7 @@ public final class SceneBankWorkflowService {
|
||||
if (details == null || details.summary().assetFamily() != p.packer.messages.assets.AssetFamilyCatalog.SCENE_BANK) {
|
||||
return new SceneBankWorkflowResult(true, "", AssetWorkspaceSceneBankValidation.NOT_APPLICABLE, List.of());
|
||||
}
|
||||
final List<PackerDiagnosticDTO> diagnostics = validateDiagnostics(projectReference, details);
|
||||
final List<PackerDiagnosticDTO> diagnostics = validateDiagnostics(projectReference, details, null);
|
||||
final String currentFingerprint = diagnostics.stream().anyMatch(PackerDiagnosticDTO::blocking)
|
||||
? ""
|
||||
: computeFingerprint(projectReference, details);
|
||||
@@ -98,7 +98,70 @@ public final class SceneBankWorkflowService {
|
||||
return inspect(projectReference, details);
|
||||
}
|
||||
|
||||
private List<PackerDiagnosticDTO> validateDiagnostics(ProjectReference projectReference, AssetWorkspaceAssetDetails details) {
|
||||
public SceneBankWorkflowResult inspectLayer(ProjectReference projectReference, AssetWorkspaceAssetDetails details, int layerIndex) {
|
||||
if (details == null || details.summary().assetFamily() != p.packer.messages.assets.AssetFamilyCatalog.SCENE_BANK) {
|
||||
return new SceneBankWorkflowResult(true, "", AssetWorkspaceSceneBankValidation.NOT_APPLICABLE, List.of());
|
||||
}
|
||||
final List<PackerDiagnosticDTO> diagnostics = validateDiagnostics(projectReference, details, layerIndex);
|
||||
final String currentFingerprint = diagnostics.stream().anyMatch(PackerDiagnosticDTO::blocking)
|
||||
? ""
|
||||
: computeFingerprint(projectReference, details, layerIndex);
|
||||
final String validatedFingerprint = readFingerprint(details.summary().assetRoot().resolve(layerValidationFile(layerIndex)));
|
||||
final String acceptedFingerprint = readFingerprint(details.summary().assetRoot().resolve(layerAcceptanceFile(layerIndex)));
|
||||
final AssetWorkspaceSceneBankValidation validation = validationState(
|
||||
diagnostics,
|
||||
currentFingerprint,
|
||||
validatedFingerprint,
|
||||
acceptedFingerprint);
|
||||
return new SceneBankWorkflowResult(
|
||||
diagnostics.stream().noneMatch(PackerDiagnosticDTO::blocking),
|
||||
messageFor(validation),
|
||||
validation,
|
||||
diagnostics);
|
||||
}
|
||||
|
||||
public SceneBankWorkflowResult validateLayer(ProjectReference projectReference, AssetWorkspaceAssetDetails details, int layerIndex) {
|
||||
final SceneBankWorkflowResult inspection = inspectLayer(projectReference, details, layerIndex);
|
||||
final Path validationFile = details.summary().assetRoot().resolve(layerValidationFile(layerIndex));
|
||||
try {
|
||||
if (inspection.success() && !inspection.validation().currentFingerprint().isBlank()) {
|
||||
writeFingerprint(validationFile, inspection.validation().currentFingerprint());
|
||||
} else {
|
||||
Files.deleteIfExists(validationFile);
|
||||
}
|
||||
} catch (IOException exception) {
|
||||
return new SceneBankWorkflowResult(
|
||||
false,
|
||||
"Unable to persist validation state: " + exception.getMessage(),
|
||||
inspection.validation(),
|
||||
inspection.diagnostics());
|
||||
}
|
||||
return inspectLayer(projectReference, details, layerIndex);
|
||||
}
|
||||
|
||||
public SceneBankWorkflowResult acceptLayer(ProjectReference projectReference, AssetWorkspaceAssetDetails details, int layerIndex) {
|
||||
final SceneBankWorkflowResult inspection = inspectLayer(projectReference, details, layerIndex);
|
||||
if (!inspection.validation().canAccept()) {
|
||||
return new SceneBankWorkflowResult(
|
||||
false,
|
||||
"Scene layer must validate successfully before acceptance.",
|
||||
inspection.validation(),
|
||||
inspection.diagnostics());
|
||||
}
|
||||
try {
|
||||
writeFingerprint(details.summary().assetRoot().resolve(layerAcceptanceFile(layerIndex)), inspection.validation().currentFingerprint());
|
||||
writeFingerprint(details.summary().assetRoot().resolve(layerValidationFile(layerIndex)), inspection.validation().currentFingerprint());
|
||||
} catch (IOException exception) {
|
||||
return new SceneBankWorkflowResult(
|
||||
false,
|
||||
"Unable to persist acceptance state: " + exception.getMessage(),
|
||||
inspection.validation(),
|
||||
inspection.diagnostics());
|
||||
}
|
||||
return inspectLayer(projectReference, details, layerIndex);
|
||||
}
|
||||
|
||||
private List<PackerDiagnosticDTO> validateDiagnostics(ProjectReference projectReference, AssetWorkspaceAssetDetails details, Integer targetLayerIndex) {
|
||||
final List<PackerDiagnosticDTO> diagnostics = new ArrayList<>();
|
||||
final AssetStudioSceneBankMetadata metadata = details.sceneBankMetadata();
|
||||
if (metadata == null) {
|
||||
@@ -106,6 +169,12 @@ public final class SceneBankWorkflowService {
|
||||
return diagnostics;
|
||||
}
|
||||
for (AssetStudioSceneLayerBinding binding : metadata.layerBindings()) {
|
||||
if (!binding.enabled()) {
|
||||
continue;
|
||||
}
|
||||
if (targetLayerIndex != null && binding.index() != targetLayerIndex) {
|
||||
continue;
|
||||
}
|
||||
if (binding.tilesetAssetRoot().isBlank()) {
|
||||
diagnostics.add(error("Layer " + binding.index() + " is missing tileset_asset_root.", metadata.supportFile()));
|
||||
continue;
|
||||
@@ -139,7 +208,7 @@ public final class SceneBankWorkflowService {
|
||||
} else if (!expectedSource.equals(map.tilesets().getFirst().source())) {
|
||||
diagnostics.add(error("TMX tileset reference does not match support metadata: " + binding.tilemap(), tmxPath));
|
||||
}
|
||||
if (map.width() != metadata.mapWidth() || map.height() != metadata.mapHeight()) {
|
||||
if (map.width() != binding.width() || map.height() != binding.height()) {
|
||||
diagnostics.add(error("TMX dimensions do not match scene-bank support metadata: " + binding.tilemap(), tmxPath));
|
||||
}
|
||||
if (map.tileWidth() != tileset.tileWidth() || map.tileHeight() != tileset.tileHeight()) {
|
||||
@@ -167,6 +236,9 @@ public final class SceneBankWorkflowService {
|
||||
final List<Path> files = new ArrayList<>();
|
||||
files.add(metadata.supportFile());
|
||||
for (AssetStudioSceneLayerBinding binding : metadata.layerBindings()) {
|
||||
if (!binding.enabled()) {
|
||||
continue;
|
||||
}
|
||||
files.add(details.summary().assetRoot().resolve(binding.tilemap()).toAbsolutePath().normalize());
|
||||
if (!binding.tilesetAssetRoot().isBlank()) {
|
||||
files.add(projectReference.rootPath().resolve("assets").resolve(binding.tilesetAssetRoot()).resolve("tileset.tsx").toAbsolutePath().normalize());
|
||||
@@ -182,6 +254,38 @@ public final class SceneBankWorkflowService {
|
||||
}
|
||||
}
|
||||
|
||||
private String computeFingerprint(ProjectReference projectReference, AssetWorkspaceAssetDetails details, int layerIndex) {
|
||||
final AssetStudioSceneBankMetadata metadata = details.sceneBankMetadata();
|
||||
if (metadata == null) {
|
||||
return "";
|
||||
}
|
||||
try {
|
||||
final MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
final List<Path> files = new ArrayList<>();
|
||||
files.add(metadata.supportFile());
|
||||
metadata.layerBindings().stream()
|
||||
.filter(AssetStudioSceneLayerBinding::enabled)
|
||||
.filter(binding -> binding.index() == layerIndex)
|
||||
.findFirst()
|
||||
.ifPresent(binding -> {
|
||||
files.add(details.summary().assetRoot().resolve(binding.tilemap()).toAbsolutePath().normalize());
|
||||
if (!binding.tilesetAssetRoot().isBlank()) {
|
||||
files.add(projectReference.rootPath().resolve("assets").resolve(binding.tilesetAssetRoot()).resolve("tileset.tsx").toAbsolutePath().normalize());
|
||||
}
|
||||
});
|
||||
if (files.size() == 1) {
|
||||
return "";
|
||||
}
|
||||
files.stream()
|
||||
.distinct()
|
||||
.sorted(Comparator.comparing(Path::toString))
|
||||
.forEach(path -> updateDigest(digest, path));
|
||||
return HexFormat.of().formatHex(digest.digest());
|
||||
} catch (Exception exception) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDigest(MessageDigest digest, Path path) {
|
||||
try {
|
||||
if (!Files.isRegularFile(path)) {
|
||||
@@ -238,6 +342,14 @@ public final class SceneBankWorkflowService {
|
||||
acceptedFingerprint);
|
||||
}
|
||||
|
||||
private String layerValidationFile(int layerIndex) {
|
||||
return "scene-bank.layer-" + layerIndex + ".validation.json";
|
||||
}
|
||||
|
||||
private String layerAcceptanceFile(int layerIndex) {
|
||||
return "scene-bank.layer-" + layerIndex + ".acceptance.json";
|
||||
}
|
||||
|
||||
private String messageFor(AssetWorkspaceSceneBankValidation validation) {
|
||||
return switch (validation.status()) {
|
||||
case NOT_APPLICABLE -> "";
|
||||
|
||||
+89
-54
@@ -28,7 +28,7 @@ public final class TiledAssetGenerationService {
|
||||
}
|
||||
final List<AssetWorkspaceBankCompositionFile> selectedFiles = details.bankComposition().selectedFiles();
|
||||
if (selectedFiles.isEmpty()) {
|
||||
return new TiledAssetGenerationResult(false, "Select at least one glyph artifact before generating TSX.", List.of());
|
||||
return new TiledAssetGenerationResult(false, "The selected tileset bank has no included glyph artifacts.", List.of());
|
||||
}
|
||||
final int tileSize = parseTileSize(details.metadataFields());
|
||||
final List<TiledTilesetTile> tiles = new ArrayList<>();
|
||||
@@ -72,63 +72,98 @@ public final class TiledAssetGenerationService {
|
||||
final List<Path> writtenFiles = new ArrayList<>();
|
||||
try {
|
||||
for (AssetStudioSceneLayerBinding binding : metadata.layerBindings()) {
|
||||
final String tilesetAssetRoot = Objects.requireNonNullElse(binding.tilesetAssetRoot(), "").trim();
|
||||
if (tilesetAssetRoot.isBlank()) {
|
||||
return new TiledAssetGenerationResult(
|
||||
false,
|
||||
"Layer " + binding.index() + " must declare a non-blank tileset_asset_root before TMX generation.",
|
||||
List.of());
|
||||
if (!binding.enabled()) {
|
||||
continue;
|
||||
}
|
||||
final Path tilesetPath = projectReference.rootPath()
|
||||
.resolve("assets")
|
||||
.resolve(tilesetAssetRoot)
|
||||
.resolve(GENERATED_TSX_FILE)
|
||||
.toAbsolutePath()
|
||||
.normalize();
|
||||
if (!java.nio.file.Files.isRegularFile(tilesetPath)) {
|
||||
return new TiledAssetGenerationResult(
|
||||
false,
|
||||
"Referenced TSX was not found for layer " + binding.index() + ": " + tilesetAssetRoot,
|
||||
List.of());
|
||||
final TiledAssetGenerationResult result = generateSceneBankTilemap(projectReference, details, binding.index());
|
||||
if (!result.success()) {
|
||||
return result;
|
||||
}
|
||||
final TiledTilesetDocument tileset = codec.readTileset(tilesetPath);
|
||||
final String relativeTilesetPath = details.summary().assetRoot()
|
||||
.toAbsolutePath()
|
||||
.normalize()
|
||||
.relativize(tilesetPath)
|
||||
.toString()
|
||||
.replace('\\', '/');
|
||||
final int tileCount = metadata.mapWidth() * metadata.mapHeight();
|
||||
final List<Long> gids = new ArrayList<>(tileCount);
|
||||
for (int index = 0; index < tileCount; index += 1) {
|
||||
gids.add(0L);
|
||||
}
|
||||
final TiledMapDocument document = new TiledMapDocument(
|
||||
"1.10",
|
||||
"1.12.1",
|
||||
"orthogonal",
|
||||
"right-down",
|
||||
metadata.mapWidth(),
|
||||
metadata.mapHeight(),
|
||||
tileset.tileWidth(),
|
||||
tileset.tileHeight(),
|
||||
2,
|
||||
1,
|
||||
List.of(),
|
||||
List.of(new TiledTilesetReference(1, relativeTilesetPath)),
|
||||
List.of(new TiledTileLayer(
|
||||
1,
|
||||
binding.layerName(),
|
||||
metadata.mapWidth(),
|
||||
metadata.mapHeight(),
|
||||
gids,
|
||||
List.of())),
|
||||
List.of());
|
||||
final Path outputPath = details.summary().assetRoot().resolve(binding.tilemap());
|
||||
codec.writeMap(outputPath, document);
|
||||
writtenFiles.add(outputPath);
|
||||
writtenFiles.addAll(result.writtenFiles());
|
||||
}
|
||||
if (writtenFiles.isEmpty()) {
|
||||
return new TiledAssetGenerationResult(false, "Enable at least one layer before generating TMX.", List.of());
|
||||
}
|
||||
return new TiledAssetGenerationResult(true, "Generated TMX successfully.", writtenFiles);
|
||||
} catch (RuntimeException exception) {
|
||||
return new TiledAssetGenerationResult(false, "Unable to generate TMX: " + exception.getMessage(), List.of());
|
||||
}
|
||||
}
|
||||
|
||||
public TiledAssetGenerationResult generateSceneBankTilemap(ProjectReference projectReference, AssetWorkspaceAssetDetails details, int layerIndex) {
|
||||
if (details == null || details.summary().assetFamily() != AssetFamilyCatalog.SCENE_BANK) {
|
||||
return new TiledAssetGenerationResult(false, "TMX generation is available only for Scene Bank assets.", List.of());
|
||||
}
|
||||
final AssetStudioSceneBankMetadata metadata = details.sceneBankMetadata();
|
||||
if (metadata == null) {
|
||||
return new TiledAssetGenerationResult(false, "Scene Bank support metadata is missing or invalid.", List.of());
|
||||
}
|
||||
final AssetStudioSceneLayerBinding binding = metadata.layerBindings().stream()
|
||||
.filter(candidate -> candidate.index() == layerIndex)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (binding == null) {
|
||||
return new TiledAssetGenerationResult(false, "Layer " + layerIndex + " is not defined in Scene Bank metadata.", List.of());
|
||||
}
|
||||
if (!binding.enabled()) {
|
||||
return new TiledAssetGenerationResult(false, "Layer " + layerIndex + " is disabled.", List.of());
|
||||
}
|
||||
try {
|
||||
final String tilesetAssetRoot = Objects.requireNonNullElse(binding.tilesetAssetRoot(), "").trim();
|
||||
if (tilesetAssetRoot.isBlank()) {
|
||||
return new TiledAssetGenerationResult(
|
||||
false,
|
||||
"Layer " + binding.index() + " must declare a non-blank tileset_asset_root before TMX generation.",
|
||||
List.of());
|
||||
}
|
||||
final Path tilesetPath = projectReference.rootPath()
|
||||
.resolve("assets")
|
||||
.resolve(tilesetAssetRoot)
|
||||
.resolve(GENERATED_TSX_FILE)
|
||||
.toAbsolutePath()
|
||||
.normalize();
|
||||
if (!java.nio.file.Files.isRegularFile(tilesetPath)) {
|
||||
return new TiledAssetGenerationResult(
|
||||
false,
|
||||
"Referenced TSX was not found for layer " + binding.index() + ": " + tilesetAssetRoot,
|
||||
List.of());
|
||||
}
|
||||
final TiledTilesetDocument tileset = codec.readTileset(tilesetPath);
|
||||
final String relativeTilesetPath = details.summary().assetRoot()
|
||||
.toAbsolutePath()
|
||||
.normalize()
|
||||
.relativize(tilesetPath)
|
||||
.toString()
|
||||
.replace('\\', '/');
|
||||
final int tileCount = binding.width() * binding.height();
|
||||
final List<Long> gids = new ArrayList<>(tileCount);
|
||||
for (int index = 0; index < tileCount; index += 1) {
|
||||
gids.add(0L);
|
||||
}
|
||||
final TiledMapDocument document = new TiledMapDocument(
|
||||
"1.10",
|
||||
"1.12.1",
|
||||
"orthogonal",
|
||||
"right-down",
|
||||
binding.width(),
|
||||
binding.height(),
|
||||
tileset.tileWidth(),
|
||||
tileset.tileHeight(),
|
||||
2,
|
||||
1,
|
||||
List.of(),
|
||||
List.of(new TiledTilesetReference(1, relativeTilesetPath)),
|
||||
List.of(new TiledTileLayer(
|
||||
1,
|
||||
binding.layerName(),
|
||||
binding.width(),
|
||||
binding.height(),
|
||||
gids,
|
||||
List.of())),
|
||||
List.of());
|
||||
final Path outputPath = details.summary().assetRoot().resolve(binding.tilemap());
|
||||
codec.writeMap(outputPath, document);
|
||||
return new TiledAssetGenerationResult(true, "Generated TMX for layer " + binding.index() + ".", List.of(outputPath));
|
||||
} catch (TiledUnsupportedFeatureException | IOException exception) {
|
||||
return new TiledAssetGenerationResult(false, "Unable to generate TMX: " + exception.getMessage(), List.of());
|
||||
}
|
||||
|
||||
+13
-3
@@ -137,7 +137,9 @@ public final class AddAssetWizard {
|
||||
assetFamilyCombo.valueProperty().addListener((ignored, oldValue, newValue) -> {
|
||||
if (!Objects.equals(oldValue, newValue)) {
|
||||
if (newValue != AssetFamilyCatalog.GLYPH_BANK) {
|
||||
glyphSpecializationCombo.getSelectionModel().select(AssetStudioGlyphSpecialization.NONE);
|
||||
glyphSpecializationCombo.getSelectionModel().clearSelection();
|
||||
} else if (glyphSpecializationCombo.getValue() == null) {
|
||||
glyphSpecializationCombo.getSelectionModel().select(AssetStudioGlyphSpecialization.SPRITES);
|
||||
}
|
||||
refreshOutputFormats();
|
||||
if (stepIndex == 1) {
|
||||
@@ -148,10 +150,13 @@ public final class AddAssetWizard {
|
||||
}
|
||||
|
||||
private void configureGlyphSpecializationCombo() {
|
||||
glyphSpecializationCombo.setItems(FXCollections.observableArrayList(AssetStudioGlyphSpecialization.values()));
|
||||
glyphSpecializationCombo.setItems(FXCollections.observableArrayList(
|
||||
java.util.Arrays.stream(AssetStudioGlyphSpecialization.values())
|
||||
.filter(candidate -> candidate != AssetStudioGlyphSpecialization.NONE)
|
||||
.toList()));
|
||||
glyphSpecializationCombo.setMaxWidth(Double.MAX_VALUE);
|
||||
glyphSpecializationCombo.setPromptText(Container.i18n().text(I18n.ASSETS_ADD_WIZARD_PROMPT_SPECIALIZATION));
|
||||
glyphSpecializationCombo.getSelectionModel().select(AssetStudioGlyphSpecialization.NONE);
|
||||
glyphSpecializationCombo.getSelectionModel().select(AssetStudioGlyphSpecialization.SPRITES);
|
||||
glyphSpecializationCombo.setCellFactory(ignored -> new javafx.scene.control.ListCell<>() {
|
||||
@Override
|
||||
protected void updateItem(AssetStudioGlyphSpecialization item, boolean empty) {
|
||||
@@ -331,6 +336,11 @@ public final class AddAssetWizard {
|
||||
feedbackLabel.setText(Container.i18n().text(I18n.ASSETS_ADD_WIZARD_ERROR_TYPE));
|
||||
return false;
|
||||
}
|
||||
if (selectedFamily() == AssetFamilyCatalog.GLYPH_BANK
|
||||
&& (selectedGlyphSpecialization() == null || selectedGlyphSpecialization() == AssetStudioGlyphSpecialization.NONE)) {
|
||||
feedbackLabel.setText(Container.i18n().text(I18n.ASSETS_ADD_WIZARD_ERROR_SPECIALIZATION));
|
||||
return false;
|
||||
}
|
||||
if (selectedFormat() == null || selectedFormat() == OutputFormatCatalog.UNKNOWN) {
|
||||
feedbackLabel.setText(Container.i18n().text(I18n.ASSETS_ADD_WIZARD_ERROR_FORMAT));
|
||||
return false;
|
||||
|
||||
@@ -135,6 +135,9 @@ assets.badge.diagnostics=Diagnostics
|
||||
assets.section.summary=Summary
|
||||
assets.section.runtimeContract=Runtime Contract
|
||||
assets.section.bankComposition=Bank Composition
|
||||
assets.section.sceneLayers=Scene Layers
|
||||
assets.section.colorSchemaGroups=Color Schema Groups
|
||||
assets.section.layerConfiguration=Layer Configuration
|
||||
assets.section.paletteOverhauling=Palette Overhauling
|
||||
assets.subsection.codecConfiguration=Codec Configuration
|
||||
assets.subsection.metadata=Metadata
|
||||
@@ -148,6 +151,8 @@ assets.action.generateTsx=Generate TSX
|
||||
assets.action.generateTmx=Generate TMX
|
||||
assets.action.validateSceneBank=Validate Scene Bank
|
||||
assets.action.acceptSceneBank=Accept Scene Bank
|
||||
assets.action.validateLayer=Validate Layer
|
||||
assets.action.acceptLayer=Accept Layer
|
||||
assets.action.delete=Delete
|
||||
assets.deleteDialog.title=Delete Asset
|
||||
assets.deleteDialog.description=Type the asset name below to confirm deletion of {0}.
|
||||
@@ -188,8 +193,14 @@ assets.label.type=Type
|
||||
assets.label.studioRole=Studio Role
|
||||
assets.label.sceneStatus=Scene Status
|
||||
assets.label.sceneLayers=Scene Layers
|
||||
assets.label.sceneDimensions=Layer Size
|
||||
assets.label.layer=Layer
|
||||
assets.label.layerOverview=Layer Overview
|
||||
assets.label.tilemaps=Tilemaps
|
||||
assets.label.tilemap=Tilemap
|
||||
assets.label.tileset=Tileset
|
||||
assets.label.supportFile=Support File
|
||||
assets.label.useLayer=Use this layer
|
||||
assets.type.glyphBank=Glyph Bank
|
||||
assets.type.sceneBank=Scene Bank
|
||||
assets.type.paletteBank=Palette Bank
|
||||
@@ -215,6 +226,8 @@ assets.value.included=Included
|
||||
assets.value.excluded=Excluded
|
||||
assets.value.yes=Yes
|
||||
assets.value.no=No
|
||||
assets.value.notConfigured=Not configured
|
||||
assets.value.layerOverviewPending=Overview reserved for this layer. Preview data will appear here when the layer pipeline is connected.
|
||||
assets.progress.idle=Assets workspace idle.
|
||||
assets.progress.refreshing=Refreshing assets...
|
||||
assets.progress.loadingDetails=Loading selected asset details...
|
||||
@@ -250,6 +263,22 @@ assets.paletteOverhauling.selected=Bank Palettes
|
||||
assets.paletteOverhauling.tileSelector=Preview Tile
|
||||
assets.paletteOverhauling.appliedPalette=Applied Palette
|
||||
assets.paletteOverhauling.previewEmpty=Select at least one palette to inspect it on a tile.
|
||||
assets.paletteWizard.createTitle=Create Palette
|
||||
assets.paletteWizard.updateTitle=Update Palette
|
||||
assets.paletteWizard.name=Name
|
||||
assets.paletteWizard.schema=Schema
|
||||
assets.paletteWizard.original=Original Palette
|
||||
assets.paletteWizard.editable=Editable Palette
|
||||
assets.paletteWizard.applyColor=Apply Color
|
||||
assets.paletteWizard.duplicate=An identical palette already exists for this schema.
|
||||
assets.paletteWizard.ready=Palette is ready to be saved.
|
||||
assets.colorSchema.empty=No schemas have been authored for this glyph bank yet.
|
||||
assets.colorSchema.summary={0} schema groups ready, {1} selected tiles still unassigned.
|
||||
assets.colorSchema.removeBlocked=Schema {0} cannot be removed while palettes still reference it.
|
||||
assets.colorSchema.dialog.availableTiles=Available Tiles
|
||||
assets.colorSchema.dialog.assignedTiles=Assigned Tiles
|
||||
assets.colorSchema.dialog.colorCount=Color count: {0}
|
||||
assets.colorSchema.dialog.tooManyColors=Color Schema Groups support at most 15 visible indices.
|
||||
assets.details.codecConfiguration.empty=This codec does not expose configuration fields yet.
|
||||
assets.details.metadata.empty=This asset does not expose metadata fields yet.
|
||||
assets.addWizard.title=Add Asset
|
||||
@@ -281,6 +310,7 @@ assets.addWizard.error.rootRelative=Asset root must be a relative path inside as
|
||||
assets.addWizard.error.rootOutsideAssets=The selected directory must stay inside assets/.
|
||||
assets.addWizard.error.rootAlreadyAsset=The selected root already contains asset.json.
|
||||
assets.addWizard.error.type=Choose an asset type before continuing.
|
||||
assets.addWizard.error.specialization=Choose a Studio specialization before continuing.
|
||||
assets.addWizard.error.format=Choose an output format before continuing.
|
||||
assets.addWizard.error.codec=Choose an output codec before continuing.
|
||||
assets.addWizard.error.unsupportedCombination=The selected asset type, output format, and codec combination is not supported.
|
||||
|
||||
@@ -114,6 +114,20 @@
|
||||
-fx-padding: 8;
|
||||
}
|
||||
|
||||
.studio-button.assets-details-mini-action-button {
|
||||
-fx-min-width: 26;
|
||||
-fx-pref-width: 26;
|
||||
-fx-max-width: 26;
|
||||
-fx-min-height: 24;
|
||||
-fx-pref-height: 24;
|
||||
-fx-max-height: 24;
|
||||
-fx-padding: 0;
|
||||
-fx-background-radius: 6;
|
||||
-fx-border-radius: 6;
|
||||
-fx-font-size: 12px;
|
||||
-fx-font-weight: bold;
|
||||
}
|
||||
|
||||
.studio-button.studio-button-primary {
|
||||
-fx-background-color: #27507a;
|
||||
-fx-border-color: #5ea0de;
|
||||
@@ -1213,6 +1227,15 @@
|
||||
-fx-background-color: #162a20;
|
||||
}
|
||||
|
||||
.assets-workspace-asset-row-tone-scene {
|
||||
-fx-background-color: #1d1610;
|
||||
-fx-border-color: #b58931;
|
||||
}
|
||||
|
||||
.assets-workspace-asset-row-tone-scene:hover {
|
||||
-fx-background-color: #2a2015;
|
||||
}
|
||||
|
||||
.assets-workspace-asset-row-tone-generic {
|
||||
-fx-background-color: #11151b;
|
||||
-fx-border-color: #334050;
|
||||
@@ -1240,6 +1263,10 @@
|
||||
-fx-text-fill: #aee8c5;
|
||||
}
|
||||
|
||||
.assets-workspace-asset-name-tone-scene {
|
||||
-fx-text-fill: #f5d47a;
|
||||
}
|
||||
|
||||
.assets-workspace-asset-name-tone-generic {
|
||||
-fx-text-fill: #f6fbff;
|
||||
}
|
||||
@@ -1457,6 +1484,12 @@
|
||||
-fx-max-height: 446;
|
||||
}
|
||||
|
||||
.assets-details-color-schema-section {
|
||||
-fx-min-height: 446;
|
||||
-fx-pref-height: 446;
|
||||
-fx-max-height: 446;
|
||||
}
|
||||
|
||||
.assets-details-bank-composition-body {
|
||||
-fx-alignment: top-left;
|
||||
}
|
||||
@@ -1465,6 +1498,76 @@
|
||||
-fx-alignment: top-left;
|
||||
}
|
||||
|
||||
.assets-details-palette-overhauling-toolbar {
|
||||
-fx-alignment: top-left;
|
||||
-fx-padding: 25 0 0 0;
|
||||
}
|
||||
|
||||
.assets-details-color-schema-content {
|
||||
-fx-alignment: top-left;
|
||||
}
|
||||
|
||||
.assets-details-color-schema-toolbar {
|
||||
-fx-alignment: top-left;
|
||||
-fx-padding: 25 0 0 0;
|
||||
}
|
||||
|
||||
.assets-details-list-with-actions {
|
||||
-fx-alignment: top-left;
|
||||
}
|
||||
|
||||
.assets-details-color-schema-body {
|
||||
-fx-alignment: top-left;
|
||||
}
|
||||
|
||||
.assets-details-color-schema-list {
|
||||
-fx-pref-width: 280;
|
||||
-fx-max-width: 320;
|
||||
}
|
||||
|
||||
.assets-details-color-schema-item {
|
||||
-fx-padding: 8 10 8 10;
|
||||
}
|
||||
|
||||
.assets-details-color-schema-title {
|
||||
-fx-font-size: 12px;
|
||||
-fx-font-weight: bold;
|
||||
-fx-text-fill: #f2f6fb;
|
||||
}
|
||||
|
||||
.assets-details-color-schema-version {
|
||||
-fx-font-size: 11px;
|
||||
-fx-text-fill: #8fa4b8;
|
||||
}
|
||||
|
||||
.assets-details-color-schema-meta,
|
||||
.assets-details-color-schema-summary,
|
||||
.assets-details-color-schema-empty,
|
||||
.assets-details-color-schema-warning,
|
||||
.assets-details-color-schema-preview-title {
|
||||
-fx-font-size: 11px;
|
||||
-fx-text-fill: #9bb0c3;
|
||||
}
|
||||
|
||||
.assets-details-color-schema-status-ok {
|
||||
-fx-background-color: #203a2b;
|
||||
-fx-text-fill: #8ee0ac;
|
||||
}
|
||||
|
||||
.assets-details-color-schema-status-inconsistent {
|
||||
-fx-background-color: #4a261f;
|
||||
-fx-text-fill: #ffb29d;
|
||||
}
|
||||
|
||||
.assets-details-color-schema-strip {
|
||||
-fx-padding: 0 0 4 0;
|
||||
}
|
||||
|
||||
.assets-details-color-schema-swatch {
|
||||
-fx-border-color: #334150;
|
||||
-fx-border-width: 1;
|
||||
}
|
||||
|
||||
.assets-details-bank-file-cell {
|
||||
-fx-alignment: center-left;
|
||||
}
|
||||
@@ -1500,6 +1603,43 @@
|
||||
-fx-alignment: center-left;
|
||||
}
|
||||
|
||||
.assets-details-palette-invalid {
|
||||
-fx-font-size: 10px;
|
||||
-fx-text-fill: #d9a58f;
|
||||
}
|
||||
|
||||
.assets-details-palette-wizard {
|
||||
-fx-background-color: #111821;
|
||||
-fx-border-color: #263545;
|
||||
-fx-border-width: 1;
|
||||
}
|
||||
|
||||
.assets-details-palette-wizard-label {
|
||||
-fx-font-size: 11px;
|
||||
-fx-font-weight: bold;
|
||||
-fx-text-fill: #9fc3e7;
|
||||
}
|
||||
|
||||
.assets-details-palette-wizard-strip,
|
||||
.assets-details-palette-wizard-editor,
|
||||
.assets-details-palette-wizard-color-editor {
|
||||
-fx-alignment: center-left;
|
||||
}
|
||||
|
||||
.assets-details-palette-wizard-summary {
|
||||
-fx-font-size: 11px;
|
||||
-fx-text-fill: #c0d0e0;
|
||||
}
|
||||
|
||||
.assets-details-palette-wizard-actions {
|
||||
-fx-alignment: center-right;
|
||||
}
|
||||
|
||||
.assets-details-palette-wizard-swatch {
|
||||
-fx-border-color: #334150;
|
||||
-fx-border-width: 1;
|
||||
}
|
||||
|
||||
.assets-details-palette-hash {
|
||||
-fx-text-fill: #9fc3e7;
|
||||
-fx-font-size: 10px;
|
||||
@@ -1594,6 +1734,124 @@
|
||||
-fx-border-width: 1;
|
||||
}
|
||||
|
||||
.assets-details-chip-fixed {
|
||||
-fx-alignment: center;
|
||||
-fx-min-width: 88;
|
||||
-fx-pref-width: 88;
|
||||
-fx-max-width: 88;
|
||||
}
|
||||
|
||||
.assets-scene-layer-shell {
|
||||
-fx-spacing: 0;
|
||||
}
|
||||
|
||||
.assets-scene-layer-layout {
|
||||
-fx-alignment: top-left;
|
||||
}
|
||||
|
||||
.assets-scene-layer-config-column {
|
||||
-fx-spacing: 10;
|
||||
}
|
||||
|
||||
.assets-scene-layer-config {
|
||||
-fx-pref-width: 0;
|
||||
-fx-spacing: 8;
|
||||
}
|
||||
|
||||
.assets-scene-layer-config-section {
|
||||
-fx-pref-width: 0;
|
||||
}
|
||||
|
||||
.assets-scene-layer-chip {
|
||||
-fx-min-width: 70;
|
||||
-fx-pref-width: 70;
|
||||
-fx-max-width: 70;
|
||||
-fx-alignment: center;
|
||||
}
|
||||
|
||||
.assets-scene-layer-selector {
|
||||
-fx-alignment: center-left;
|
||||
}
|
||||
|
||||
.assets-scene-layer-selector-button {
|
||||
-fx-background-color: #17120d;
|
||||
-fx-border-color: #634d22;
|
||||
-fx-text-fill: #d9c28f;
|
||||
-fx-font-weight: bold;
|
||||
-fx-padding: 8 14 8 14;
|
||||
}
|
||||
|
||||
.assets-scene-layer-selector-button:hover {
|
||||
-fx-background-color: #221a10;
|
||||
-fx-border-color: #8f6f33;
|
||||
-fx-text-fill: #f5ddb0;
|
||||
}
|
||||
|
||||
.assets-scene-layer-selector-button-active {
|
||||
-fx-background-color: #2a1f12;
|
||||
-fx-border-color: #d4a94a;
|
||||
-fx-text-fill: #ffe5a6;
|
||||
}
|
||||
|
||||
.assets-scene-layer-enabled {
|
||||
-fx-text-fill: #d6e0ea;
|
||||
}
|
||||
|
||||
.assets-scene-layer-form-actions {
|
||||
-fx-alignment: center-right;
|
||||
-fx-spacing: 8;
|
||||
}
|
||||
|
||||
.assets-scene-layer-actions {
|
||||
-fx-padding: 6 0 0 0;
|
||||
}
|
||||
|
||||
.assets-scene-layer-action {
|
||||
-fx-max-width: 140;
|
||||
}
|
||||
|
||||
.assets-scene-layer-size-editor {
|
||||
-fx-alignment: center-left;
|
||||
}
|
||||
|
||||
.assets-scene-layer-size-field {
|
||||
-fx-pref-width: 88;
|
||||
}
|
||||
|
||||
.assets-scene-layer-size-separator {
|
||||
-fx-text-fill: #d6e0ea;
|
||||
-fx-font-weight: bold;
|
||||
}
|
||||
|
||||
.assets-scene-layer-overview {
|
||||
-fx-background-color: #11151b;
|
||||
-fx-background-radius: 10;
|
||||
-fx-border-color: #26313d;
|
||||
-fx-border-radius: 10;
|
||||
-fx-border-width: 1;
|
||||
-fx-min-width: 260;
|
||||
-fx-pref-width: 260;
|
||||
-fx-max-width: 260;
|
||||
-fx-min-height: 220;
|
||||
-fx-padding: 10;
|
||||
-fx-spacing: 10;
|
||||
}
|
||||
|
||||
.assets-scene-layer-overview-title {
|
||||
-fx-text-fill: #d6e0ea;
|
||||
-fx-font-size: 12px;
|
||||
-fx-font-weight: bold;
|
||||
}
|
||||
|
||||
.assets-scene-layer-overview-surface {
|
||||
-fx-background-color: #0f141a;
|
||||
-fx-background-radius: 8;
|
||||
-fx-border-color: #26313d;
|
||||
-fx-border-radius: 8;
|
||||
-fx-border-width: 1;
|
||||
-fx-min-height: 148;
|
||||
}
|
||||
|
||||
.assets-details-chip-image {
|
||||
-fx-background-color: #11283a;
|
||||
-fx-border-color: #5cb6ff;
|
||||
@@ -1606,6 +1864,12 @@
|
||||
-fx-text-fill: #dde6ff;
|
||||
}
|
||||
|
||||
.assets-details-chip-scene {
|
||||
-fx-background-color: #2a1f12;
|
||||
-fx-border-color: #d4a94a;
|
||||
-fx-text-fill: #ffe5a6;
|
||||
}
|
||||
|
||||
.assets-details-chip-generic {
|
||||
-fx-background-color: #1e242c;
|
||||
-fx-border-color: #5f7388;
|
||||
|
||||
+2
@@ -116,6 +116,7 @@ final class AssetDetailsBankCompositionCoordinatorTest {
|
||||
0L),
|
||||
List.of(),
|
||||
null,
|
||||
null,
|
||||
AssetWorkspaceSceneBankValidation.NOT_APPLICABLE,
|
||||
List.of());
|
||||
}
|
||||
@@ -140,6 +141,7 @@ final class AssetDetailsBankCompositionCoordinatorTest {
|
||||
0L),
|
||||
List.of(),
|
||||
null,
|
||||
null,
|
||||
AssetWorkspaceSceneBankValidation.NOT_APPLICABLE,
|
||||
List.of());
|
||||
}
|
||||
|
||||
+373
-68
@@ -5,7 +5,7 @@ import p.packer.messages.AssetReference;
|
||||
import p.packer.messages.assets.AssetFamilyCatalog;
|
||||
import p.packer.messages.assets.OutputCodecCatalog;
|
||||
import p.packer.messages.assets.OutputFormatCatalog;
|
||||
import p.studio.workspaces.assets.metadata.AssetStudioGlyphSpecialization;
|
||||
import p.studio.workspaces.assets.metadata.*;
|
||||
import p.studio.workspaces.assets.messages.*;
|
||||
|
||||
import java.nio.file.Path;
|
||||
@@ -16,64 +16,388 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
final class AssetDetailsPaletteOverhaulingCoordinatorTest {
|
||||
@Test
|
||||
void defaultsToFirstTilePaletteWhenNoSelectedFilesExist() {
|
||||
void derivesOriginalPaletteFromReadySchemaWhenNoPaletteRecordExists() {
|
||||
final AssetDetailsPaletteOverhaulingCoordinator coordinator = new AssetDetailsPaletteOverhaulingCoordinator();
|
||||
coordinator.replaceDetails(tileDetails(List.of(), files("tile", 3)));
|
||||
coordinator.replaceDetails(details(
|
||||
List.of(tile("tile-a.png", "artifact-a")),
|
||||
new AssetStudioGlyphMaterialMetadata(
|
||||
List.of(new AssetStudioGlyphMaterialSchema(
|
||||
"schema-1",
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
1,
|
||||
Map.of(1, "#FF0000", 2, "#00FF00"),
|
||||
List.of(new AssetStudioGlyphMaterialArtifactBinding("artifact-a", "fp-a")))),
|
||||
List.of(),
|
||||
null),
|
||||
List.of()));
|
||||
|
||||
assertTrue(coordinator.ready());
|
||||
assertEquals(0, coordinator.viewModel().selectedFiles().size());
|
||||
assertNull(coordinator.viewModel().previewTileFile());
|
||||
assertNull(coordinator.viewModel().previewPaletteFile());
|
||||
assertEquals(1, coordinator.viewModel().allFiles().size());
|
||||
assertEquals("schema-1 / original", coordinator.viewModel().allFiles().getFirst().displayName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void clickingSelectedPaletteChangesOnlyPreviewPalette() {
|
||||
void initialSelectionStillMatchesBuildFacingPipelinePalettePayload() {
|
||||
final AssetDetailsPaletteOverhaulingCoordinator coordinator = new AssetDetailsPaletteOverhaulingCoordinator();
|
||||
coordinator.replaceDetails(tileDetails(List.of(files("tile", 3).get(0), files("tile", 3).get(1)), List.of(files("tile", 3).get(2))));
|
||||
coordinator.beginEdit();
|
||||
|
||||
final AssetWorkspaceBankCompositionFile first = coordinator.viewModel().availableFiles().get(0);
|
||||
coordinator.moveToSelected(List.of(first));
|
||||
coordinator.selectPreviewPalette(first);
|
||||
|
||||
assertEquals(first.path(), coordinator.viewModel().previewPaletteFile().path());
|
||||
assertEquals(1, coordinator.viewModel().selectedFiles().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void removingPreviewedPaletteFallsBackToFirstRemainingSelectedPalette() {
|
||||
final AssetDetailsPaletteOverhaulingCoordinator coordinator = new AssetDetailsPaletteOverhaulingCoordinator();
|
||||
final List<AssetWorkspaceBankCompositionFile> generated = files("tile", 3);
|
||||
coordinator.replaceDetails(tileDetails(List.of(generated.get(0), generated.get(1)), List.of(generated.get(2))));
|
||||
coordinator.beginEdit();
|
||||
final AssetWorkspaceBankCompositionFile first = coordinator.viewModel().availableFiles().get(0);
|
||||
coordinator.moveToSelected(List.of(first));
|
||||
coordinator.selectPreviewPalette(first);
|
||||
|
||||
coordinator.moveToAvailable(List.of(first));
|
||||
final AssetStudioGlyphMaterialPalette persisted = new AssetStudioGlyphMaterialPalette(
|
||||
"palette-1",
|
||||
"schema-1",
|
||||
1,
|
||||
List.of("#FF0000", "#00FF00"));
|
||||
coordinator.replaceDetails(details(
|
||||
List.of(tile("tile-a.png", "artifact-a")),
|
||||
new AssetStudioGlyphMaterialMetadata(
|
||||
List.of(new AssetStudioGlyphMaterialSchema(
|
||||
"schema-1",
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
1,
|
||||
Map.of(1, "#FF0000", 2, "#00FF00"),
|
||||
List.of(new AssetStudioGlyphMaterialArtifactBinding("artifact-a", "fp-a")))),
|
||||
List.of(persisted),
|
||||
null),
|
||||
List.of(Map.of(
|
||||
"originalArgb8888", List.of(0xFFFF0000, 0xFF00FF00),
|
||||
"convertedRgb565", List.of(0xF800, 0x07E0)))));
|
||||
|
||||
assertEquals(1, coordinator.viewModel().selectedFiles().size());
|
||||
assertEquals(first.path(), coordinator.viewModel().previewPaletteFile().path());
|
||||
assertEquals("palette-1", coordinator.viewModel().selectedFiles().getFirst().metadata().get("paletteId"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deduplicatesPalettesByColorHash() {
|
||||
void previewPaletteDefaultsToAvailablePaletteWhenBuildSelectionIsEmpty() {
|
||||
final AssetDetailsPaletteOverhaulingCoordinator coordinator = new AssetDetailsPaletteOverhaulingCoordinator();
|
||||
final AssetWorkspaceBankCompositionFile first = file("tile-a.png", List.of(0xFFFF0000, 0xFF00FF00));
|
||||
final AssetWorkspaceBankCompositionFile duplicate = file("tile-b.png", List.of(0xFFFF0000, 0xFF00FF00));
|
||||
final AssetWorkspaceBankCompositionFile unique = file("tile-c.png", List.of(0xFF0000FF));
|
||||
coordinator.replaceDetails(details(
|
||||
List.of(tile("tile-a.png", "artifact-a")),
|
||||
new AssetStudioGlyphMaterialMetadata(
|
||||
List.of(new AssetStudioGlyphMaterialSchema(
|
||||
"schema-1",
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
1,
|
||||
Map.of(1, "#FF0000", 2, "#00FF00"),
|
||||
List.of(new AssetStudioGlyphMaterialArtifactBinding("artifact-a", "fp-a")))),
|
||||
List.of(new AssetStudioGlyphMaterialPalette(
|
||||
"palette-1",
|
||||
"schema-1",
|
||||
1,
|
||||
List.of("#112233", "#445566"))),
|
||||
null),
|
||||
List.of()));
|
||||
|
||||
coordinator.replaceDetails(tileDetails(List.of(first), List.of(duplicate, unique)));
|
||||
assertNotNull(coordinator.viewModel().previewPaletteFile());
|
||||
assertTrue(coordinator.viewModel().availableFiles().contains(coordinator.viewModel().previewPaletteFile()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void originalPaletteRemainsSyntheticEvenWhenUserPaletteHasSameColors() {
|
||||
final AssetDetailsPaletteOverhaulingCoordinator coordinator = new AssetDetailsPaletteOverhaulingCoordinator();
|
||||
coordinator.replaceDetails(details(
|
||||
List.of(tile("tile-a.png", "artifact-a")),
|
||||
new AssetStudioGlyphMaterialMetadata(
|
||||
List.of(new AssetStudioGlyphMaterialSchema(
|
||||
"schema-1",
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
1,
|
||||
Map.of(1, "#FF0000", 2, "#00FF00"),
|
||||
List.of(new AssetStudioGlyphMaterialArtifactBinding("artifact-a", "fp-a")))),
|
||||
List.of(new AssetStudioGlyphMaterialPalette(
|
||||
"palette-1",
|
||||
"schema-1",
|
||||
1,
|
||||
List.of("#FF0000", "#00FF00"))),
|
||||
null),
|
||||
List.of()));
|
||||
|
||||
assertEquals(2, coordinator.viewModel().allFiles().size());
|
||||
assertEquals(10, coordinator.viewModel().allFiles().getFirst().displayName().length());
|
||||
assertEquals(coordinator.viewModel().allFiles().stream().map(AssetWorkspaceBankCompositionFile::displayName).distinct().count(),
|
||||
coordinator.viewModel().allFiles().size());
|
||||
final AssetWorkspaceBankCompositionFile original = coordinator.viewModel().allFiles().stream()
|
||||
.filter(AssetDetailsPaletteOverhaulingCoordinator::paletteIsOriginal)
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
final AssetWorkspaceBankCompositionFile userPalette = coordinator.viewModel().allFiles().stream()
|
||||
.filter(file -> "palette-1".equals(file.metadata().get("paletteId")))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
|
||||
assertEquals("schema-schema-1-original", original.metadata().get("paletteId"));
|
||||
assertFalse(AssetDetailsPaletteOverhaulingCoordinator.paletteIsOriginal(userPalette));
|
||||
}
|
||||
|
||||
private AssetWorkspaceAssetDetails tileDetails(
|
||||
@Test
|
||||
void originalPaletteTracksSchemaMaterialColorsAfterMetadataUpdate() {
|
||||
final AssetDetailsPaletteOverhaulingCoordinator coordinator = new AssetDetailsPaletteOverhaulingCoordinator();
|
||||
coordinator.replaceDetails(details(
|
||||
List.of(tile("tile-a.png", "artifact-a")),
|
||||
new AssetStudioGlyphMaterialMetadata(
|
||||
List.of(new AssetStudioGlyphMaterialSchema(
|
||||
"schema-1",
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
1,
|
||||
Map.of(1, "#FF0000", 2, "#00FF00"),
|
||||
List.of(new AssetStudioGlyphMaterialArtifactBinding("artifact-a", "fp-a")))),
|
||||
List.of(),
|
||||
null),
|
||||
List.of()));
|
||||
|
||||
coordinator.replaceMaterialMetadata(new AssetStudioGlyphMaterialMetadata(
|
||||
List.of(new AssetStudioGlyphMaterialSchema(
|
||||
"schema-1",
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
2,
|
||||
Map.of(1, "#112233", 2, "#445566"),
|
||||
List.of(new AssetStudioGlyphMaterialArtifactBinding("artifact-a", "fp-a")))),
|
||||
List.of(),
|
||||
null));
|
||||
|
||||
final AssetWorkspaceBankCompositionFile original = coordinator.viewModel().allFiles().stream()
|
||||
.filter(AssetDetailsPaletteOverhaulingCoordinator::paletteIsOriginal)
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
final Map<String, Object> palette = (Map<String, Object>) original.metadata().get("palette");
|
||||
assertEquals(List.of(0xFF112233, 0xFF445566), palette.get("originalArgb8888"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void duplicateDetectionUsesSameSchemaColorsAndOrder() {
|
||||
final AssetDetailsPaletteOverhaulingCoordinator coordinator = new AssetDetailsPaletteOverhaulingCoordinator();
|
||||
coordinator.replaceDetails(details(
|
||||
List.of(tile("tile-a.png", "artifact-a")),
|
||||
new AssetStudioGlyphMaterialMetadata(
|
||||
List.of(new AssetStudioGlyphMaterialSchema(
|
||||
"schema-1",
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
1,
|
||||
Map.of(1, "#FF0000", 2, "#00FF00"),
|
||||
List.of(new AssetStudioGlyphMaterialArtifactBinding("artifact-a", "fp-a")))),
|
||||
List.of(new AssetStudioGlyphMaterialPalette(
|
||||
"palette-1",
|
||||
"schema-1",
|
||||
1,
|
||||
List.of("#FF0000", "#00FF00"))),
|
||||
null),
|
||||
List.of()));
|
||||
|
||||
assertTrue(coordinator.duplicatePaletteExists(null, "schema-1", List.of("#FF0000", "#00FF00")));
|
||||
assertFalse(coordinator.duplicatePaletteExists(null, "schema-1", List.of("#00FF00", "#FF0000")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void paletteDisplayNameUsesExplicitNameWhenPresent() {
|
||||
final AssetDetailsPaletteOverhaulingCoordinator coordinator = new AssetDetailsPaletteOverhaulingCoordinator();
|
||||
coordinator.replaceDetails(details(
|
||||
List.of(tile("tile-a.png", "artifact-a")),
|
||||
new AssetStudioGlyphMaterialMetadata(
|
||||
List.of(new AssetStudioGlyphMaterialSchema(
|
||||
"schema-1",
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
1,
|
||||
Map.of(1, "#FF0000", 2, "#00FF00"),
|
||||
List.of(new AssetStudioGlyphMaterialArtifactBinding("artifact-a", "fp-a")))),
|
||||
List.of(new AssetStudioGlyphMaterialPalette(
|
||||
"palette-1",
|
||||
"Forest",
|
||||
"schema-1",
|
||||
1,
|
||||
List.of("#FF0000", "#00FF00"))),
|
||||
null),
|
||||
List.of()));
|
||||
|
||||
final AssetWorkspaceBankCompositionFile palette = coordinator.viewModel().allFiles().getFirst();
|
||||
assertEquals("Forest", palette.displayName());
|
||||
assertEquals("Forest", palette.metadata().get("explicitPaletteDisplayName"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void paletteDisplayNameFallsBackToColorsWhenNameIsBlank() {
|
||||
final AssetDetailsPaletteOverhaulingCoordinator coordinator = new AssetDetailsPaletteOverhaulingCoordinator();
|
||||
coordinator.replaceDetails(details(
|
||||
List.of(tile("tile-a.png", "artifact-a")),
|
||||
new AssetStudioGlyphMaterialMetadata(
|
||||
List.of(new AssetStudioGlyphMaterialSchema(
|
||||
"schema-1",
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
1,
|
||||
Map.of(1, "#FF0000", 2, "#00FF00"),
|
||||
List.of(new AssetStudioGlyphMaterialArtifactBinding("artifact-a", "fp-a")))),
|
||||
List.of(new AssetStudioGlyphMaterialPalette(
|
||||
"palette-1",
|
||||
"schema-1",
|
||||
1,
|
||||
List.of("#FF0000", "#00FF00"))),
|
||||
null),
|
||||
List.of()));
|
||||
|
||||
final AssetWorkspaceBankCompositionFile palette = coordinator.viewModel().allFiles().getFirst();
|
||||
assertEquals("ember bloom", palette.displayName());
|
||||
assertFalse(palette.metadata().containsKey("explicitPaletteDisplayName"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void generatedPaletteDisplayNameUsesPoeticColorWords() {
|
||||
assertEquals("snow white", AssetDetailsPaletteOverhaulingCoordinator.generatedDisplayName(List.of("#FFFFFF")));
|
||||
assertEquals("fog twist", AssetDetailsPaletteOverhaulingCoordinator.generatedDisplayName(List.of("#F2F4F4", "#707878")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void upsertPalettePersistsGeneratedDisplayNameWhenNameIsBlank() {
|
||||
final AssetDetailsPaletteOverhaulingCoordinator coordinator = new AssetDetailsPaletteOverhaulingCoordinator();
|
||||
coordinator.replaceDetails(details(
|
||||
List.of(tile("tile-a.png", "artifact-a")),
|
||||
new AssetStudioGlyphMaterialMetadata(
|
||||
List.of(new AssetStudioGlyphMaterialSchema(
|
||||
"schema-1",
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
1,
|
||||
Map.of(1, "#F2F4F4", 2, "#707878"),
|
||||
List.of(new AssetStudioGlyphMaterialArtifactBinding("artifact-a", "fp-a")))),
|
||||
List.of(),
|
||||
null),
|
||||
List.of()));
|
||||
|
||||
final AssetStudioGlyphMaterialMetadata metadata = coordinator.upsertPalette(
|
||||
"palette-1",
|
||||
" ",
|
||||
"schema-1",
|
||||
List.of("#F2F4F4", "#707878"));
|
||||
|
||||
assertEquals("fog twist", metadata.palettes().getFirst().displayName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void removePaletteDeletesUserPaletteEvenWhenSelectedForBuild() {
|
||||
final AssetDetailsPaletteOverhaulingCoordinator coordinator = new AssetDetailsPaletteOverhaulingCoordinator();
|
||||
coordinator.replaceDetails(details(
|
||||
List.of(tile("tile-a.png", "artifact-a")),
|
||||
new AssetStudioGlyphMaterialMetadata(
|
||||
List.of(new AssetStudioGlyphMaterialSchema(
|
||||
"schema-1",
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
1,
|
||||
Map.of(1, "#FF0000", 2, "#00FF00"),
|
||||
List.of(new AssetStudioGlyphMaterialArtifactBinding("artifact-a", "fp-a")))),
|
||||
List.of(new AssetStudioGlyphMaterialPalette(
|
||||
"palette-1",
|
||||
"schema-1",
|
||||
1,
|
||||
List.of("#112233", "#445566"))),
|
||||
null),
|
||||
List.of(Map.of(
|
||||
"originalArgb8888", List.of(0xFF112233, 0xFF445566),
|
||||
"convertedRgb565", List.of(0x1106, 0x42AC)))));
|
||||
|
||||
final AssetStudioGlyphMaterialMetadata metadata = coordinator.removePalette("palette-1");
|
||||
|
||||
assertTrue(metadata.palettes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void removePaletteRejectsSyntheticOriginalPalette() {
|
||||
final AssetDetailsPaletteOverhaulingCoordinator coordinator = new AssetDetailsPaletteOverhaulingCoordinator();
|
||||
coordinator.replaceDetails(details(
|
||||
List.of(tile("tile-a.png", "artifact-a")),
|
||||
new AssetStudioGlyphMaterialMetadata(
|
||||
List.of(new AssetStudioGlyphMaterialSchema(
|
||||
"schema-1",
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
1,
|
||||
Map.of(1, "#FF0000", 2, "#00FF00"),
|
||||
List.of(new AssetStudioGlyphMaterialArtifactBinding("artifact-a", "fp-a")))),
|
||||
List.of(),
|
||||
null),
|
||||
List.of()));
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> coordinator.removePalette("schema-schema-1-original"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void stalePaletteIsProjectedAsInvalid() {
|
||||
final AssetDetailsPaletteOverhaulingCoordinator coordinator = new AssetDetailsPaletteOverhaulingCoordinator();
|
||||
coordinator.replaceDetails(details(
|
||||
List.of(tile("tile-a.png", "artifact-a")),
|
||||
new AssetStudioGlyphMaterialMetadata(
|
||||
List.of(new AssetStudioGlyphMaterialSchema(
|
||||
"schema-1",
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
2,
|
||||
Map.of(1, "#FF0000"),
|
||||
List.of(new AssetStudioGlyphMaterialArtifactBinding("artifact-a", "fp-a")))),
|
||||
List.of(new AssetStudioGlyphMaterialPalette(
|
||||
"palette-1",
|
||||
"schema-1",
|
||||
1,
|
||||
List.of("#FF0000"))),
|
||||
null),
|
||||
List.of()));
|
||||
|
||||
final AssetWorkspaceBankCompositionFile palette = coordinator.viewModel().allFiles().getFirst();
|
||||
assertEquals(Boolean.FALSE, palette.metadata().get("valid"));
|
||||
assertTrue(((String) palette.metadata().get("invalidReason")).contains("stale"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void paletteIsInvalidWhenSchemaArtifactFingerprintDrifts() {
|
||||
final AssetDetailsPaletteOverhaulingCoordinator coordinator = new AssetDetailsPaletteOverhaulingCoordinator();
|
||||
coordinator.replaceDetails(details(
|
||||
List.of(tile("tile-a.png", "artifact-a")),
|
||||
new AssetStudioGlyphMaterialMetadata(
|
||||
List.of(new AssetStudioGlyphMaterialSchema(
|
||||
"schema-1",
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
1,
|
||||
Map.of(1, "#FF0000"),
|
||||
List.of(new AssetStudioGlyphMaterialArtifactBinding("artifact-a", "fp-old")))),
|
||||
List.of(new AssetStudioGlyphMaterialPalette(
|
||||
"palette-1",
|
||||
"schema-1",
|
||||
1,
|
||||
List.of("#FF0000"))),
|
||||
null),
|
||||
List.of()));
|
||||
|
||||
final AssetWorkspaceBankCompositionFile palette = coordinator.viewModel().allFiles().getFirst();
|
||||
assertEquals(Boolean.FALSE, palette.metadata().get("valid"));
|
||||
assertTrue(((String) palette.metadata().get("invalidReason")).contains("inconsistent"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void previewTilesAreScopedToSelectedPaletteSchema() {
|
||||
final AssetDetailsPaletteOverhaulingCoordinator coordinator = new AssetDetailsPaletteOverhaulingCoordinator();
|
||||
coordinator.replaceDetails(details(
|
||||
List.of(tile("tile-a.png", "artifact-a"), tile("tile-b.png", "artifact-b")),
|
||||
new AssetStudioGlyphMaterialMetadata(
|
||||
List.of(
|
||||
new AssetStudioGlyphMaterialSchema(
|
||||
"schema-1",
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
1,
|
||||
Map.of(1, "#FF0000", 2, "#00FF00"),
|
||||
List.of(new AssetStudioGlyphMaterialArtifactBinding("artifact-a", "fp-a"))),
|
||||
new AssetStudioGlyphMaterialSchema(
|
||||
"schema-2",
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
1,
|
||||
Map.of(1, "#0000FF"),
|
||||
List.of(new AssetStudioGlyphMaterialArtifactBinding("artifact-b", "fp-b")))),
|
||||
List.of(),
|
||||
null),
|
||||
List.of()));
|
||||
|
||||
final AssetWorkspaceBankCompositionFile schema2Palette = coordinator.viewModel().allFiles().stream()
|
||||
.filter(file -> "schema-2".equals(file.metadata().get("schemaId")))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
coordinator.selectPreviewPalette(schema2Palette);
|
||||
|
||||
assertEquals(List.of("tile-b.png"), coordinator.viewModel().previewTileFiles().stream().map(AssetWorkspaceBankCompositionFile::path).toList());
|
||||
assertEquals("schema-2", coordinator.viewModel().previewPaletteFile().metadata().get("schemaId"));
|
||||
assertEquals(Map.of(1, "#0000FF"), coordinator.viewModel().previewPaletteFile().metadata().get("schemaMaterialIndices"));
|
||||
}
|
||||
|
||||
private AssetWorkspaceAssetDetails details(
|
||||
List<AssetWorkspaceBankCompositionFile> selectedFiles,
|
||||
List<AssetWorkspaceBankCompositionFile> availableFiles) {
|
||||
AssetStudioGlyphMaterialMetadata metadata,
|
||||
List<Map<String, Object>> pipelinePalettes) {
|
||||
return new AssetWorkspaceAssetDetails(
|
||||
new AssetWorkspaceAssetSummary(
|
||||
AssetReference.forAssetId(1),
|
||||
@@ -82,7 +406,7 @@ final class AssetDetailsPaletteOverhaulingCoordinatorTest {
|
||||
AssetWorkspaceBuildParticipation.INCLUDED,
|
||||
1,
|
||||
AssetFamilyCatalog.GLYPH_BANK,
|
||||
AssetStudioGlyphSpecialization.NONE,
|
||||
AssetStudioGlyphSpecialization.SPRITES,
|
||||
Path.of("/tmp/bank"),
|
||||
false,
|
||||
false),
|
||||
@@ -93,48 +417,29 @@ final class AssetDetailsPaletteOverhaulingCoordinatorTest {
|
||||
Map.of(OutputCodecCatalog.NONE, List.of()),
|
||||
List.of(),
|
||||
Map.of(),
|
||||
new AssetWorkspaceBankCompositionDetails(availableFiles, selectedFiles, 0L),
|
||||
selectedFiles.stream().map(file -> (Map<String, Object>) file.metadata().get("palette")).toList(),
|
||||
new AssetWorkspaceBankCompositionDetails(List.of(), selectedFiles, 0L),
|
||||
pipelinePalettes,
|
||||
metadata,
|
||||
null,
|
||||
AssetWorkspaceSceneBankValidation.NOT_APPLICABLE,
|
||||
List.of());
|
||||
}
|
||||
|
||||
private List<AssetWorkspaceBankCompositionFile> files(String prefix, int count) {
|
||||
return java.util.stream.IntStream.range(0, count)
|
||||
.mapToObj(index -> file(
|
||||
prefix + "-" + index + ".png",
|
||||
List.of(
|
||||
0xFF000000 | ((index + 1) << 16),
|
||||
0xFF000000 | ((index + 1) << 8),
|
||||
0xFF000000 | (index + 1))))
|
||||
.toList();
|
||||
}
|
||||
|
||||
private AssetWorkspaceBankCompositionFile file(String path, List<Integer> colors) {
|
||||
private AssetWorkspaceBankCompositionFile tile(String path, String artifactId) {
|
||||
return new AssetWorkspaceBankCompositionFile(
|
||||
path,
|
||||
path,
|
||||
256L,
|
||||
1L,
|
||||
null,
|
||||
"artifact-a".equals(artifactId) ? "fp-a" : "fp-b",
|
||||
Map.of(
|
||||
"artifactId", artifactId,
|
||||
"tile", Map.of(
|
||||
"width", 2,
|
||||
"height", 2,
|
||||
"paletteIndices", List.of(0, 1, 2, 0)),
|
||||
"palette", Map.of(
|
||||
"originalArgb8888", colors,
|
||||
"convertedRgb565", colors.stream().map(this::toRgb565).toList())));
|
||||
}
|
||||
|
||||
private int toRgb565(int argb8888) {
|
||||
final int red = (argb8888 >> 16) & 0xFF;
|
||||
final int green = (argb8888 >> 8) & 0xFF;
|
||||
final int blue = argb8888 & 0xFF;
|
||||
final int r5 = (red >> 3) & 0x1F;
|
||||
final int g6 = (green >> 2) & 0x3F;
|
||||
final int b5 = (blue >> 3) & 0x1F;
|
||||
return (r5 << 11) | (g6 << 5) | b5;
|
||||
"originalArgb8888", List.of(0xFFFF0000, 0xFF00FF00),
|
||||
"convertedRgb565", List.of(0xF800, 0x07E0))));
|
||||
}
|
||||
}
|
||||
|
||||
+219
@@ -0,0 +1,219 @@
|
||||
package p.studio.workspaces.assets.details.schema;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import p.packer.messages.AssetReference;
|
||||
import p.packer.messages.assets.AssetFamilyCatalog;
|
||||
import p.packer.messages.assets.OutputCodecCatalog;
|
||||
import p.packer.messages.assets.OutputFormatCatalog;
|
||||
import p.studio.workspaces.assets.metadata.*;
|
||||
import p.studio.workspaces.assets.messages.*;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
final class AssetDetailsColorSchemaCoordinatorTest {
|
||||
@Test
|
||||
void createFlowExcludesTilesAlreadyBoundToAnotherSchema() {
|
||||
final AssetDetailsColorSchemaCoordinator coordinator = new AssetDetailsColorSchemaCoordinator();
|
||||
final AssetWorkspaceBankCompositionFile tileA = tile("a.png", "artifact-a", "fp-a", List.of("#FF0000"));
|
||||
final AssetWorkspaceBankCompositionFile tileB = tile("b.png", "artifact-b", "fp-b", List.of("#00FF00"));
|
||||
coordinator.replaceDetails(details(
|
||||
List.of(tileA, tileB),
|
||||
new AssetStudioGlyphMaterialMetadata(
|
||||
List.of(new AssetStudioGlyphMaterialSchema(
|
||||
"schema-1",
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
1,
|
||||
Map.of(1, "#FF0000"),
|
||||
List.of(new AssetStudioGlyphMaterialArtifactBinding("artifact-a", "fp-a")))),
|
||||
List.of(),
|
||||
null)));
|
||||
|
||||
assertEquals(List.of(tileB), coordinator.availableTilesForCreate());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createFlowListsSelectedTilesBeforePaletteMetadataExists() {
|
||||
final AssetDetailsColorSchemaCoordinator coordinator = new AssetDetailsColorSchemaCoordinator();
|
||||
final AssetWorkspaceBankCompositionFile tile = selectedArtifactOnly("a.png", "artifact-a", "fp-a");
|
||||
coordinator.replaceDetails(details(
|
||||
List.of(tile),
|
||||
new AssetStudioGlyphMaterialMetadata(List.of(), List.of(), null)));
|
||||
|
||||
assertEquals(List.of(tile), coordinator.availableTilesForCreate());
|
||||
assertEquals(List.of(), AssetDetailsColorSchemaCoordinator.tileColors(tile));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createFlowUsesSelectedFingerprintWhenCurrentFileFingerprintIsMissing() {
|
||||
final AssetDetailsColorSchemaCoordinator coordinator = new AssetDetailsColorSchemaCoordinator();
|
||||
final AssetWorkspaceBankCompositionFile tile = new AssetWorkspaceBankCompositionFile(
|
||||
"a.png",
|
||||
"a.png",
|
||||
64L,
|
||||
1L,
|
||||
null,
|
||||
Map.of(
|
||||
"artifactId", "artifact-a",
|
||||
"selectedFingerprint", "fp-a"));
|
||||
coordinator.replaceDetails(details(
|
||||
List.of(tile),
|
||||
new AssetStudioGlyphMaterialMetadata(List.of(), List.of(), null)));
|
||||
|
||||
assertEquals(List.of(tile), coordinator.availableTilesForCreate());
|
||||
final AssetStudioGlyphMaterialMetadata metadata = coordinator.upsertSchema(
|
||||
"schema-1",
|
||||
List.of(tile),
|
||||
List.of("#FF0000"));
|
||||
assertEquals("fp-a", metadata.schemas().getFirst().artifactBindings().getFirst().fingerprint());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateFlowKeepsCurrentTilesAndIncrementsVersionWhenSchemaChanges() {
|
||||
final AssetDetailsColorSchemaCoordinator coordinator = new AssetDetailsColorSchemaCoordinator();
|
||||
final AssetWorkspaceBankCompositionFile tileA = tile("a.png", "artifact-a", "fp-a", List.of("#FF0000"));
|
||||
final AssetWorkspaceBankCompositionFile tileB = tile("b.png", "artifact-b", "fp-b", List.of("#00FF00"));
|
||||
coordinator.replaceDetails(details(
|
||||
List.of(tileA, tileB),
|
||||
new AssetStudioGlyphMaterialMetadata(
|
||||
List.of(new AssetStudioGlyphMaterialSchema(
|
||||
"schema-1",
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
1,
|
||||
Map.of(1, "#FF0000"),
|
||||
List.of(new AssetStudioGlyphMaterialArtifactBinding("artifact-a", "fp-a")))),
|
||||
List.of(),
|
||||
null)));
|
||||
|
||||
final AssetStudioGlyphMaterialMetadata updated = coordinator.upsertSchema(
|
||||
"schema-1",
|
||||
List.of(tileA, tileB),
|
||||
List.of("#FF0000", "#00FF00"));
|
||||
|
||||
final AssetStudioGlyphMaterialSchema schema = updated.schemas().getFirst();
|
||||
assertEquals(2, schema.version());
|
||||
assertEquals(Map.of(1, "#FF0000", 2, "#00FF00"), schema.materialIndices());
|
||||
assertEquals(List.of("artifact-a", "artifact-b"), schema.artifactBindings().stream().map(AssetStudioGlyphMaterialArtifactBinding::artifactId).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void removeIsBlockedWhenPalettesStillReferenceSchema() {
|
||||
final AssetDetailsColorSchemaCoordinator coordinator = new AssetDetailsColorSchemaCoordinator();
|
||||
coordinator.replaceDetails(details(
|
||||
List.of(tile("a.png", "artifact-a", "fp-a", List.of("#FF0000"))),
|
||||
new AssetStudioGlyphMaterialMetadata(
|
||||
List.of(new AssetStudioGlyphMaterialSchema(
|
||||
"schema-1",
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
1,
|
||||
Map.of(1, "#FF0000"),
|
||||
List.of(new AssetStudioGlyphMaterialArtifactBinding("artifact-a", "fp-a")))),
|
||||
List.of(new AssetStudioGlyphMaterialPalette("palette-1", "schema-1", 1, List.of("#FF0000"))),
|
||||
null)));
|
||||
|
||||
assertFalse(coordinator.canRemove("schema-1"));
|
||||
assertThrows(IllegalStateException.class, () -> coordinator.removeSchema("schema-1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void effectiveStatusBecomesInconsistentWhenArtifactFingerprintDrifts() {
|
||||
final AssetStudioGlyphMaterialSchema schema = new AssetStudioGlyphMaterialSchema(
|
||||
"schema-1",
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
1,
|
||||
Map.of(1, "#FF0000"),
|
||||
List.of(new AssetStudioGlyphMaterialArtifactBinding("artifact-a", "fp-old")));
|
||||
|
||||
assertEquals(
|
||||
AssetStudioGlyphMaterialSchemaStatus.INCONSISTENT,
|
||||
AssetDetailsColorSchemaCoordinator.effectiveStatus(
|
||||
schema,
|
||||
List.of(tile("a.png", "artifact-a", "fp-new", List.of("#FF0000", "#FF0001")))));
|
||||
}
|
||||
|
||||
@Test
|
||||
void schemaUpdateCanRefreshOnlyFingerprintAndIncrementVersion() {
|
||||
final AssetDetailsColorSchemaCoordinator coordinator = new AssetDetailsColorSchemaCoordinator();
|
||||
final AssetWorkspaceBankCompositionFile changedTile = tile("a.png", "artifact-a", "fp-new", List.of("#FF0000"));
|
||||
coordinator.replaceDetails(details(
|
||||
List.of(changedTile),
|
||||
new AssetStudioGlyphMaterialMetadata(
|
||||
List.of(new AssetStudioGlyphMaterialSchema(
|
||||
"schema-1",
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
1,
|
||||
Map.of(1, "#FF0000"),
|
||||
List.of(new AssetStudioGlyphMaterialArtifactBinding("artifact-a", "fp-old")))),
|
||||
List.of(),
|
||||
null)));
|
||||
|
||||
final AssetStudioGlyphMaterialSchema updated = coordinator.upsertSchema(
|
||||
"schema-1",
|
||||
List.of(changedTile),
|
||||
List.of("#FF0000")).schemas().getFirst();
|
||||
|
||||
assertEquals(2, updated.version());
|
||||
assertEquals(AssetStudioGlyphMaterialSchemaStatus.OK, updated.status());
|
||||
assertEquals("fp-new", updated.artifactBindings().getFirst().fingerprint());
|
||||
}
|
||||
|
||||
private AssetWorkspaceAssetDetails details(
|
||||
List<AssetWorkspaceBankCompositionFile> selectedTiles,
|
||||
AssetStudioGlyphMaterialMetadata metadata) {
|
||||
return new AssetWorkspaceAssetDetails(
|
||||
new AssetWorkspaceAssetSummary(
|
||||
AssetReference.forAssetId(1),
|
||||
"glyph_bank",
|
||||
AssetWorkspaceAssetState.REGISTERED,
|
||||
AssetWorkspaceBuildParticipation.INCLUDED,
|
||||
1,
|
||||
AssetFamilyCatalog.GLYPH_BANK,
|
||||
AssetStudioGlyphSpecialization.SPRITES,
|
||||
Path.of("/tmp/glyph"),
|
||||
false,
|
||||
false),
|
||||
List.of(),
|
||||
OutputFormatCatalog.GLYPH_INDEXED_V1,
|
||||
OutputCodecCatalog.NONE,
|
||||
List.of(OutputCodecCatalog.NONE),
|
||||
Map.of(OutputCodecCatalog.NONE, List.of()),
|
||||
List.of(),
|
||||
Map.of(),
|
||||
new AssetWorkspaceBankCompositionDetails(List.of(), selectedTiles, 0L),
|
||||
List.of(),
|
||||
metadata,
|
||||
null,
|
||||
AssetWorkspaceSceneBankValidation.NOT_APPLICABLE,
|
||||
List.of());
|
||||
}
|
||||
|
||||
private AssetWorkspaceBankCompositionFile tile(String path, String artifactId, String fingerprint, List<String> colors) {
|
||||
final List<Integer> argb = colors.stream()
|
||||
.map(color -> Integer.parseUnsignedInt("FF" + color.substring(1), 16))
|
||||
.map(Integer::valueOf)
|
||||
.toList();
|
||||
return new AssetWorkspaceBankCompositionFile(
|
||||
path,
|
||||
path,
|
||||
64L,
|
||||
1L,
|
||||
fingerprint,
|
||||
Map.of(
|
||||
"artifactId", artifactId,
|
||||
"tile", Map.of("width", 8, "height", 8, "paletteIndices", List.of(1, 1, 1)),
|
||||
"palette", Map.of("originalArgb8888", argb, "convertedRgb565", List.of())));
|
||||
}
|
||||
|
||||
private AssetWorkspaceBankCompositionFile selectedArtifactOnly(String path, String artifactId, String fingerprint) {
|
||||
return new AssetWorkspaceBankCompositionFile(
|
||||
path,
|
||||
path,
|
||||
64L,
|
||||
1L,
|
||||
fingerprint,
|
||||
Map.of("artifactId", artifactId));
|
||||
}
|
||||
}
|
||||
+78
-12
@@ -6,6 +6,8 @@ import p.packer.messages.assets.AssetFamilyCatalog;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@@ -25,8 +27,67 @@ final class AssetStudioMetadataServiceTest {
|
||||
|
||||
assertEquals(AssetStudioGlyphSpecialization.TILESET, snapshot.glyphSpecialization());
|
||||
assertNull(snapshot.sceneBankMetadata());
|
||||
assertNull(snapshot.glyphMaterialMetadata());
|
||||
}
|
||||
|
||||
@Test
|
||||
void keepsGlyphBankWithoutStudioMetadataAsNone() throws Exception {
|
||||
final Path assetRoot = tempDir.resolve("legacy-glyph");
|
||||
Files.createDirectories(assetRoot);
|
||||
|
||||
final AssetStudioMetadataSnapshot snapshot = service.read(assetRoot, AssetFamilyCatalog.GLYPH_BANK);
|
||||
|
||||
assertEquals(AssetStudioGlyphSpecialization.NONE, snapshot.glyphSpecialization());
|
||||
assertNull(snapshot.sceneBankMetadata());
|
||||
assertNull(snapshot.glyphMaterialMetadata());
|
||||
}
|
||||
|
||||
@Test
|
||||
void readsAndWritesGlyphMaterialSupportMetadata() throws Exception {
|
||||
final Path assetRoot = tempDir.resolve("glyph");
|
||||
Files.createDirectories(assetRoot);
|
||||
final AssetStudioGlyphMaterialMetadata metadata = new AssetStudioGlyphMaterialMetadata(
|
||||
List.of(new AssetStudioGlyphMaterialSchema(
|
||||
"schema-1",
|
||||
AssetStudioGlyphMaterialSchemaStatus.OK,
|
||||
2,
|
||||
Map.of(1, "#8B4513", 2, "#00AA00"),
|
||||
List.of(
|
||||
new AssetStudioGlyphMaterialArtifactBinding("artifact-1", "fp-1"),
|
||||
new AssetStudioGlyphMaterialArtifactBinding("artifact-2", "fp-2")))),
|
||||
List.of(new AssetStudioGlyphMaterialPalette(
|
||||
"palette-1",
|
||||
"Forest",
|
||||
"schema-1",
|
||||
2,
|
||||
List.of("#8B4513", "#00AA00"))),
|
||||
null);
|
||||
service.writeGlyphMaterialMetadata(assetRoot, metadata);
|
||||
|
||||
final AssetStudioMetadataSnapshot snapshot = service.read(assetRoot, AssetFamilyCatalog.GLYPH_BANK);
|
||||
|
||||
assertNotNull(snapshot.glyphMaterialMetadata());
|
||||
assertEquals(1, snapshot.glyphMaterialMetadata().schemas().size());
|
||||
assertEquals("schema-1", snapshot.glyphMaterialMetadata().schemas().getFirst().schemaId());
|
||||
assertEquals("#8B4513", snapshot.glyphMaterialMetadata().schemas().getFirst().materialIndices().get(1));
|
||||
assertEquals(1, snapshot.glyphMaterialMetadata().palettes().size());
|
||||
assertEquals("Forest", snapshot.glyphMaterialMetadata().palettes().getFirst().displayName());
|
||||
assertEquals(List.of("#8B4513", "#00AA00"), snapshot.glyphMaterialMetadata().palettes().getFirst().colors());
|
||||
}
|
||||
|
||||
@Test
|
||||
void keepsHtmlRgbAsCanonicalGlyphMaterialColorAndDerivesRgb565() {
|
||||
final AssetStudioGlyphMaterialPalette palette = new AssetStudioGlyphMaterialPalette(
|
||||
"palette-1",
|
||||
"schema-1",
|
||||
1,
|
||||
List.of("#FF0000", "#00FF00", "#0000FF"));
|
||||
|
||||
assertEquals(List.of("#FF0000", "#00FF00", "#0000FF"), palette.colors());
|
||||
assertEquals(List.of(0xF800, 0x07E0, 0x001F), palette.convertedRgb565Colors());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void readsSceneBankSupportMetadataWhenContractIsValid() throws Exception {
|
||||
final Path assetRoot = tempDir.resolve("scene");
|
||||
@@ -36,10 +97,12 @@ final class AssetStudioMetadataServiceTest {
|
||||
"schema_version": 1,
|
||||
"map_width": 20,
|
||||
"map_height": 12,
|
||||
"layer_count": 2,
|
||||
"layer_count": 4,
|
||||
"layers": [
|
||||
{ "index": 1, "name": "Ground", "tilemap": "ground.tmx", "tileset_asset_root": "tilesets/ground" },
|
||||
{ "index": 2, "name": "Collision", "tilemap": "collision.tmx", "tileset_asset_root": "tilesets/ground" }
|
||||
{ "index": 1, "enabled": true, "name": "Ground", "width": 20, "height": 12, "tilemap": "ground.tmx", "tileset_asset_root": "tilesets/ground" },
|
||||
{ "index": 2, "enabled": true, "name": "Collision", "width": 10, "height": 8, "tilemap": "collision.tmx", "tileset_asset_root": "tilesets/ground" },
|
||||
{ "index": 3, "enabled": false, "name": "Layer 3", "width": 20, "height": 12, "tilemap": "layer-3.tmx", "tileset_asset_root": "" },
|
||||
{ "index": 4, "enabled": false, "name": "Layer 4", "width": 20, "height": 12, "tilemap": "layer-4.tmx", "tileset_asset_root": "" }
|
||||
]
|
||||
}
|
||||
""");
|
||||
@@ -49,14 +112,19 @@ final class AssetStudioMetadataServiceTest {
|
||||
assertNotNull(snapshot.sceneBankMetadata());
|
||||
assertEquals(20, snapshot.sceneBankMetadata().mapWidth());
|
||||
assertEquals(12, snapshot.sceneBankMetadata().mapHeight());
|
||||
assertEquals(2, snapshot.sceneBankMetadata().layerCount());
|
||||
assertEquals(4, snapshot.sceneBankMetadata().layerCount());
|
||||
assertEquals(10, snapshot.sceneBankMetadata().layerBindings().get(1).width());
|
||||
assertEquals(8, snapshot.sceneBankMetadata().layerBindings().get(1).height());
|
||||
assertEquals(
|
||||
java.util.List.of("ground.tmx", "collision.tmx"),
|
||||
snapshot.sceneBankMetadata().layerBindings().stream().map(AssetStudioSceneLayerBinding::tilemap).toList());
|
||||
snapshot.sceneBankMetadata().layerBindings().stream()
|
||||
.filter(AssetStudioSceneLayerBinding::enabled)
|
||||
.map(AssetStudioSceneLayerBinding::tilemap)
|
||||
.toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsSceneBankSupportMetadataBeyondWaveOneLayerLimit() throws Exception {
|
||||
void rejectsSceneBankSupportMetadataWhenLayerCountIsNotFixedAtFour() throws Exception {
|
||||
final Path assetRoot = tempDir.resolve("scene-invalid");
|
||||
Files.createDirectories(assetRoot);
|
||||
Files.writeString(assetRoot.resolve(AssetStudioMetadataService.SCENE_BANK_SUPPORT_FILE), """
|
||||
@@ -64,13 +132,11 @@ final class AssetStudioMetadataServiceTest {
|
||||
"schema_version": 1,
|
||||
"map_width": 16,
|
||||
"map_height": 16,
|
||||
"layer_count": 5,
|
||||
"layer_count": 3,
|
||||
"layers": [
|
||||
{ "index": 1, "name": "A", "tilemap": "a.tmx", "tileset_asset_root": "" },
|
||||
{ "index": 2, "name": "B", "tilemap": "b.tmx", "tileset_asset_root": "" },
|
||||
{ "index": 3, "name": "C", "tilemap": "c.tmx", "tileset_asset_root": "" },
|
||||
{ "index": 4, "name": "D", "tilemap": "d.tmx", "tileset_asset_root": "" },
|
||||
{ "index": 5, "name": "E", "tilemap": "e.tmx", "tileset_asset_root": "" }
|
||||
{ "index": 1, "enabled": true, "name": "A", "width": 16, "height": 16, "tilemap": "a.tmx", "tileset_asset_root": "" },
|
||||
{ "index": 2, "enabled": false, "name": "B", "width": 16, "height": 16, "tilemap": "b.tmx", "tileset_asset_root": "" },
|
||||
{ "index": 3, "enabled": false, "name": "C", "width": 16, "height": 16, "tilemap": "c.tmx", "tileset_asset_root": "" }
|
||||
]
|
||||
}
|
||||
""");
|
||||
|
||||
+15
-4
@@ -80,11 +80,16 @@ final class SceneBankWorkflowServiceTest {
|
||||
Map.of(),
|
||||
new AssetWorkspaceBankCompositionDetails(List.of(), List.of(), 0L),
|
||||
List.of(),
|
||||
null,
|
||||
new AssetStudioSceneBankMetadata(
|
||||
8,
|
||||
8,
|
||||
1,
|
||||
List.of(new AssetStudioSceneLayerBinding(1, "Ground", "ground.tmx", "tilesets/missing")),
|
||||
4,
|
||||
List.of(
|
||||
new AssetStudioSceneLayerBinding(true, 1, "Ground", 8, 8, "ground.tmx", "tilesets/missing"),
|
||||
new AssetStudioSceneLayerBinding(false, 2, "Layer 2", 8, 8, "layer-2.tmx", ""),
|
||||
new AssetStudioSceneLayerBinding(false, 3, "Layer 3", 8, 8, "layer-3.tmx", ""),
|
||||
new AssetStudioSceneLayerBinding(false, 4, "Layer 4", 8, 8, "layer-4.tmx", "")),
|
||||
sceneRoot.resolve("scene-bank.studio.json")),
|
||||
AssetWorkspaceSceneBankValidation.NOT_APPLICABLE,
|
||||
List.of());
|
||||
@@ -155,6 +160,7 @@ final class SceneBankWorkflowServiceTest {
|
||||
0L),
|
||||
List.of(),
|
||||
null,
|
||||
null,
|
||||
AssetWorkspaceSceneBankValidation.NOT_APPLICABLE,
|
||||
List.of());
|
||||
}
|
||||
@@ -181,11 +187,16 @@ final class SceneBankWorkflowServiceTest {
|
||||
Map.of(),
|
||||
new AssetWorkspaceBankCompositionDetails(List.of(), List.of(), 0L),
|
||||
List.of(),
|
||||
null,
|
||||
new AssetStudioSceneBankMetadata(
|
||||
16,
|
||||
12,
|
||||
1,
|
||||
List.of(new AssetStudioSceneLayerBinding(1, "Ground", "ground.tmx", "tilesets/overworld")),
|
||||
4,
|
||||
List.of(
|
||||
new AssetStudioSceneLayerBinding(true, 1, "Ground", 16, 12, "ground.tmx", "tilesets/overworld"),
|
||||
new AssetStudioSceneLayerBinding(false, 2, "Layer 2", 16, 12, "layer-2.tmx", ""),
|
||||
new AssetStudioSceneLayerBinding(false, 3, "Layer 3", 16, 12, "layer-3.tmx", ""),
|
||||
new AssetStudioSceneLayerBinding(false, 4, "Layer 4", 16, 12, "layer-4.tmx", "")),
|
||||
assetRoot.resolve("scene-bank.studio.json")),
|
||||
AssetWorkspaceSceneBankValidation.NOT_APPLICABLE,
|
||||
List.of());
|
||||
|
||||
+8
-2
@@ -105,6 +105,7 @@ final class TiledAssetGenerationServiceTest {
|
||||
0L),
|
||||
List.of(),
|
||||
null,
|
||||
null,
|
||||
AssetWorkspaceSceneBankValidation.NOT_APPLICABLE,
|
||||
List.of());
|
||||
}
|
||||
@@ -131,11 +132,16 @@ final class TiledAssetGenerationServiceTest {
|
||||
Map.of(),
|
||||
new AssetWorkspaceBankCompositionDetails(List.of(), List.of(), 0L),
|
||||
List.of(),
|
||||
null,
|
||||
new AssetStudioSceneBankMetadata(
|
||||
16,
|
||||
12,
|
||||
1,
|
||||
List.of(new AssetStudioSceneLayerBinding(1, "Ground", "ground.tmx", "tilesets/overworld")),
|
||||
4,
|
||||
List.of(
|
||||
new AssetStudioSceneLayerBinding(true, 1, "Ground", 16, 12, "ground.tmx", "tilesets/overworld"),
|
||||
new AssetStudioSceneLayerBinding(false, 2, "Layer 2", 16, 12, "layer-2.tmx", ""),
|
||||
new AssetStudioSceneLayerBinding(false, 3, "Layer 3", 16, 12, "layer-3.tmx", ""),
|
||||
new AssetStudioSceneLayerBinding(false, 4, "Layer 4", 16, 12, "layer-4.tmx", "")),
|
||||
assetRoot.resolve("scene-bank.studio.json")),
|
||||
AssetWorkspaceSceneBankValidation.NOT_APPLICABLE,
|
||||
List.of());
|
||||
|
||||
Reference in New Issue
Block a user