User Tools

Site Tools


custom-asset

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
custom-asset [2022/03/29 20:52] – created minotoriouscustom-asset [2022/03/30 10:16] (current) minotorious
Line 1: Line 1:
-ASSET classes are the basic registerable types in Foundation.+[[assets|ASSET]] classes are the basic registerable types in Foundation.
  
-For reference all available pure DATA classes can be found in [[api#assets_classes|this]] section of the API.+For reference all available [[assets|ASSET]] classes can be found in [[api#assets_classes|this]] section of the API.
  
 ===== Creating & Using a Custom ASSET Object ===== ===== Creating & Using a Custom ASSET Object =====
 ==== Step 1: Defining an ASSET Object using a Lua Table ==== ==== Step 1: Defining an ASSET Object using a Lua Table ====
-To create a custom ASSET object we will need to make use of the ''mod:registerClass(AssetTable)'' function providing it with an associated Lua Table.+To create a custom [[assets|ASSET]] object we will need to make use of the ''mod:registerClass(AssetTable)'' function providing it with an associated Lua Table.
  
-Here you decide what properties your custom ASSET object will contain. +Here you decide what properties your custom [[assets|ASSET]] object will contain. 
 <code lua> <code lua>
 local MY_ASSET_OBJECT = { local MY_ASSET_OBJECT = {
-    TypeName = "MY_ASSET_OBJECT ",+    TypeName = "MY_ASSET_OBJECT",
     DataType = "ASSET",     DataType = "ASSET",
     Properties = {     Properties = {
Line 21: Line 21:
 mod:registerClass(MY_ASSET_OBJECT) mod:registerClass(MY_ASSET_OBJECT)
 </code> </code>
-Note that ASSETs unlike DATA do not need the ''SAVE_GAME'' flag as their properties are read from their registration on load!+Note that [[assets|ASSET]]s unlike [[api#data_classes|DATA]] do not need the ''SAVE_GAME'' flag as their properties are read from their registration on load!
  
-Also remember that you can define properties based on the basic [[data-types|data types]] (i.e. string, integer, float, etc.) or based on any of the existing DATA or ASSET objects, as well as ''list''s therof!+Also remember that you can define properties based on the basic [[data-types|data types]] (i.e. string, integer, float, etc.) or based on any of the existing [[api#data_classes|DATA]] or [[assets|ASSET]] objects, as well as ''list''s therof!
  
 ==== Step 2: Registering an Instance of an ASSET Object ==== ==== Step 2: Registering an Instance of an ASSET Object ====
 Note: This also aplies to using vanilla ASSET objects! Note: This also aplies to using vanilla ASSET objects!
  
-In your mod's lua code you when you want to register an instance of your new ASSET object you will have to use the ''mod:registerAsset(AssetTable)'' method as follows.+In your mod's lua code you when you want to register an instance of your new [[assets|ASSET]] object you will have to use the ''mod:registerAsset(AssetTable)'' method as follows.
 <code lua> <code lua>
 mod:registerAsset({ mod:registerAsset({
-    DataType = "MY_ASSET_OBJECT ",+    DataType = "MY_ASSET_OBJECT",
     Id = "MY_ASSET_OBJECT_INSTANCE",     Id = "MY_ASSET_OBJECT_INSTANCE",
     Property1 = "SomeOtherString",     Property1 = "SomeOtherString",
Line 37: Line 37:
 }) })
 </code> </code>
-Remember, each unique ASSET instance requires an Id that identifies it from other ASSETs of the same class.+Remember, each unique [[assets|ASSET]] instance requires an Id that identifies it from other [[assets|ASSET]]s of the same class.
  
 In case you omit any properties you don't yet need to explicitly set they will use their default values. As we have done with ''Property2'' above. In case you omit any properties you don't yet need to explicitly set they will use their default values. As we have done with ''Property2'' above.
Line 44: Line 44:
 When you want to use your new ASSET instance be it in a [[api/component|COMPONENT]] property, [[api/building_function|BUILDING_FUNCTION]], or other [[assets|ASSET]]/[[api#data_classes|DATA]] class you can use the string Id to reference it by name. When you want to use your new ASSET instance be it in a [[api/component|COMPONENT]] property, [[api/building_function|BUILDING_FUNCTION]], or other [[assets|ASSET]]/[[api#data_classes|DATA]] class you can use the string Id to reference it by name.
  
-For example here we are using our custom ASSET instance as the default value in a [[api/component|COMPONENT]]+For example here we are using our custom [[assets|ASSET]] instance as the default value in a [[api/component|COMPONENT]]
 <code lua> <code lua>
 local COMP_EXAMPLE = { local COMP_EXAMPLE = {
custom-asset.1648601522.txt.gz · Last modified: 2022/03/29 20:52 by minotorious

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki