packer & compiler test

This commit is contained in:
2026-03-24 13:42:57 +00:00
parent d7a26473c8
commit d16a987949
9 changed files with 430 additions and 341 deletions
@@ -37,6 +37,8 @@ import java.util.*;
import java.util.stream.Stream;
public final class FileSystemPackerWorkspaceService implements PackerWorkspaceService {
private static final int TILE_BANK_COLOR_KEY_RGB565 = 0xF81F;
private final ObjectMapper mapper;
private final PackerWorkspaceFoundation workspaceFoundation;
private final PackerAssetDetailsService detailsService;
@@ -863,6 +865,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
final List<Map<String, Object>> assetTable = new ArrayList<>();
final List<Map<String, Object>> preload = new ArrayList<>();
final List<Map<String, Object>> assetTableMetadata = new ArrayList<>();
final Map<String, Integer> nextPreloadSlotByBankType = new HashMap<>();
final ByteArrayOutputStream payload = new ByteArrayOutputStream();
for (PackedAsset packedAsset : packedAssets) {
final int offset = payload.size();
@@ -877,7 +880,11 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
"codec", packedAsset.codec(),
"metadata", packedAsset.metadata())));
if (packedAsset.preloadEnabled()) {
preload.add(new LinkedHashMap<>(Map.of("asset_id", packedAsset.assetId())));
final int slot = nextPreloadSlotByBankType.getOrDefault(packedAsset.bankType(), 0);
nextPreloadSlotByBankType.put(packedAsset.bankType(), slot + 1);
preload.add(new LinkedHashMap<>(Map.of(
"asset_id", packedAsset.assetId(),
"slot", slot)));
}
assetTableMetadata.add(new LinkedHashMap<>(Map.of(
"asset_id", packedAsset.assetId(),
@@ -1015,13 +1022,16 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
if (paletteIndex < 0 || paletteIndex >= 64) {
continue;
}
final int paletteBaseOffset = (paletteIndex * 16) * 2;
bytes[paletteBaseOffset] = (byte) (TILE_BANK_COLOR_KEY_RGB565 & 0xFF);
bytes[paletteBaseOffset + 1] = (byte) ((TILE_BANK_COLOR_KEY_RGB565 >>> 8) & 0xFF);
final JsonNode convertedNode = paletteNode.path("convertedRgb565");
if (!convertedNode.isArray()) {
continue;
}
for (int colorIndex = 0; colorIndex < Math.min(16, convertedNode.size()); colorIndex += 1) {
for (int colorIndex = 0; colorIndex < Math.min(15, convertedNode.size()); colorIndex += 1) {
final int rgb565 = convertedNode.get(colorIndex).asInt(0);
final int baseOffset = ((paletteIndex * 16) + colorIndex) * 2;
final int baseOffset = ((paletteIndex * 16) + colorIndex + 1) * 2;
bytes[baseOffset] = (byte) (rgb565 & 0xFF);
bytes[baseOffset + 1] = (byte) ((rgb565 >>> 8) & 0xFF);
}
@@ -1042,12 +1052,13 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
}
private byte[] buildPrelude(int headerLength) {
final int preludeLength = 24;
final int preludeLength = 32;
final ByteBuffer buffer = ByteBuffer.allocate(preludeLength).order(ByteOrder.LITTLE_ENDIAN);
buffer.put((byte) 'P').put((byte) 'P').put((byte) 'A').put((byte) 'K');
buffer.put((byte) 'A').put((byte) 'S').put((byte) 'P').put((byte) 'A');
buffer.putInt(1);
buffer.putInt(headerLength);
buffer.putInt(preludeLength + headerLength);
buffer.putLong((long) preludeLength + headerLength);
buffer.putInt(0);
buffer.putInt(0);
buffer.putInt(0);
return buffer.array();