DataPack: Difference between revisions

From Whirled Club Wiki
Jump to navigation Jump to search
(Created page with "This is a brief introduction to '''DataPacks'''. == The Quick And Dirty == A DataPack can be used for many things. Most importantly is that they are editable. The Whirled te...")
 
m (Text replacement - ">" to ">")
 
(2 intermediate revisions by the same user not shown)
Line 5: Line 5:
A DataPack can be used for many things. Most importantly is that they are editable. The Whirled team is building tools that will enable all users to edit DataPacks, to create new levels for your games, or to change a [[remix avatar (code tutorial)|remixable avatar]]. Not all of these tools are in place yet, but by using DataPacks now you can ensure that your creation can benefit from these future enhancements.
A DataPack can be used for many things. Most importantly is that they are editable. The Whirled team is building tools that will enable all users to edit DataPacks, to create new levels for your games, or to change a [[remix avatar (code tutorial)|remixable avatar]]. Not all of these tools are in place yet, but by using DataPacks now you can ensure that your creation can benefit from these future enhancements.


* Create a directory to hold the files you want in each DataPack. Let's say I call my directory "blackbird".
* Create a directory to hold the files you want in each DataPack. Let's say I call my directory "blackbird".
* In that directory create a text file called "_data.xml" (it has to be called that, it's the special name of the data file inside a DataPack).
* In that directory create a text file called "_data.xml" (it has to be called that, it's the special name of the data file inside a DataPack).
* Edit _data.xml with a text editor:
* Edit _data.xml with a text editor:
<geshi lang=xml>
<geshi lang=xml>
&lt;datapack&gt;
<datapack>
:&lt;data name=&quot;levelName&quot; info=&quot;The name of the level&quot; type=&quot;String&quot; value=&quot;Blackbird Laughter&quot;/&gt;
:<data name="levelName" info="The name of the level" type="String" value="Blackbird Laughter"/>
:&lt;data name=&quot;laps&quot; info=&quot;How many laps are required&quot; type=&quot;Number&quot; value=&quot;3&quot;/&gt;
:<data name="laps" info="How many laps are required" type="Number" value="3"/>
:&lt;data name=&quot;intro&quot; info=&quot;Introductory text for players&quot; type=&quot;String&quot; value=&quot;Spookyha!&quot;/&gt;
:<data name="intro" info="Introductory text for players" type="String" value="Spookyha!"/>
:&lt;data name=&quot;outtro&quot; info=&quot;Outgoing text for players&quot; type=&quot;String&quot; value=&quot;Kekekeke&quot;/&gt;
:<data name="outtro" info="Outgoing text for players" type="String" value="Kekekeke"/>
:&lt;file name=&quot;level&quot; info=&quot;Level image&quot; type=&quot;Image&quot; value=&quot;blackbird.png&quot;/&gt;
:<file name="level" info="Level image" type="Image" value="blackbird.png"/>
:&lt;file name=&quot;map&quot; info=&quot;Level map: black pixels are road, white is blocked, shades of gray are 'muddy', they drive at their percent black&quot; type=&quot;Image&quot; value=&quot;blackbird_map.png&quot;/&gt;
:<file name="map" info="Level map: black pixels are road, white is blocked, shades of gray are 'muddy', they drive at their percent black" type="Image" value="blackbird_map.png"/>
:&lt;file name=&quot;intro&quot; info=&quot;Intro movie to play&quot; type=&quot;DisplayObject&quot; value=&quot;blackbird_intro.swf&quot;/&gt;
:<file name="intro" info="Intro movie to play" type="DisplayObject" value="blackbird_intro.swf"/>
:&lt;file name=&quot;outtro&quot; info=&quot;Outgoing movie&quot; type=&quot;DisplayObject&quot; value=&quot;blackbird_outtro.swf&quot;/&gt;
:<file name="outtro" info="Outgoing movie" type="DisplayObject" value="blackbird_outtro.swf"/>
&lt;/datapack&gt;
</datapack>
&lt;/geshi&gt;
</geshi>
* Place the referenced files in the same directory: blackbird.png, blackbird_map.png, blackbird_intro.swf, blackbird_outtro.swf&quot;
* Place the referenced files in the same directory: blackbird.png, blackbird_map.png, blackbird_intro.swf, blackbird_outtro.swf"
* Zip up all the files in that directory with any zip creator, making sure not to save any directory structure (the files should all be &quot;flat&quot; at the top) and with compression off (store only). For example on the unix command line I'd type &quot;zip -0 blackbird_level.zip blackbird/*&quot;.
* Zip up all the files in that directory with any zip creator, making sure not to save any directory structure (the files should all be "flat" at the top) and with compression off (store only). For example on the unix command line I'd type "zip -0 blackbird_level.zip blackbird/*".


Because the bulk of the bytes (images and such) are already compressed, the fact that the overall datapack isn't compressed isn't such a big loss.
Because the bulk of the bytes (images and such) are already compressed, the fact that the overall datapack isn't compressed isn't such a big loss.


== Common attributes ==
== Common attributes ==
Both &lt;file&gt; and &lt;data&gt; fields have a few shared attributes:
Both <file> and <data> fields have a few shared attributes:
* name - The name of the file or data field.
* name - The name of the file or data field.
* info - A String description of the field, shown to users when remixing.
* info - A String description of the field, shown to users when remixing.
* optional - Not required, but if optional=&quot;true&quot; then the field can have no value, and will return null to your code.
* optional - Not required, but if optional="true" then the field can have no value, and will return null to your code.
* type - The type of the data or file field.
* type - The type of the data or file field.
* value - The value of the file or data field, see below for more details.
* value - The value of the file or data field, see below for more details.
Line 37: Line 37:
Data fields provide access to a small piece of data.
Data fields provide access to a small piece of data.


* type=&quot;String&quot; - value is a String
* type="String" - value is a String
* type=&quot;Number&quot; (optional attributes: min and max.) - value is interpreted as a Number
* type="Number" (optional attributes: min and max.) - value is interpreted as a Number
* type=&quot;int&quot; (optional attributes: min and max.) - value is interpreted as an int
* type="int" (optional attributes: min and max.) - value is interpreted as an int
* type=&quot;Choice&quot; (required attribute: &quot;choices&quot;, an Array of values) - the value is a duplicate of one of these elements
* type="Choice" (required attribute: "choices", an Array of values) - the value is a duplicate of one of these elements
* type=&quot;Boolean&quot; - value is &quot;true&quot; or &quot;false&quot;
* type="Boolean" - value is "true" or "false"
* type=&quot;Color&quot; - value is a uint representing a color
* type="Color" - value is a uint representing a color
* type=&quot;Array&quot; - value is a comma-separated array of Strings
* type="Array" - value is a comma-separated array of Strings
* type=&quot;Point&quot; - value is two Numbers separated by a comma (x,y)
* type="Point" - value is two Numbers separated by a comma (x,y)
* type=&quot;Rectangle&quot; - value is four Numbers separated by a comma (x,y,width,height)
* type="Rectangle" - value is four Numbers separated by a comma (x,y,width,height)


== File Types ==
== File Types ==
Line 51: Line 51:
File fields provide access to files included in the DataPack. Note that the name of a file field is the convenient name with which you will look up the file. Multiple file fields can have the same filename as their value, and that file will only need to be included once.
File fields provide access to files included in the DataPack. Note that the name of a file field is the convenient name with which you will look up the file. Multiple file fields can have the same filename as their value, and that file will only need to be included once.


* type=&quot;Image&quot; - value is a filename, the file should be a gif, jpg, or png ONLY. (optional attributes: width and height to force a particular size, or maxWidth and/or maxHeight to restrict the size)
* type="Image" - value is a filename, the file should be a gif, jpg, or png ONLY. (optional attributes: width and height to force a particular size, or maxWidth and/or maxHeight to restrict the size)
* type=&quot;DisplayObject&quot; - same as Image, only swf files are also applicable. Note that with the move to flash 10, you cannot use DataPack's getContents() to get and reparent a SWF that is AVM1 (flash 8 or earlier, or just compiled to actionscript 1 or 2). To add a remixable swf to your display hierarchy safely, you'll want to use getLoaders() and add the Loader.
* type="DisplayObject" - same as Image, only swf files are also applicable. Note that with the move to flash 10, you cannot use DataPack's getContents() to get and reparent a SWF that is AVM1 (flash 8 or earlier, or just compiled to actionscript 1 or 2). To add a remixable swf to your display hierarchy safely, you'll want to use getLoaders() and add the Loader.
* type=&quot;XML&quot; - the file contents will be returned as XML.
* type="XML" - the file contents will be returned as XML.
* type=&quot;Text&quot; - the file contents will be returned as one large String.
* type="Text" - the file contents will be returned as one large String.
* type=&quot;Blob&quot; - the file may contain anything
* type="Blob" - the file may contain anything


== Related Discussion Threads ==
== Related Discussion Threads ==

Latest revision as of 13:58, 4 September 2018

This is a brief introduction to DataPacks.

The Quick And Dirty

A DataPack can be used for many things. Most importantly is that they are editable. The Whirled team is building tools that will enable all users to edit DataPacks, to create new levels for your games, or to change a remixable avatar. Not all of these tools are in place yet, but by using DataPacks now you can ensure that your creation can benefit from these future enhancements.

  • Create a directory to hold the files you want in each DataPack. Let's say I call my directory "blackbird".
  • In that directory create a text file called "_data.xml" (it has to be called that, it's the special name of the data file inside a DataPack).
  • Edit _data.xml with a text editor:

<geshi lang=xml> <datapack>

<file name="level" info="Level image" type="Image" value="blackbird.png"/>
<file name="map" info="Level map: black pixels are road, white is blocked, shades of gray are 'muddy', they drive at their percent black" type="Image" value="blackbird_map.png"/>
<file name="intro" info="Intro movie to play" type="DisplayObject" value="blackbird_intro.swf"/>
<file name="outtro" info="Outgoing movie" type="DisplayObject" value="blackbird_outtro.swf"/>

</datapack> </geshi>

  • Place the referenced files in the same directory: blackbird.png, blackbird_map.png, blackbird_intro.swf, blackbird_outtro.swf"
  • Zip up all the files in that directory with any zip creator, making sure not to save any directory structure (the files should all be "flat" at the top) and with compression off (store only). For example on the unix command line I'd type "zip -0 blackbird_level.zip blackbird/*".

Because the bulk of the bytes (images and such) are already compressed, the fact that the overall datapack isn't compressed isn't such a big loss.

Common attributes

Both <file> and fields have a few shared attributes:

  • name - The name of the file or data field.
  • info - A String description of the field, shown to users when remixing.
  • optional - Not required, but if optional="true" then the field can have no value, and will return null to your code.
  • type - The type of the data or file field.
  • value - The value of the file or data field, see below for more details.

Data Types

Data fields provide access to a small piece of data.

  • type="String" - value is a String
  • type="Number" (optional attributes: min and max.) - value is interpreted as a Number
  • type="int" (optional attributes: min and max.) - value is interpreted as an int
  • type="Choice" (required attribute: "choices", an Array of values) - the value is a duplicate of one of these elements
  • type="Boolean" - value is "true" or "false"
  • type="Color" - value is a uint representing a color
  • type="Array" - value is a comma-separated array of Strings
  • type="Point" - value is two Numbers separated by a comma (x,y)
  • type="Rectangle" - value is four Numbers separated by a comma (x,y,width,height)

File Types

File fields provide access to files included in the DataPack. Note that the name of a file field is the convenient name with which you will look up the file. Multiple file fields can have the same filename as their value, and that file will only need to be included once.

  • type="Image" - value is a filename, the file should be a gif, jpg, or png ONLY. (optional attributes: width and height to force a particular size, or maxWidth and/or maxHeight to restrict the size)
  • type="DisplayObject" - same as Image, only swf files are also applicable. Note that with the move to flash 10, you cannot use DataPack's getContents() to get and reparent a SWF that is AVM1 (flash 8 or earlier, or just compiled to actionscript 1 or 2). To add a remixable swf to your display hierarchy safely, you'll want to use getLoaders() and add the Loader.
  • type="XML" - the file contents will be returned as XML.
  • type="Text" - the file contents will be returned as one large String.
  • type="Blob" - the file may contain anything

Related Discussion Threads