Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ide/vscode/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const Version = "9.0.30";
export const Version = "9.0.31";
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OffsetWord } from 'bc-minecraft-bedrock-shared';
import { Errors } from '../..';
import { DiagnosticsBuilder, DiagnosticSeverity } from '../../../types';
import { DiagnosticsBuilder } from '../../../types';
import { check_definition_value } from '../../definitions';

export function diagnose_structure_implementation(
Expand All @@ -9,37 +9,20 @@ export function diagnose_structure_implementation(
): boolean {
const strId = typeof id === 'string' ? id : id.text;

//If it has a slash it needs ""
if (strId.includes('/')) {
if (strId.startsWith('"') && strId.endsWith('"')) {
// Do nothing
} else {
diagnoser.add(
id,
`A structure id with '/' needs quotes surrounding it: ${strId} => "${strId}"`,
DiagnosticSeverity.error,
'behaviorpack.mcstructure.invalid',
);
}

//Project has structures
const struc = diagnoser.context.getProjectData().behaviors.structures.get(strId, diagnoser.project);
if (struc !== undefined) {
return true;
}
}

const data = diagnoser.context.getProjectData().projectData;

// Check general structures (vanilla etc.)
if (data.general.structures.has(strId)) return true;

//structures can be identified with : or /
if (strId.includes(':')) {
let cid = strId.replace('mystructure:', '').replace(':', '/');
if (!cid.includes('/')) cid = cid.replace(/"/g, '');
if (check_definition_value(diagnoser.project.definitions.structure, cid, diagnoser)) return true;
if (data.behaviorPacks.structures.has(cid)) return true;
if (data.general.structures.has(cid)) return true;
}
// Check project-defined structures
const struc = diagnoser.context.getProjectData().behaviors.structures.get(strId, diagnoser.project);
if (struc !== undefined) return true;

// Check definitions (from project configuration)
if (check_definition_value(diagnoser.project.definitions.structure, strId, diagnoser)) return true;

// Check behavior pack structures collection
if (data.behaviorPacks.structures.has(strId)) return true;

//Nothing then report error
Errors.missing('behaviors', 'structures', strId, diagnoser, id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,46 @@ describe("BehaviorPack", () => {
data = diagnoser.context.getProjectData().projectData;
});

it("quotes", () => {
it("simple namespace:name no errors", () => {
data.behaviorPacks.packs[0].structures.set({
id: "test/example",
id: "puff:coin1",
documentation: "",
location: { position: 0, uri: "" },
});

diagnose_structure_implementation({ offset: 0, text: "test/example" }, diagnoser);
diagnose_structure_implementation({ offset: 0, text: "test:example" }, diagnoser);
diagnose_structure_implementation({ offset: 0, text: "puff:coin1" }, diagnoser);

diagnoser.expectAmount(1);
diagnoser.expectEmpty();
});

it("no errors", () => {
it("deep path namespace:name no errors", () => {
data.behaviorPacks.packs[0].structures.set({
id: '"test/example"',
id: "stuff:towers/diamond",
documentation: "",
location: { position: 0, uri: "" },
});

diagnose_structure_implementation({ offset: 0, text: '"test/example"' }, diagnoser);
diagnose_structure_implementation({ offset: 0, text: '"test:example"' }, diagnoser);
diagnose_structure_implementation({ offset: 0, text: "stuff:towers/diamond" }, diagnoser);

diagnoser.expectEmpty();
});

it("missing", () => {
it("mystructure namespace for root structures", () => {
data.behaviorPacks.packs[0].structures.set({
id: '"test/example"',
id: "mystructure:house",
documentation: "",
location: { position: 0, uri: "" },
});

diagnose_structure_implementation({ offset: 0, text: '"t/example"' }, diagnoser);
diagnose_structure_implementation({ offset: 0, text: '"t:example"' }, diagnoser);
diagnose_structure_implementation({ offset: 0, text: "mystructure:house" }, diagnoser);

diagnoser.expectAmount(2);
diagnoser.expectEmpty();
});

it("missing structure reports error", () => {
diagnose_structure_implementation({ offset: 0, text: "puff:coin1" }, diagnoser);

diagnoser.expectAmount(1);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`Structure "empty/air_1" from F:/Temp2/world/behavior_packs/EW-BP/structures/empty/air_1.mcstructure 1`] = `
exports[`Structure empty:air_1 from F:/Temp2/world/behavior_packs/EW-BP/structures/empty/air_1.mcstructure 1`] = `
{
"documentation": "McStructure: "empty/air_1"",
"id": ""empty/air_1"",
"documentation": "McStructure: empty:air_1",
"id": "empty:air_1",
"location": {
"position": 0,
"uri": "F:/Temp2/world/behavior_packs/EW-BP/structures/empty/air_1.mcstructure",
},
}
`;

exports[`Structure "empty/air_1" from F:\\Temp2\\world\\behavior_packs\\EW-BP\\structures\\empty\\air_1.mcstructure 1`] = `
exports[`Structure empty:air_1 from F:\\Temp2\\world\\behavior_packs\\EW-BP\\structures\\empty\\air_1.mcstructure 1`] = `
{
"documentation": "McStructure: "empty/air_1"",
"id": ""empty/air_1"",
"documentation": "McStructure: empty:air_1",
"id": "empty:air_1",
"location": {
"position": 0,
"uri": "F:\\Temp2\\world\\behavior_packs\\EW-BP\\structures\\empty\\air_1.mcstructure",
},
}
`;

exports[`Structure "empty/temp/air_1" from F:/Temp2/world/behavior_packs/EW-BP/structures/empty/temp/air_1.mcstructure 1`] = `
exports[`Structure empty:temp/air_1 from F:/Temp2/world/behavior_packs/EW-BP/structures/empty/temp/air_1.mcstructure 1`] = `
{
"documentation": "McStructure: "empty/temp/air_1"",
"id": ""empty/temp/air_1"",
"documentation": "McStructure: empty:temp/air_1",
"id": "empty:temp/air_1",
"location": {
"position": 0,
"uri": "F:/Temp2/world/behavior_packs/EW-BP/structures/empty/temp/air_1.mcstructure",
},
}
`;

exports[`Structure mystructure:house from F:/Temp2/world/behavior_packs/EW-BP/structures/house.mcstructure 1`] = `
{
"documentation": "McStructure: mystructure:house",
"id": "mystructure:house",
"location": {
"position": 0,
"uri": "F:/Temp2/world/behavior_packs/EW-BP/structures/house.mcstructure",
},
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@ export function process(doc: TextDocument): Structure | undefined {
if (index < 0) return undefined;
index += 11;

let id = uri.substring(index, uri.length).replace(/\\/g, '/');
id = id.replace('.mcstructure', '');
let path = uri.substring(index, uri.length).replace(/\\/g, '/');
path = path.replace('.mcstructure', '');

if (id.includes('/')) {
id = '"' + id + '"';
// The first path segment is the namespace; the rest is the identifier.
// Files directly in the structures/ folder use the 'mystructure' namespace.
const slashIndex = path.indexOf('/');
let id: string;

if (slashIndex < 0) {
id = `mystructure:${path}`;
} else {
const namespace = path.substring(0, slashIndex);
const name = path.substring(slashIndex + 1);
id = `${namespace}:${name}`;
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ describe('Structure', () => {
const data: { uri: string; result: string }[] = [
{
uri: 'F:\\Temp2\\world\\behavior_packs\\EW-BP\\structures\\empty\\air_1.mcstructure',
result: '"empty/air_1"',
result: 'empty:air_1',
},
{
uri: 'F:/Temp2/world/behavior_packs/EW-BP/structures/empty/air_1.mcstructure',
result: '"empty/air_1"',
result: 'empty:air_1',
},
{
uri: 'F:/Temp2/world/behavior_packs/EW-BP/structures/empty/temp/air_1.mcstructure',
result: '"empty/temp/air_1"',
result: 'empty:temp/air_1',
},
{
uri: 'F:/Temp2/world/behavior_packs/EW-BP/structures/house.mcstructure',
result: 'mystructure:house',
},
];

Expand Down