#解析 #源代码 #导出 #动作 #修改 #编辑 #引擎

vdm

一个*可能*简单的Rust包,让VDM解析和查看对源引擎游戏来说尽可能容易。

9个稳定版本

1.0.8 2024年5月27日
1.0.7 2023年3月3日
1.0.4 2023年2月26日

#293解析实现

MIT/Apache

40KB
918

VDM

一个用于解析和修改在源游戏中使用.vdm文件的Rust库。

包含的功能

  • 轻松解析.vdm文件。
  • 从头创建新的.vdm。
  • 修改、删除和添加动作。
  • 导出到文件。

用法

将此内容添加到您的Cargo.toml

[dependencies]
vdm = "1"

示例

创建新的.vdm

开始最快的方式是创建一个新的.vdm文件并将其导出。

let vdm = VDM::new();

// Include the file path you wish to export to
vdm.export("example.vdm"));

然而,这将导致一个空白的.vdm文件。相反,让我们给它添加一个新的动作。

let mut vdm = VDM::new();

// This will create a new action and automatically append it to the vdm.
let mut action = vdm.create_action(ActionType::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.skip_to_time = 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");

这相当冗长,但我们可以通过了解我们想要做什么来大大缩短它。

let mut vdm = VDM::new();

// create_action() 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.create_action(ActionType::SkipAhead).props_mut();

// Since we used .props_mut() we can directly edit the Action without needing to set anything after.
// Set is available if you want to completely replace an Action or its properties with .set_nth_props()
props.name = "Skip 5 seconds in".to_string();
props.skip_to_time = Some(5.0);

vdm.export("example.vdm");

example.vdm

demoactions
{
  "1"
  {
    factory "SkipAhead"
    name "Unnamed"
    skiptotime "5.000"
  }
}

因为没有列出开始时间,所以它将在演示开始后尽快发生。

编辑现有的.vdm文件

您也可以用非常类似的方式解析/编辑现有的.vdm文件。

在这个例子中,我们将改变上一个例子中跳过的开始时间。

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.set_nth_props(0, props);
vdm.set_first_props(props);

vdm.export("example.vdm");

或者,我们也可以使用 .first_mut() 和 .props_mut() 作为可变借用,这可以进一步缩短代码。

let mut vdm = VDM::open("example.vdm").unwrap();
// Grab the first actions properties as mutable.
let mut props = vdm.first_mut().props_mut();

// This sets the starting point 100 game ticks into the demo
// 66 ticks = 1 second
props.start_tick = Some(500);

// export without needing to set anything.
vdm.export("example.vdm");

example.vdm

demoactions
{
  "1"
  {
    factory "SkipAhead"
    name "Unnamed"
    skiptotime "5.000"
    starttick "100"
  }
}

`.vdm`文件只会显示与特定动作一起工作的动作。例如,SkipAhead永远不会显示RGB值。

删除动作

假设我们需要删除我们刚才创建的动作。很简单!

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

demoactions
{
}

动作类型

  • 跳过前
  • 停止播放
  • 播放命令
  • 屏幕渐变开始
  • 文本消息开始
  • 播放CD轨道开始
  • 播放声音开始
  • 暂停
  • 更改播放速率
  • 缩放视野

开发命令:cargo watch -q -c -x "run -q"

许可:MIT OR Apache-2.0

依赖

~2.2–3MB
~54K SLoC