Skip to content

Commit 49e8e24

Browse files
authored
Update readme
1 parent c20207d commit 49e8e24

File tree

1 file changed

+53
-22
lines changed

1 file changed

+53
-22
lines changed

README.md

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,46 @@
1-
Datamodel.NET is a CLR library which implements the Datamodel structure and Datamodel Exchange file format.
1+
Datamodel.NET is a library which implements the Datamodel structure and Datamodel Exchange (DMX) file format.
22

3-
Datamodel is a strongly-typed generic data structure designed by Valve Corporation for use in their games. Datamodel Exchange is a Datamodel container file format with multiple possible encodings; binary and ASCII ("keyvalues2") are included.
3+
Datamodel is a strongly-typed generic data structure designed by Valve Corporation. It is primarily used as a developer storage format for meshes, animations, and maps.
44

5-
## Datamodel Attributes
5+
## Usage
6+
```shell
7+
dotnet add package KeyValues2
8+
```
69

7-
The following CLR types are supported as Datamodel attributes:
10+
```cs
11+
using var Datamodel;
812

9-
* `int`
10-
* `float`
11-
* `bool`
12-
* `string`
13-
* `byte`
14-
* `byte[]`
15-
* `ulong`
16-
* `System.TimeSpan`
13+
// Load a file with unknown layout
14+
var dm = Datamodel.Load("my_file.dmx");
15+
var element = dm.Root;
16+
var value = element.Get<string>("my_property");
1717

18-
Additionally, the following Datamodel.NET types are supported:
18+
// Load a file with a known layout
19+
var map = Datamodel.Load<CMapRootElement>("fy_pool.vmap");
20+
var root = (CMapRootElement)map.Root;
21+
Debug.Assert(root.IsPrefab == false);
1922

20-
* `Element` (a named collection of attributes)
21-
* `Vector2`
22-
* `Vector3` / `QAngle`
23-
* `Vector4` / `Quaternion`
24-
* `Matrix` (4x4)
25-
26-
`IList<T>` collections of the above types are also supported. (This can be a bit confusing given that both `byte` and `byte[]` are valid attribute types; use the `ByteArray` type if you run into trouble.)
23+
// Layout definition
24+
// Full implementation can be found here:
25+
/// https://github.com/ValveResourceFormat/Datamodel.NET/blob/master/Tests/ValveMap.cs
26+
[LowercaseProperties]
27+
class CMapRootElement : Element
28+
{
29+
public bool IsPrefab { get; set; }
30+
public int EditorBuild { get; set; } = 8600;
31+
public int EditorVersion { get; set; } = 400;
32+
}
33+
```
2734

28-
## Datamodel.NET features
35+
## Features
2936

3037
* Support for all known versions of Valve's `binary` and `keyvalues2` DMX encodings
3138
* Inline documentation
3239
* Binary codec supports just-in-time attribute loading
3340
* Write your own codecs with the `ICodec` interface
3441
* Serialize and deserialize support for Datamodel.Element subclasses
3542

36-
## Quick example
43+
## Serialization
3744

3845
```c#
3946
var HelloWorld = new Datamodel.Datamodel("helloworld", 1); // must provide a format name (can be anything) and version
@@ -52,3 +59,27 @@ HelloWorld.Save("hello world.dmx", "keyvalues2", 1); // must provide an encoding
5259
"Hello" "string" "World"
5360
}
5461
```
62+
63+
## Datamodel Attributes
64+
65+
The following CLR types are supported as Datamodel attributes:
66+
67+
* `int`
68+
* `float`
69+
* `bool`
70+
* `string`
71+
* `byte`
72+
* `byte[]`
73+
* `ulong`
74+
* `System.TimeSpan`
75+
76+
Additionally, the following Datamodel.NET types are supported:
77+
78+
* `Element` (a named collection of attributes)
79+
* `Vector2`
80+
* `Vector3` / `QAngle`
81+
* `Vector4` / `Quaternion`
82+
* `Matrix` (4x4)
83+
84+
`IList<T>` collections of the above types are also supported. (This can be a bit confusing given that both `byte` and `byte[]` are valid attribute types; use the `ByteArray` type if you run into trouble.)
85+

0 commit comments

Comments
 (0)