Skip to content

Commit

Permalink
Merge pull request #7 from Mojang/mammerla-schemawarningsdoclink
Browse files Browse the repository at this point in the history
JSON parsing & val improvements
  • Loading branch information
mammerla authored Dec 20, 2023
2 parents 2963587 + d8f45f7 commit eab41a9
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 30 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

## [0.1.64]

### Updated

- Improved warning messages for schema errors with a bit more detail
- Fixed doc link

## [0.1.63]

### Added
Expand Down
3 changes: 1 addition & 2 deletions app/src/UX/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,6 @@ export default class Home extends Component<IHomeProps, IHomeState> {
</span>
);
}

let effectArea = <></>;

if (this.state.effect === HomeEffect.dragOver) {
Expand Down Expand Up @@ -1123,7 +1122,7 @@ export default class Home extends Component<IHomeProps, IHomeState> {
<div className="home-header">
<div className="home-header-image">&#160;</div>
<div className="home-header-sublink">
<a href={constants.homeUrl} className="home-header-docsLink" target="_blank" rel="noreferrer noopener">
<a href={constants.homeUrl + "/docs/"} className="home-header-docsLink" target="_blank" rel="noreferrer noopener">
Docs
</a>
&#160;&#160;/&#160;&#160;
Expand Down
12 changes: 10 additions & 2 deletions app/src/UX/ImageEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,21 @@ export default class ImageEditor extends Component<IImageEditorProps, IImageEdit
async persist() {}

render() {
return (
<div className="ie-outer">
let editToggle = <></>;

if (!this.props.readOnly || !this.state.isView) {
editToggle = (
<div className="ie-float">
<Button onClick={this._toggleEdit}>
<FontAwesomeIcon icon={faEdit} className="fa-lg" />
</Button>
</div>
);
}

return (
<div className="ie-outer">
{editToggle}
<div className="ie-contents" ref={this.rootElt}></div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion app/src/UX/JsonEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default class JsonEditor extends Component<IJsonEditorProps, IJsonEditorS
enableSchemaRequest: false,
schemas: [
{
uri: constants.homeUrl + "/res/latest/schemas/Minecraft-bedrock-json-schemas-main/" + schemaPath,
uri: constants.homeUrl + "/res/latest/schemas/" + schemaPath,
fileMatch: [modelUriToStr],
schema: schemaContent,
},
Expand Down
18 changes: 15 additions & 3 deletions app/src/UX/ProjectItemList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,8 @@ export default class ProjectItemList extends Component<IProjectItemListProps, IP
case ProjectItemType.renderControllerJson:
return "render ctlr";

case ProjectItemType.itemTextureJson:
return "texture";
case ProjectItemType.uiTextureJson:
return "ui texture";

case ProjectItemType.uiJson:
return "ui";
Expand Down Expand Up @@ -777,6 +777,18 @@ export default class ProjectItemList extends Component<IProjectItemListProps, IP
case ProjectItemType.worldTemplateManifestJson:
return "wtmanifest";

case ProjectItemType.itemTextureJson:
return "item tx";

case ProjectItemType.terrainTextureJson:
return "terrain tx";

case ProjectItemType.flipBookTexturesJson:
return "flipbook";

case ProjectItemType.globalVariablesJson:
return "ui var";

case ProjectItemType.json:
return "json";
}
Expand Down Expand Up @@ -1037,7 +1049,7 @@ export default class ProjectItemList extends Component<IProjectItemListProps, IP
projectItem.itemType === ProjectItemType.uiJson ||
projectItem.itemType === ProjectItemType.lang ||
projectItem.itemType === ProjectItemType.languagesCatalogResourceJson ||
projectItem.itemType === ProjectItemType.itemTextureJson ||
projectItem.itemType === ProjectItemType.uiTextureJson ||
projectItem.itemType === ProjectItemType.attachableResourceJson)
) {
return false;
Expand Down
9 changes: 7 additions & 2 deletions app/src/app/IProjectItemData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import IGitHubInfo from "./IGitHubInfo";

export const MaxItemTypes = 90;
export const MaxItemTypes = 94;

export enum ProjectItemType {
unknown = 0,
Expand Down Expand Up @@ -38,7 +38,7 @@ export enum ProjectItemType {
modelJson = 32,
particleJson = 33,
renderControllerJson = 34,
itemTextureJson = 35,
uiTextureJson = 35,
uiJson = 36,
languagesCatalogResourceJson = 37,
biomeBehaviorJson = 38,
Expand Down Expand Up @@ -93,6 +93,11 @@ export enum ProjectItemType {
geometry = 87,
lightingJson = 88,
textureSetJson = 89,
fogJson = 90,
flipBookTexturesJson = 91,
itemTextureJson = 92,
terrainTextureJson = 93,
globalVariablesJson = 94,
}

export enum ProjectItemStorageType {
Expand Down
30 changes: 25 additions & 5 deletions app/src/app/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2063,19 +2063,39 @@ export default class Project {
folderPath.indexOf("/render_controllers/") >= 0
) {
newJsonType = ProjectItemType.renderControllerJson;
} else if (
(folderContext === FolderContext.resourcePack || folderContext === FolderContext.resourcePackSubPack) &&
projectPath.endsWith("terrain_texture.json")
) {
newJsonType = ProjectItemType.terrainTextureJson;
} else if (
(folderContext === FolderContext.resourcePack || folderContext === FolderContext.resourcePackSubPack) &&
projectPath.endsWith("_global_variables.json")
) {
newJsonType = ProjectItemType.globalVariablesJson;
} else if (
(folderContext === FolderContext.resourcePack || folderContext === FolderContext.resourcePackSubPack) &&
projectPath.endsWith("flipbook_textures.json")
) {
newJsonType = ProjectItemType.flipBookTexturesJson;
} else if (
(folderContext === FolderContext.resourcePack || folderContext === FolderContext.resourcePackSubPack) &&
projectPath.endsWith("item_texture.json")
) {
newJsonType = ProjectItemType.itemTextureJson;
} else if (folderContext === FolderContext.resourcePack && folderPath.indexOf("/materials/") >= 0) {
newJsonType = ProjectItemType.materialSetJson;
} else if (folderContext === FolderContext.resourcePack && folderPath.indexOf("/sounds/") >= 0) {
newJsonType = ProjectItemType.soundDefinitionJson;
} else if (folderPath.indexOf("/texts/") >= 0 || baseName === "languages") {
newJsonType = ProjectItemType.languagesCatalogResourceJson;
} else if (
(folderContext === FolderContext.resourcePack && folderPath.indexOf("/texture_sets/") >= 0) ||
((folderContext === FolderContext.resourcePack ||
folderContext === FolderContext.resourcePackSubPack) &&
folderPath.indexOf("/textures/") >= 0)
(folderContext === FolderContext.resourcePack || folderContext === FolderContext.resourcePackSubPack) &&
folderPath.indexOf("/textures/ui/") >= 0
) {
newJsonType = ProjectItemType.itemTextureJson;
newJsonType = ProjectItemType.uiTextureJson;
} else if (folderContext === FolderContext.resourcePack && folderPath.indexOf("/texture_sets/") >= 0) {
newJsonType = ProjectItemType.textureSetJson;
} else if (
(folderContext === FolderContext.resourcePack || folderContext === FolderContext.resourcePackSubPack) &&
folderPath.indexOf("/lighting/") >= 0
Expand Down
40 changes: 31 additions & 9 deletions app/src/app/ProjectItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ export default class ProjectItem {
return "Particle";
case ProjectItemType.renderControllerJson:
return "Render controller";
case ProjectItemType.itemTextureJson:
return "Texture";
case ProjectItemType.uiTextureJson:
return "UI Texture";
case ProjectItemType.uiJson:
return "User interface";
case ProjectItemType.languagesCatalogResourceJson:
Expand Down Expand Up @@ -329,6 +329,14 @@ export default class ProjectItem {
return "Texture Sets";
case ProjectItemType.lightingJson:
return "Lighting";
case ProjectItemType.flipBookTexturesJson:
return "Flipbook Textures";
case ProjectItemType.itemTextureJson:
return "Item Texture";
case ProjectItemType.terrainTextureJson:
return "Terrain Texture";
case ProjectItemType.globalVariablesJson:
return "UI Global Variables";
default:
return "Unknown";
}
Expand All @@ -351,8 +359,6 @@ export default class ProjectItem {
return "behavior/animations/animations.json";
case ProjectItemType.blockTypeBehaviorJson:
return "behavior/blocks/blocks.json";
case ProjectItemType.blockMaterialsBehaviorJson:
return "behavior/blocks/blocks.json";
case ProjectItemType.itemTypeBehaviorJson:
return "behavior/items/items.json";
case ProjectItemType.lootTableBehaviorJson:
Expand All @@ -361,6 +367,8 @@ export default class ProjectItem {
return "behavior/blocks/blocks.json";
case ProjectItemType.dialogueBehaviorJson:
return "behavior/dialogue/dialogue.json";
case ProjectItemType.entityTypeBehaviorJson:
return "behavior/entities/entities.json";
case ProjectItemType.blocksCatalogResourceJson:
return "resource/blocks.json";
case ProjectItemType.soundsCatalogResourceJson:
Expand All @@ -369,18 +377,22 @@ export default class ProjectItem {
return "resource/animations/actor_animation.json";
case ProjectItemType.animationControllerResourceJson:
return "resource/animation_controllers/animation_controller.json";
case ProjectItemType.fogJson:
return "resource/fog/fog.json";
case ProjectItemType.entityTypeResourceJson:
return "resource/entity/entity.json";
case ProjectItemType.fogResourceJson:
return "resource/fog/fog.json";
case ProjectItemType.modelJson:
return "resource/models/entity/model_entity.json";
case ProjectItemType.biomeResourceJson:
return "resource/biomes_client.json";
case ProjectItemType.particleJson:
return "resource/particles/particles.json";
case ProjectItemType.renderControllerJson:
return "resource/render_controllers/render_controllers.json";
case ProjectItemType.itemTextureJson:
return "resource/textures/item_texture.json";
// case ProjectItemType.uiTextureJson:
// return "resource/textures/ui_texture_definition.json";
case ProjectItemType.languagesCatalogResourceJson:
return "language/languages.json";
case ProjectItemType.featureBehaviorJson:
Expand All @@ -400,15 +412,25 @@ export default class ProjectItem {
case ProjectItemType.itemTypeResourceJson:
return "resource/items/items.json";
case ProjectItemType.materialsResourceJson:
return "resource/items/materials.json";
return "resource/materials/materials.json";
case ProjectItemType.musicDefinitionJson:
return "resource/sounds/music_definitions.json";
case ProjectItemType.soundDefinitionJson:
return "resource/sounds/sound_definitions.json";
case ProjectItemType.blockTypeResourceJson:
return "resource/blocks.json";

// uiJson = 36,
case ProjectItemType.uiJson:
return "resource/ui/ui.json";
case ProjectItemType.tickJson:
return "behavior/functions/tick.json";
case ProjectItemType.flipBookTexturesJson:
return "resource/textures/flipbook_textures.json";
case ProjectItemType.itemTextureJson:
return "resource/textures/item_texture.json";
case ProjectItemType.terrainTextureJson:
return "resource/textures/terrain_texture.json";
case ProjectItemType.globalVariablesJson:
return "resource/ui/_global_variables.json";

default:
return undefined;
Expand Down
10 changes: 9 additions & 1 deletion app/src/info/PathLengthFileGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ export default class PathLengthFileGenerator implements IProjectFileInfoGenerato

let path = file.storageRelativePath;

const packStarterFolderHints = ["bp", "rp", "resource pack", "resource packs", "behavior pack", "behavior packs"];
const packStarterFolderHints = [
"bp",
"rp",
"resource pack",
"resource packs",
"behavior pack",
"behavior packs",
"world_template",
];

for (const hint of packStarterFolderHints) {
const hintIndex = path.toLowerCase().indexOf("/" + hint + "/");
Expand Down
48 changes: 43 additions & 5 deletions app/src/info/SchemaItemInfoGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,19 @@ export default class SchemaItemInfoGenerator implements IProjectInfoItemGenerato

try {
contentObj = JSON.parse(content);
} catch (e) {
items.push(new ProjectInfoItem(InfoItemType.error, this.id, 1, "Could not parse JSON - " + e, projectItem));
} catch (e: any) {
let errorMess: any = e;

if (e.message) {
errorMess = e.message;
}

items.push(
new ProjectInfoItem(InfoItemType.error, this.id, 1, "Could not parse JSON - " + errorMess, projectItem)
);
}

const result = await val(contentObj);
const result = val(contentObj);

if (!result && val.errors) {
for (let i = 0; i < val.errors.length; i++) {
Expand Down Expand Up @@ -135,14 +143,44 @@ export default class SchemaItemInfoGenerator implements IProjectInfoItemGenerato
errorContent = serial;
}

let data = undefined;

if (error.params) {
for (const key in error.params) {
let val = error.params[key];

if (
typeof val === "string" &&
key !== "type" &&
key !== "pattern" &&
key !== "missingProperty" &&
key !== "comparison" &&
key !== "failingKeyword"
) {
// force line breaks in long strings
if (val.length > 80 && val.indexOf(" ") < 0) {
val = val.replace(/,/gi, ", ");
}

if (data === undefined) {
data = "";
} else {
data += " ";
}

data += "(" + key + ": " + val + ")";
}
}
}

items.push(
new ProjectInfoItem(
InfoItemType.error,
InfoItemType.warning,
this.id,
100 + projectItem.itemType,
message,
projectItem,
undefined,
data,
undefined,
errorContent
)
Expand Down

0 comments on commit eab41a9

Please sign in to comment.