Welcome Guest, you are in: • Language Login

Nova by Vertice Wiki

RSS RSS

Navigation

Search the wiki
»





PoweredBy
There are many possibilities to store user data with a Nova Scene. Let me present some possible solutions:

  • Inside the Nova Scene

Nova entities and Nova scene have a property called "UserDatas". This property is an hashtable that will allow you to store all what you want within the Nova Scene. An hash table is an untype dictionary of key/value. Then, when you save your Nova scene, all these properties are serialized within the scene file.

Here is a sample in Nova script demonstrating storing specific data into the UserDatas property.


#Region "Imports"
Imports System
Imports System.Xml
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Net.Sockets
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Windows.Forms
Imports Vertice.Nova
Imports Vertice.Nova.Actions
Imports Vertice.Nova.Materials
Imports Vertice.Nova.Animations
Imports Vertice.Nova.Physics
Imports Vertice.Nova.Core
Imports System.IO
Imports Vertice.NovaStudio
Imports Vertice.Nova.InputControls
Imports Vertice.Core
Imports Vertice.Nova.PostProcesses
Imports System.Xml.Serialization 
#End Region

<Serializable()> _
public Class Geek
	Sub New()
		
	End Sub
	
	Sub New(ByVal n As String, f As String, b As DateTime)
		_name = n
		_firstname = f
		_birthday = b
	End Sub
	
	Private _name As String
	Public Property Name() As String
		Get
			Return _name
		End Get
		Set(ByVal value As String)
			_name = value
		End Set
	End Property
	
	Private _firstname As String
	Public Property Firstname() As String
		Get
			Return _firstname
		End Get
		Set(ByVal value As String)
			_firstname = value
		End Set
	End Property
	
	Private _birthday As DateTime
	Public Property Birthday() As DateTime
		Get
			Return _birthday
		End Get
		Set(ByVal value As DateTime)
			_birthday = value
		End Set
	End Property
	
	Public Overrides Function ToString As String
		Return String.Format("{0} {1} => {2}", _firstname, _name, _birthday.ToString())
	End Function	
End Class

Class Script
	Private geeks As List(Of Geek)
	Private currentScene As NovaScene

	Public Sub New(scene As NovaScene)
		Try
			currentScene = scene

			Deserialize()
			
			Serialize()
		Catch ex As Exception
			MessageBox.Show(ex.ToString())
		End Try
	End Sub

	Private Sub Deserialize()
		If Not currentScene.UserDatas("VerticeTeam") Is Nothing Then
				
			Messagebox.Show("Loading data")
				
			Dim serial As New XmlSerializer(GetType(List(Of Geek)))
			Dim ms As New MemoryStream(CType(currentScene.UserDatas("VerticeTeam"), Byte()))
			
			geeks = CType(serial.Deserialize(ms), List(Of Geek))
		Else
			Messagebox.Show("Generating data")

			geeks = New List(Of Geek)
			
			geeks.Add(New Geek("Name 1", "Firstname 1", Datetime.Now()))
			geeks.Add(New Geek("Name 2", "Firstname 2", Datetime.Now()))
			geeks.Add(New Geek("Name 3", "Firstname 3", Datetime.Now()))
		End If
		
		For Each g As geek In geeks 
			MessageBox.Show(g.ToString())		
		Next
	End Sub
	Private Sub Serialize()
		Try
			Dim serial As New XmlSerializer(GetType(List(Of Geek)))
			Dim ms As New MemoryStream()
		
			serial.Serialize(ms, geeks)
			
			currentScene.UserDatas("VerticeTeam") = ms.GetBuffer()
		Catch ex As Exception
			MessageBox.Show(ex.ToString())
		End Try
	End Sub

	Protected Overrides Sub Finalize()
	End Sub
End Class

  • Outside the Nova Scene
In that case, you can choose any support you want. In fact, since you use Microsoft .NET technologies, you can choose what you want: file, database, active Directory, registry, ...

You may also use the Tag property for all common Nova Objects and for the Nova scene. But in that case, remember that Tag properties are volatile and not stored at all. If you need a persistant storage, just prefer one of the previous method.

Moreover, all this is possible from a custom action in the action builder, a Nova Script, a Nova Plugin and through the SDK.