Blitz3D+ Command Reference

ResourceDocumentDirty ( document )

Parameters

document - resource authoring handle

Description

Returns True while a resource document has unsaved changes.

Newly created documents are dirty. Runtime brush edits do not change this flag or the authored source - use it to show an unsaved-changes marker in your tool's title bar.

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

Requires Extended mode.

See also: SaveResourceDocument, ResourceDocumentPath, ResourceDocumentRevision.

Example

; CreateResourceDocument Example
; ------------------------------
; Requires Extended mode.

; 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