From The Depths - Forum
Notice to modders- new data management system - Printable Version

+- From The Depths - Forum (https://forum.fromthedepthsgame.com)
+-- Forum: Announcements (https://forum.fromthedepthsgame.com/forumdisplay.php?fid=3)
+--- Forum: Developer updates (https://forum.fromthedepthsgame.com/forumdisplay.php?fid=4)
+--- Thread: Notice to modders- new data management system (/showthread.php?tid=38727)



Notice to modders- new data management system - Nick Smart - 2019-04-14

Hello.

Let me start by saying that GetParameters1(), GetParameters2(), GetExtraInfo(v) andare depreciated and will be removed entirely on the 5th of May 2019.

SetParameter1(v4), SetParameters2(v4) and SetExtraInfo(v) will stay forever, to allow old designs to be loaded, and their data migrated.


They are replaced by a system that manages 
a) Saving and loading
b) Copy and pasting
c) Multiplayer syncronisation
d) Local change events 
e) Clamping (min, max, etc)
f) More data types (Guid,componentId, Dictionaries,Lists,Colors,Vector4s,Vector3s,Vector2s, enumerations, etc)
g) Quick display on the UI

I've used the example of the Adv Cannon Firing Piece (APS firing piece)

I've made AdvCannonData, which extends PrototypeSystem (yes, I should have refactored the name after it stopped being a prototype, but that ship has sailed).
It defines a bunch of Var objects of different types. See Var<float>,Var<int> and special types such as VarFloatClamp,Var01 in this example, but there are lots more.
Each Var object must have either a Variable attribute on it, defining a unique index to save to. If you want to use a slider for the variable on a UI and define it in one line of code (see below) use the Slider attribute which extends the Variable attribute.
Each index is unique. The name and description can be input (if using Slider these are the display string, and the tooltip).
[Image: oX2vqYX.png]

Next, you make this AdvCannonData object a PUBLIC member PROPERTY of the block.
[Image: SVEa4Fc.png]

Then you can hook up some change listeners. This code is in BlockStart (actually WeaponStart in this case).
[Image: kpNBxza.png]

Then you can use code like this to easily display the info on the UI (as a slider, or as a boolean toggle).
[Image: T5ZhJRZ.png]



For migrating data from the old way to the new way please see this screenshot.
I've commented out GetExtraInfo but kept it in the file so I can see the order data used to be SAVED in.
I've changed the SetExtraInfo so that I am writing this old data into my new data packet, and thus completing the migration of old blueprints to the new format.

[Image: cUa76lO.png]


"Vars" declared like this are automatically saved / loaded / copy / pasted / MP synced 

Here are some more advanced usage notes:

If you want to change a variable but don't want to sync the change over the network (GP PIDs make use of this function to avoid massive amounts of data being sent over the network when controlling hydrofoils, as the PID is run on both client and server), then follow this example
[Image: A8tI5f4.png]


If you want to run a single callback once per frame if one or more variables in the pack has been changed you can use this call (seen in ParticleCannonMeleeLens)
[Image: C3Ptv6I.png]

A single Var change callback function looks like this, giving the new value, the old value, and the type of change.
[Image: hYtukrL.png]




Please share this post with modders that you know.


RE: Notice to modders- new data management system - Why7090 - 2019-04-14

What are the types that this system can save, and how? Is it able to save Dictionary and List types? And what about custom structs/classes, and reference loops? Can we set it to ignore a specific property?

And how can I migrate from BlockWithText to this new system? (I used to save settings of my blocks in JSON formatted string, even if they don't have any text)


RE: Notice to modders- new data management system - Nick Smart - 2019-04-14

(2019-04-14, 01:59 PM)Why7090 Wrote: What are the types that this system can save, and how? Is it able to save Dictionary and List types? And what about custom structs/classes, and reference loops? Can we set it to ignore a specific property?

This is one example of a dictionary that I save. It's a dictionary of GUID keys and double values.
[Image: IjhPFSK.png]

Here is an example of saving a list of custom classes 
[Image: ZnFdb2s.png]

If you have a variable of type Var and you want to ignore it use the IgnoreAttribute
[Image: V6Y0vWm.png]

You can also set extra settings using the VariableModifier Attribute.
[Image: 8QmmbPn.png]
And here is a look at the details of that VariableModifier attribute
[Image: XQ1oV75.png]


RE: Notice to modders- new data management system - Nick Smart - 2019-04-14

And here is a simpler "integer" list class

[Image: 7qvpcJr.png]


RE: Notice to modders- new data management system - Nick Smart - 2019-04-14

The basic types supported are... float, double, bool, Guid, UInt32, int, Color32,Color,enumerations, Vector3,Vector3i,ComponentId,Vector2,string, and classes extending the IOneDoubleToSave interface.

This means that Var<float>, Var<double>, etc will all "just work".

Whereas Var<Hydrofoil> will not save or load or do anything meaningful.


RE: Notice to modders- new data management system - Nick Smart - 2019-04-14

To Migrate from IBlockWithText do this...

(Note the IblockWithText functionality will remain in game)

Let the system know you have migrated to a new data structure.
[Image: UCEtsBQ.png]

Hook into the old system SetText method and put the string into your new data structure (Data.Text is a VarString (which is a Var<string>)
[Image: CnH7IkB.png]

And, for good measure, although it won't be called if you follow the first step
[Image: xHhIcjg.png]


This example is supported by the following code
[Image: mz8Jvj2.png]

[Image: uq8PHWB.png]

[Image: AT1aoYv.png]


RE: Notice to modders- new data management system - Why7090 - 2019-04-14

How to filter a value? For example, I want to strim leading and ending spaces and quotes in a string.


RE: Notice to modders- new data management system - Nick Smart - 2019-04-14

(2019-04-14, 03:18 PM)Why7090 Wrote: How to filter a value? For example, I want to strim leading and ending spaces and quotes in a string.

Override VarString with your special class. See VarStringName ( or indeed VarString as an override of Var<string>)

[Image: 9YSnSSq.png]

Also see this cleaner example of what you are after

[Image: lanNTrB.png]