Drag[en]gine Script Module DragonScript  1.21
Dragengine.LoadSave.PersistencyEnvironment Class Reference

Persistency environment for reading and writing for complex objects. More...

Inheritance diagram for Dragengine.LoadSave.PersistencyEnvironment:

Public Member Functions

void forEachVariable (Block ablock)
 Visit variables with block with parameters String name and Object value. More...
 
Persistency getPersistency ()
 Persistency with factories. More...
 
Object getVariable (String name)
 Variable value. More...
 
Object getVariable (String name, Object defaultValue)
 Variable value or default value if absent. More...
 
int getVersion ()
 File version number. More...
 
PersistencyEnvironment new (Persistency persistency)
 Create persistency environment. More...
 
PersistencyEnvironment new (Persistency persistency, int version)
 Create persistency environment. More...
 
PersistencyEnvironment new (PersistencyEnvironment environment)
 Create copy of persistency environment. More...
 
bool readBool (FileReader reader)
 Read boolean. More...
 
Persistable readObject (FileReader reader)
 Read object using factory and file reader. More...
 
Persistable readObjectOrNull (FileReader reader)
 Read object using factory and file reader or null if empty factory name. More...
 
String readString16OrNullIfEmpty (FileReader reader)
 Read string with 16-bit length or null if empty. More...
 
String readString8OrNullIfEmpty (FileReader reader)
 Read string with 8-bit length or null if empty. More...
 
StringID readStringIDOrNullIfEmpty (FileReader reader)
 Read StringID with 8-bit length or null if empty. More...
 
void removeAllVariables ()
 Remove all variables. More...
 
void removeVariable (String name)
 Remove variable if present. More...
 
void setCommonVariables (Loaders loaders)
 Set common variables from Loader. More...
 
void setVariable (String name, Object value)
 Set variable. More...
 
void writeBool (FileWriter writer, bool value)
 Write boolean. More...
 
void writeObject (FileWriter writer, Persistable object)
 Write object using file writer. More...
 
void writeObjectOrNull (FileWriter writer, Persistable object)
 Write object or null using file writer. More...
 
void writeString16OrEmptyIfNull (FileWriter writer, String string)
 Write string with 16-bit length or empty string if null. More...
 
void writeString8OrEmptyIfNull (FileWriter writer, String string)
 Write string with 8-bit length or empty string if null. More...
 
void writeStringIDOrEmptyIfNull (FileWriter writer, StringID string)
 Write StringID with 8-bit length or empty string if null. More...
 

Static Public Attributes

static final String varConvoPlayback = "conversationPlayback"
 Variable conversation playback. More...
 
static final String varLoadAnimator = "loadAnimator"
 Variable animation loader. More...
 
static final String varLoadConversation = "loadConversation"
 Variable conversation loader. More...
 

Detailed Description

Persistency environment for reading and writing for complex objects.

Carries information required to properly restore complex objects. Stores a file version number which can be used to track file format changes. The file version is static during the lifetime of the object instance. Provides also helper methods to reduce code lines for typical persistency tasks.

Variables can be set by the user to temporarily store additional information specific persistency factories required to properly restore objects. Variables are identified by a string name and can contain any type of object. Best practice is to create a copy of a persistency environment if temporary variables have to be modified and use this new environment for subsequent restoring. You can also set and restore the temporary variables but using a copy of a persistency environment is simpler.

Member Function Documentation

◆ forEachVariable()

void Dragengine.LoadSave.PersistencyEnvironment.forEachVariable ( Block  ablock)

Visit variables with block with parameters String name and Object value.

◆ getPersistency()

Persistency Dragengine.LoadSave.PersistencyEnvironment.getPersistency ( )

Persistency with factories.

◆ getVariable() [1/2]

Object Dragengine.LoadSave.PersistencyEnvironment.getVariable ( String  name)

Variable value.

Exceptions
EInvalidParamNamed variable is absent.

◆ getVariable() [2/2]

Object Dragengine.LoadSave.PersistencyEnvironment.getVariable ( String  name,
Object  defaultValue 
)

Variable value or default value if absent.

◆ getVersion()

int Dragengine.LoadSave.PersistencyEnvironment.getVersion ( )

File version number.

◆ new() [1/3]

PersistencyEnvironment Dragengine.LoadSave.PersistencyEnvironment.new ( Persistency  persistency)

Create persistency environment.

◆ new() [2/3]

PersistencyEnvironment Dragengine.LoadSave.PersistencyEnvironment.new ( Persistency  persistency,
int  version 
)

Create persistency environment.

◆ new() [3/3]

PersistencyEnvironment Dragengine.LoadSave.PersistencyEnvironment.new ( PersistencyEnvironment  environment)

Create copy of persistency environment.

◆ readBool()

bool Dragengine.LoadSave.PersistencyEnvironment.readBool ( FileReader  reader)

