ValidateResourceDocument ( document )

Parameters

document - resource authoring handle

Description

Returns a JSON validation report for a resource document.

The caller-owned report contains valid, errorCount and diagnostics. The returned integer is a JSON handle, not a Boolean validity result. Validation checks dependencies and authored values without constructing runtime resources. Free the report with FreeJson.

Each picture, model, heightmap, sound, shader or collider data that the resource, or a resource it uses, names and whose file is missing is an error, resource.asset.missing, at the dependency's source ($.assets[n].source), "Missing asset: " and the file - every one of them, not only the first. A resource edited for a world can still be changed and saved meanwhile (ReplaceResourceDocumentSource). A file an editor holds unsaved counts as there.

For the full story, see the reusable resources guide, which covers resource formats, ownership, editing and the save workflow.


See also: ResourceDocumentDiagnostics, SaveResourceDocument, ResourceDocumentLastDiagnostics, FreeJson.

Example

; CreateResourceDocument Example
; ------------------------------

; Create an untitled material document in memory; nothing touches the disk
document=CreateResourceDocument("material")
If document=0 Then RuntimeError ResourceDocumentError()

Print "New material document"
Print "  path: '"+ResourceDocumentPath(document)+"' (untitled)"
Print "  dirty: "+ResourceDocumentDirty(document)
Print "  revision: "+ResourceDocumentRevision(document)

; Recolour it with an edit transaction made at the revision we observed
revision=ResourceDocumentRevision(document)
text$="{'protocol':'blitz3d.resource-document-edit','version':1,'revision':"+revision+","
text=text+"'operations':[{'op':'set-material-property','property':'color','value':[0.9,0.4,0.1,1]}]}"
edit=ParseJson(Replace(text,"'",Chr(34)))
If ApplyResourceDocumentEdit(document,edit)=0 Then RuntimeError ResourceDocumentError()
Print ""
Print "ApplyResourceDocumentEdit succeeded; revision is now "+ResourceDocumentRevision(document)

; The same edit is now stale, so it is rejected and nothing changes
Print "Applying it again returns "+ApplyResourceDocumentEdit(document,edit)
Print "  ResourceDocumentError: "+ResourceDocumentError()
FreeJson edit

; Broken replacement text is rejected too, with diagnostics
If ReplaceResourceDocumentSource(document,"{",ResourceDocumentRevision(document))=0
    diagnostics=ResourceDocumentDiagnostics(document)
    Print ""
    Print "ReplaceResourceDocumentSource rejected '{' with "+JsonCount(diagnostics)+" diagnostic(s)"
    FreeJson diagnostics
EndIf

; Validation reports on the document without changing it
report=ValidateResourceDocument(document)
valid=JsonObjectGet(report,"valid")
Print ""
Print "ValidateResourceDocument valid: "+JsonBoolean(valid)
FreeJson valid
FreeJson report

; Read the colour back from a JSON snapshot of the document
snapshot=ResourceDocumentJson(document)
definition=JsonObjectGet(snapshot,"definition")
Print "Authored definition: "+JsonStringify(definition)
FreeJson definition
FreeJson snapshot
Print "Source text length: "+Len(ResourceDocumentSource(document))+" characters"

; Diagnostics of the latest operation in this program, handle or not
latest=ResourceDocumentLastDiagnostics()
Print "Latest operation diagnostics: "+JsonCount(latest)
FreeJson latest

FreeResourceDocument document

Print ""
Print "Press any key to close the example"
WaitKey

End

Index