Skip to content

Commit

Permalink
Merge pull request #8 from JakubMarecek/main
Browse files Browse the repository at this point in the history
added file verifying for scene and questphase
  • Loading branch information
manavortex authored Jun 2, 2024
2 parents 2e0defc + 2db862d commit f00ec68
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 1 deletion.
30 changes: 30 additions & 0 deletions Scripts/Internal/FileValidation/graph_questphase.wscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @type lib
// @name FileValidation_Questphase

import {
checkIfFileIsBroken
} from "./Internal/FileValidation/00_shared.wscript";
import {
getPathToCurrentFile
} from '../../Wolvenkit_FileValidation.wscript';
import * as Logger from 'Logger.wscript';

export function validateQuestphaseFile(questphase, _questphaseSettings) {
if (!_questphaseSettings?.Enabled) return;

if (questphase?.Data?.RootChunk) return validateQuestphaseFile(questphase.Data.RootChunk, _entSettings);
if (checkIfFileIsBroken(questphase, 'questphase')) return;

const nodeIDs = [];

for (let i = 0; i < questphase.graph.Data.nodes.length; i++) {
const node = questphase.graph.Data.nodes[i];
const nodeID = node.Data.id;

if (nodeIDs.includes(nodeID)) {
Logger.Warning(`There is duplicate ID of two or more nodes: ${nodeID}. File ${getPathToCurrentFile()}`);
} else {
nodeIDs.push(nodeID);
}
}
}
38 changes: 38 additions & 0 deletions Scripts/Internal/FileValidation/graph_scene.wscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// @type lib
// @name FileValidation_Scene

import {
checkIfFileIsBroken
} from "./Internal/FileValidation/00_shared.wscript";
import {
getPathToCurrentFile
} from '../../Wolvenkit_FileValidation.wscript';
import * as Logger from 'Logger.wscript';

export function validateSceneFile(scene, _sceneSettings) {
// check if enabled
if (!_sceneSettings?.Enabled) return;

if (scene?.Data?.RootChunk) return validateQuestphaseFile(scene.Data.RootChunk, _entSettings);
if (checkIfFileIsBroken(scene, 'scene')) return;

const nodeIDs = [];

for (let i = 0; i < scene.sceneGraph.Data.graph.length; i++) {
const node = scene.sceneGraph.Data.graph[i];
const nodeID = node.Data.nodeId.id;

if (nodeIDs.includes(nodeID)) {
Logger.Warning(`There is duplicate ID of two or more nodes: ${nodeID}. File ${getPathToCurrentFile()}`);
} else {
nodeIDs.push(nodeID);
}

if (node.Data.questNode != undefined) {
const questNodeID = node.Data.questNode.Data.id;
if (questNodeID != nodeID) {
Logger.Warning(`Node ID doesn't match with quest node definition in node: ${nodeID}. File ${getPathToCurrentFile()}`);
}
}
}
}
7 changes: 6 additions & 1 deletion Scripts/Wolvenkit_FileValidation.wscript
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
checkIfFileIsBroken, stringifyPotentialCName, checkDepotPath, hasUppercase,
getNumCurlyBraces, checkCurlyBraces, isNumericHash, formatArrayForPrint
} from "./Internal/FileValidation/00_shared.wscript";

import { validateQuestphaseFile as validate_questphase_file } from "./Internal/FileValidation/graph_questphase.wscript"
import { validateSceneFile as validate_scene_file } from "./Internal/FileValidation/graph_scene.wscript"

/*
* .___ __ .__ __ .__ .__ _____.__.__
Expand Down Expand Up @@ -2166,4 +2167,8 @@ export function validateWorkspotFile(workspot, _workspotSettings) {
}
//#endregion

export const validateQuestphaseFile = validate_questphase_file;

export const validateSceneFile = validate_scene_file;

export const validateInkatlasFile = validate_inkatlas_file;
6 changes: 6 additions & 0 deletions Scripts/hook_global.wscript
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ globalThis.onSave = function (ext, file) {
FileValidation.validateJsonFile(data, Settings.Json);
file = TypeHelper.JsonStringify(fileContent);
break;
case "questphase":
FileValidation.validateQuestphaseFile(data, Settings.GraphQuestphase);
break;
case "scene":
FileValidation.validateSceneFile(data, Settings.GraphScene);
break;
}
} catch (err) {
if (isWolvenkitDeveloper) {
Expand Down
12 changes: 12 additions & 0 deletions Scripts/hook_settings.wscript
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,18 @@ const Settings = {
* Set this to "false" to suppress checking of nested files in workspot.
*/
checkFilepaths: true,
},
GraphQuestphase: {
/*
* Set this to "false" to disable file validation for .questphase files.
*/
Enabled: true,
},
GraphScene: {
/*
* Set this to "false" to disable file validation for .scene files.
*/
Enabled: true,
}
};

Expand Down

0 comments on commit f00ec68

Please sign in to comment.