Read boolean.

◆ readObject()

Persistable Dragengine.LoadSave.PersistencyEnvironment.readObject ( FileReader  reader)

Read object using factory and file reader.

Exceptions
EInvalidParamreader is null.
EInvalidParamRead factory name is absent in getPersistency().

◆ readObjectOrNull()

Persistable Dragengine.LoadSave.PersistencyEnvironment.readObjectOrNull ( FileReader  reader)

Read object using factory and file reader or null if empty factory name.

Exceptions
EInvalidParamRead factory name is absent in getPersistency().

◆ readString16OrNullIfEmpty()

String Dragengine.LoadSave.PersistencyEnvironment.readString16OrNullIfEmpty ( FileReader  reader)

Read string with 16-bit length or null if empty.

◆ readString8OrNullIfEmpty()

String Dragengine.LoadSave.PersistencyEnvironment.readString8OrNullIfEmpty ( FileReader  reader)

Read string with 8-bit length or null if empty.

◆ readStringIDOrNullIfEmpty()

StringID Dragengine.LoadSave.PersistencyEnvironment.readStringIDOrNullIfEmpty ( FileReader  reader)

Read StringID with 8-bit length or null if empty.

◆ removeAllVariables()

void Dragengine.LoadSave.PersistencyEnvironment.removeAllVariables ( )

Remove all variables.

◆ removeVariable()

void Dragengine.LoadSave.PersistencyEnvironment.removeVariable ( String  name)

Remove variable if present.

◆ setCommonVariables()

void Dragengine.LoadSave.PersistencyEnvironment.setCommonVariables ( Loaders  loaders)

Set common variables from Loader.

Call this after creating a new environment to work properly with factories provides by the DragonScript module.

◆ setVariable()

void Dragengine.LoadSave.PersistencyEnvironment.setVariable ( String  name,
Object  value 
)

Set variable.

◆ writeBool()

void Dragengine.LoadSave.PersistencyEnvironment.writeBool ( FileWriter  writer,
bool  value 
)

Write boolean.

◆ writeObject()

void Dragengine.LoadSave.PersistencyEnvironment.writeObject ( FileWriter  writer,
Persistable  object 
)

Write object using file writer.

Writes persistency factory name as string with 8-bit length and then calls Persistable.writeToFile().

Exceptions
EInvalidParamwriter is null.
EInvalidParamobject is null.
EInvalidParamobject.persistencyFactoryName() is empty.

◆ writeObjectOrNull()

void Dragengine.LoadSave.PersistencyEnvironment.writeObjectOrNull ( FileWriter  writer,
Persistable  object 
)

Write object or null using file writer.

If object is null writes empty string with 8-bit length. Otherwise writes persistency factory name as string with 8-bit length and then calls Persistable.writeToFile().

Exceptions
EInvalidParamwriter is null.
EInvalidParamobject is not null and object.persistencyFactoryName() is empty.

◆ writeString16OrEmptyIfNull()

void Dragengine.LoadSave.PersistencyEnvironment.writeString16OrEmptyIfNull ( FileWriter  writer,
String  string 
)

Write string with 16-bit length or empty string if null.

◆ writeString8OrEmptyIfNull()

void Dragengine.LoadSave.PersistencyEnvironment.writeString8OrEmptyIfNull ( FileWriter  writer,
String  string 
)

Write string with 8-bit length or empty string if null.

◆ writeStringIDOrEmptyIfNull()

void Dragengine.LoadSave.PersistencyEnvironment.writeStringIDOrEmptyIfNull ( FileWriter  writer,
StringID  string 
)

Write StringID with 8-bit length or empty string if null.

Member Data Documentation

◆ varConvoPlayback

final String Dragengine.LoadSave.PersistencyEnvironment.varConvoPlayback = "conversationPlayback"
static

Variable conversation playback.

Used by some factories to call one of the methods subclassed by a game class. If variable is not set factories will use null objects where possible while in other cases it might fail loading. In this case subclasses are responsible to restore the missing objects.

If set has to be an instance of ConversationPlayback.

◆ varLoadAnimator

final String Dragengine.LoadSave.PersistencyEnvironment.varLoadAnimator = "loadAnimator"
static

Variable animation loader.

Used by some factories to load animators. If variable is not set factories will consider loading the resource having failed. Some can cope with this while others throw an exception. The following factories are known to use this variable:

  • ConversationGesturePlayback

If set has to be an instance of LoadAnimator.

◆ varLoadConversation

final String Dragengine.LoadSave.PersistencyEnvironment.varLoadConversation = "loadConversation"
static

Variable conversation loader.

Used by some factories to load conversations. If variable is not set factories will consider loading the resource having failed. Some can cope with this while others throw an exception. The following factories are known to use this variable:

  • ConversationPlayback

If set has to be an instance of LoadConversation.


The documentation for this class was generated from the following file: