A rust library for parsing and modifying .vdm files used in source games.
Included features:
Add this to your Cargo.toml
[dependencies]
vdm = "1.0.0"
The quickest way to get stated is by making a brand new .vdm file and exporting it.
```rust let vdm = VDM::new();
// Include the file path you wish to export to vdm.export("example.vdm")); ```
However, this would result in a blank .vdm file. Instead, let's add a new action to it.
```rust let mut vdm = VDM::new();
// This will create a new action and automatically append it to the vdm. let mut action = vdm.create_action("SkipAhead");
// Gather the props from the action to edit them. let mut props = action.props();
// Name the action for easy organization when exported props.name = "Skip 5 seconds in".to_string();
// Skip 5 seconds into the demo props.skiptotime = Some(5.0);
// Save the new props to the action action.set_props(props);
// Save the action to the vdm vdm.set_last(action);
vdm.export("example.vdm"); ```
This is rather verbose, but we can shorten it quite a bit by knowing what we want to do.
```rust let mut vdm = VDM::new();
// createaction() always create the action at the end, we don't need to save it because it's easy to access later. let mut props = vdm.createaction("SkipAhead").props();
props.name = "Skip 5 seconds in".tostring(); props.skipto_time = Some(5.0);
// We can set the props of a specific action directly without having to modify the action first. vdm.setlastprops(props);
vdm.export("example.vdm"); ```
example.vdm
vdm
demoactions
{
"1"
{
factory "SkipAhead"
name "Unnamed"
skiptotime "5.000"
}
}
Because no start time is listed, it will happen as soon as possible after the demo starts.
You can also parse/edit existing .vdm files in a very similar way.
In this example, we're going to change when the skipping starts in the previous example.
```rust let mut vdm = VDM::open("example.vdm").unwrap();
// Grab the first actions properties. let mut props = vdm.first().props();
// This sets the starting point 100 game ticks into the demo // 66 ticks = 1 second props.start_tick = Some(100);
// You could also use vdm.setnthprops(0, props); vdm.setfirstprops(props);
vdm.export("example.vdm"); ```
example.vdm
vdm
demoactions
{
"1"
{
factory "SkipAhead"
name "Unnamed"
skiptotime "5.000"
starttick "100"
}
}
The .vdm file will only ever show actions that work with that specific action. SkipAhead will never show RGB values for example.
Let's say we need to delete the action we just made. It's simple!
```rust let mut vdm = VDM::open("example.vdm").unwrap();
// Remove whatever the last action is. vdm.remove_last();
// Alternatively you can remove the first or nth element // vdm.remove(n); // vdm.remove_first();
vdm.export("example.vdm"); ```
example.vdm
vdm
demoactions
{
}
Dev command: cargo watch -q -c -x "run -q"
License: MIT OR Apache-2.0