Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add texture validation for particles #322

Merged
merged 2 commits into from
Feb 10, 2025
Merged
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
32 changes: 30 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,29 @@ 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;

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@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"
);

}
Loading