From 2db862d447a20d62389d6d6f955136d29040946b Mon Sep 17 00:00:00 2001 From: JakubMarecek Date: Sun, 2 Jun 2024 22:51:37 +0200 Subject: [PATCH] added file verifying for scene and questphase --- .../FileValidation/graph_questphase.wscript | 30 +++++++++++++++ .../FileValidation/graph_scene.wscript | 38 +++++++++++++++++++ Scripts/Wolvenkit_FileValidation.wscript | 7 +++- Scripts/hook_global.wscript | 6 +++ Scripts/hook_settings.wscript | 12 ++++++ 5 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 Scripts/Internal/FileValidation/graph_questphase.wscript create mode 100644 Scripts/Internal/FileValidation/graph_scene.wscript diff --git a/Scripts/Internal/FileValidation/graph_questphase.wscript b/Scripts/Internal/FileValidation/graph_questphase.wscript new file mode 100644 index 0000000..20a61a3 --- /dev/null +++ b/Scripts/Internal/FileValidation/graph_questphase.wscript @@ -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); + } + } +} \ No newline at end of file diff --git a/Scripts/Internal/FileValidation/graph_scene.wscript b/Scripts/Internal/FileValidation/graph_scene.wscript new file mode 100644 index 0000000..b3f7eab --- /dev/null +++ b/Scripts/Internal/FileValidation/graph_scene.wscript @@ -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()}`); + } + } + } +} \ No newline at end of file diff --git a/Scripts/Wolvenkit_FileValidation.wscript b/Scripts/Wolvenkit_FileValidation.wscript index 78e284f..fa23bee 100644 --- a/Scripts/Wolvenkit_FileValidation.wscript +++ b/Scripts/Wolvenkit_FileValidation.wscript @@ -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" /* * .___ __ .__ __ .__ .__ _____.__.__ @@ -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; \ No newline at end of file diff --git a/Scripts/hook_global.wscript b/Scripts/hook_global.wscript index fb86448..bc4225c 100644 --- a/Scripts/hook_global.wscript +++ b/Scripts/hook_global.wscript @@ -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) { diff --git a/Scripts/hook_settings.wscript b/Scripts/hook_settings.wscript index 841e8ea..f21ade9 100644 --- a/Scripts/hook_settings.wscript +++ b/Scripts/hook_settings.wscript @@ -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, } };