Skip to content

Commit

Permalink
feat(val): Texture + Pack test additions (#51)
Browse files Browse the repository at this point in the history
* Texture + Pack test additions
  • Loading branch information
mammerla authored Feb 11, 2025
1 parent acf6111 commit b4d9482
Show file tree
Hide file tree
Showing 26 changed files with 505 additions and 95 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ See the [changelog](CHANGELOG.md) for detailed updates and notes. If you have is

See the [Project Structure](ProjectStructure.md) file for a look at the structure of the codebase including a tour of major types.

Note that commonly, while working on this, most work is done from the "app" folder; all the default project settings are opened from there.

Please note that, at this time, we are not able to accept pull request contributions from the broader community.

## Using Creator Tools
Expand Down
2 changes: 1 addition & 1 deletion app/reslist/packs-preview.resources.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"url": "https://github.com/Mojang/bedrock-samples/archive/706bce4c7df169f79f36e0302e1fe9f930e4af3e.zip",
"url": "https://github.com/Mojang/bedrock-samples/archive/7f2a5f8ed0c12aed2eb5822f71700e03afd08869.zip",
"ignoreFirstFolder": true,
"exclude": [
"documentation/",
Expand Down
2 changes: 1 addition & 1 deletion app/reslist/packs.resources.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"url": "https://github.com/Mojang/bedrock-samples/archive/5ce65764d3426f2a1f600f4156412f829c178b55.zip",
"url": "https://github.com/Mojang/bedrock-samples/archive/43ca2795c201b6fff53f38597c4d01f6c4593e1a.zip",
"ignoreFirstFolder": true,
"exclude": [
"documentation/",
Expand Down
6 changes: 4 additions & 2 deletions app/src/app/IProjectItemData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import IGitHubInfo from "./IGitHubInfo";

export const MaxItemTypes = 125;
export const MaxItemTypes = 128;

export enum ProjectItemCategory {
assets,
Expand Down Expand Up @@ -141,7 +141,9 @@ export enum ProjectItemType {
prettierRcJson = 122,
skinCatalogJson = 123,
tagsMetadata = 124,
blockCulling = 125,
personaManifestJson = 125,
personaPackFolder = 126,
blockCulling = 127,
}

export enum ProjectItemStorageType {
Expand Down
32 changes: 32 additions & 0 deletions app/src/app/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export enum FolderContext {
resourcePackSubPack = 9,
metaData = 10,
libFolder = 11,
persona = 12,
}

export const ProjectTargetStrings = [
Expand Down Expand Up @@ -1747,6 +1748,11 @@ export default class Project {
folderContext = FolderContext.resourcePackSubPack;
} else if (MinecraftUtilities.pathLooksLikeSkinPackName(folderPathA) && folderContext === FolderContext.unknown) {
folderContext = FolderContext.skinPack;
} else if (
MinecraftUtilities.pathLooksLikePersonaPackName(folderPathA) &&
folderContext === FolderContext.unknown
) {
folderContext = FolderContext.persona;
} else if (
MinecraftUtilities.pathLooksLikeWorldFolderName(folderPathA) &&
folderContext === FolderContext.unknown
Expand All @@ -1766,6 +1772,21 @@ export default class Project {
}
}

if (
folderContext === FolderContext.unknown &&
(folder.files["manifest.json"] || folder.files["pack_manifest.json"]) &&
!folder.files["level.dat"] &&
!folder.files["levelname.txt"]
) {
for (const folderName in folder.folders) {
if (folderName) {
if (folderName.toLowerCase() === "persona" || folderName.toLowerCase().startsWith("persona_")) {
folderContext = FolderContext.persona;
}
}
}
}

if (
folderContext === FolderContext.unknown &&
(folder.files["manifest.json"] || folder.files["pack_manifest.json"]) &&
Expand Down Expand Up @@ -1912,6 +1933,9 @@ export default class Project {
} else if (folderContext === FolderContext.skinPack) {
newPiType = ProjectItemType.skinPackManifestJson;
tag = "skinpackmanifest";
} else if (folderContext === FolderContext.persona) {
newPiType = ProjectItemType.personaManifestJson;
tag = "personapackmanifest";
} else if (folderContext === FolderContext.world) {
newPiType = ProjectItemType.worldTemplateManifestJson;
tag = "worldtemplatemanifest";
Expand Down Expand Up @@ -3822,6 +3846,12 @@ export default class Project {
if (file && file.parentFolder) {
this.ensurePackByFolder(file.parentFolder, PackType.skin);
}
} else if (item.itemType === ProjectItemType.personaManifestJson) {
const file = item.file;

if (file && file.parentFolder) {
this.ensurePackByFolder(file.parentFolder, PackType.persona);
}
}
}
}
Expand Down Expand Up @@ -3935,6 +3965,8 @@ export default class Project {
itemType = ProjectItemType.resourcePackFolder;
} else if (packType === PackType.skin) {
itemType = ProjectItemType.skinPackFolder;
} else if (packType === PackType.persona) {
itemType = ProjectItemType.personaPackFolder;
}

const folderPath = folder.getFolderRelativePath(this.projectFolder);
Expand Down
8 changes: 3 additions & 5 deletions app/src/app/ProjectItemUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ export default class ProjectItemUtilities {
return { itemType: ProjectItemType.particleJson, packType: PackType.resource };
} else if (firstHundred.indexOf('"render_controllers"') >= 0) {
return { itemType: ProjectItemType.renderControllerJson, packType: PackType.resource };
} else if (firstHundred.indexOf('"block_culling"') >= 0) {
return { itemType: ProjectItemType.blockCulling, packType: PackType.resource };
} else if (firstHundred.indexOf('"namespace"') >= 0) {
return { itemType: ProjectItemType.uiJson, packType: PackType.resource };
} else if (firstHundred.indexOf('"sound_definitions"') >= 0) {
Expand Down Expand Up @@ -374,7 +372,7 @@ export default class ProjectItemUtilities {
case ProjectItemType.engineOrderingJson:
case ProjectItemType.commandSetDefinitionJson:
case ProjectItemType.skinPackManifestJson:
case ProjectItemType.blockCulling:
case ProjectItemType.personaManifestJson:
case ProjectItemType.vsCodeLaunchJson:
case ProjectItemType.vsCodeTasksJson:
case ProjectItemType.vsCodeSettingsJson:
Expand Down Expand Up @@ -534,8 +532,6 @@ export default class ProjectItemUtilities {
return "Particle";
case ProjectItemType.renderControllerJson:
return "Render controller";
case ProjectItemType.blockCulling:
return "Block culling";
case ProjectItemType.uiJson:
return "User interface";
case ProjectItemType.languagesCatalogResourceJson:
Expand Down Expand Up @@ -608,6 +604,8 @@ export default class ProjectItemUtilities {
return "Command definition";
case ProjectItemType.skinPackManifestJson:
return "Skin pack manifest";
case ProjectItemType.personaManifestJson:
return "Persona manifest";
case ProjectItemType.blockTypeBaseJs:
return "Block type base JavaScript";
case ProjectItemType.blockTypeBaseTs:
Expand Down
2 changes: 1 addition & 1 deletion app/src/dataform/IFormDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import IField from "./IField";

export default interface IFormDefinition {
id?: string;
id: string;
title?: string;
description?: string;
fields: IField[];
Expand Down
50 changes: 50 additions & 0 deletions app/src/info/TextureImageInfoGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import ProjectInfoUtilities from "./ProjectInfoUtilities";
export enum TextureImageInfoGeneratorTest {
textureImages = 1,
imageProcessingError = 401,
individualTextureMemoryExceedsBudget = 402,
totalTextureMemoryExceedsBudget = 403,
}

export default class TextureImageInfoGenerator implements IProjectInfoGenerator {
Expand Down Expand Up @@ -48,6 +50,7 @@ export default class TextureImageInfoGenerator implements IProjectInfoGenerator

const itemsCopy = project.getItemsCopy();

let totalTextureMemory = 0;
for (const projectItem of itemsCopy) {
if (projectItem.itemType === ProjectItemType.texture) {
await projectItem.ensureFileStorage();
Expand Down Expand Up @@ -82,13 +85,47 @@ export default class TextureImageInfoGenerator implements IProjectInfoGenerator
const results = await exifr.parse();

if (results.ImageWidth && results.ImageHeight) {
const textureMem = Math.pow(2, Math.ceil(Math.log2(results.ImageWidth * results.ImageHeight * 4)));

textureImagePi.spectrumIntFeature("ImageWidth", results.ImageWidth);
textureImagePi.spectrumIntFeature("ImageHeight", results.ImageHeight);
textureImagePi.spectrumIntFeature("ImageSize", results.ImageWidth * results.ImageHeight);
textureImagePi.spectrumIntFeature("EstimatedTextureMemory", textureMem);

if (!isVanilla) {
textureImagePi.spectrumIntFeature("NonVanillaImageSize", results.ImageWidth * results.ImageHeight);
}

totalTextureMemory += textureMem;

// Empirical threshold for loose textures set below 2048*2048 per texture
let individualMemoryBudget = 16000000;

if (projectItem.parentItems) {
for (const itemRelationship of projectItem.parentItems) {
if (
itemRelationship.parentItem.itemType === ProjectItemType.terrainTextureCatalogResourceJson ||
itemRelationship.parentItem.itemType === ProjectItemType.itemTextureJson
) {
// Empirical threshold for atlas textures set below 256*256 per texture
individualMemoryBudget = 200000;
break;
}
}
}

if (textureMem > individualMemoryBudget) {
items.push(
new ProjectInfoItem(
InfoItemType.warning,
this.id,
TextureImageInfoGeneratorTest.individualTextureMemoryExceedsBudget,
`Individual texture memory exceeds budget`,
projectItem,
textureMem
)
);
}
}
} catch (e: any) {
items.push(
Expand All @@ -110,6 +147,19 @@ export default class TextureImageInfoGenerator implements IProjectInfoGenerator
}
}

if (totalTextureMemory > 100000000) {
items.push(
new ProjectInfoItem(
InfoItemType.error,
this.id,
TextureImageInfoGeneratorTest.totalTextureMemoryExceedsBudget,
`Total texture memory exceeds budget`,
undefined,
totalTextureMemory
)
);
}

return items;
}
}
Loading

0 comments on commit b4d9482

Please sign in to comment.