Skip to content

Commit

Permalink
Add texture validation for particles
Browse files Browse the repository at this point in the history
  • Loading branch information
Xterionix authored Feb 10, 2025
1 parent e5cbf4f commit 3222a60
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/Lib/Diagnostics/ResourcePack/Particle/entry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { DocumentDiagnosticsBuilder } from "../../../Types";
import { Internal } from 'bc-minecraft-bedrock-project';
import { DiagnosticSeverity, DocumentDiagnosticsBuilder } from "../../../Types";
import { Json } from '../../Json';
import { diagnose_molang } from '../../Molang/diagnostics';
import { MinecraftData } from 'bc-minecraft-bedrock-vanilla-data';
import { education_enabled } from '../../Definitions';

/**Diagnoses the given document as a particle
* @param doc The text document to diagnose
Expand All @@ -8,5 +12,28 @@ export function Diagnose(diagnoser: DocumentDiagnosticsBuilder): void {
//Check molang
diagnose_molang(diagnoser.document.getText(), "Particles", diagnoser);

//TODO add rp diagnostics
const particle = Json.LoadReport<Internal.ResourcePack.Particle>(diagnoser);
if (!Internal.ResourcePack.Particle.is(particle)) return;

//@ts-ignore
const texture = particle.particle_effect?.description?.['basic_render_parameters']?.['texture'];

if (typeof texture != 'string') return;

const pack = diagnoser.context.getCache().resourcePacks.get(diagnoser.document.uri);
if (pack === undefined) return;

if (MinecraftData.ResourcePack.hasTexture(texture, education_enabled(diagnoser))) return;

const rp_files = diagnoser.context
.getFiles(pack.folder, ["**/textures/**/*.{tga,png,jpg,jpeg}"], pack.context.ignores)
.map((item) => item.replace(/\\/gi, "/"));

if (!rp_files.some(path => path.includes(texture))) diagnoser.add(
`${texture}`,
`Cannot find file: ${texture}`,
DiagnosticSeverity.error,
"resourcepack.texture.missing"
);

}

0 comments on commit 3222a60

Please sign in to comment.