MCPcopy Create free account
hub / github.com/KlingAIResearch/GameFactory / parse_config

Function parse_config

visualize.py:8–54  ·  view source on GitHub ↗

根据配置生成按键数据和鼠标数据 - config: list_actions[i] 的配置 - 返回: key_data 和 mouse_data

(config)

Source from the content-addressed store, hash-verified

6
7
8def parse_config(config):
9 """
10 根据配置生成按键数据和鼠标数据
11 - config: list_actions[i] 的配置
12 - 返回: key_data 和 mouse_data
13 """
14 key_data = {}
15 mouse_data = {}
16
17 # 解析 Space 按键的帧范围
18 space_frames = set()
19 if config[-1]:
20 space_frames = set(map(int, config[-1].split()))
21
22 # 遍历配置的每一段
23 for i in range(len(config) - 1):
24 end_frame, action = config[i]
25 w, s, a, d, shift, ctrl, _, mouse_y, mouse_x = map(float, action.split())
26
27 # 计算上一段的起始帧
28 start_frame = 0 if i == 0 else config[i - 1][0] + 1
29
30 # 填充帧范围的数据
31 for frame in range(start_frame, int(end_frame) + 1):
32 # 按键状态
33 key_data[frame] = {
34 "W": bool(w),
35 "A": bool(a),
36 "S": bool(s),
37 "D": bool(d),
38 "Space": frame in space_frames,
39 "Shift": bool(shift),
40 "Ctrl": bool(ctrl),
41 }
42 # 鼠标位置
43 if frame == 0:
44 mouse_data[frame] = (320, 176) # 默认初始位置
45 else:
46 global_scale_factor = 0.4
47 mouse_scale_x = 15 * global_scale_factor
48 mouse_scale_y = 15 * 4 * global_scale_factor
49 mouse_data[frame] = (
50 mouse_data[frame-1][0] + mouse_x * mouse_scale_x, # x 坐标累计
51 mouse_data[frame-1][1] + mouse_y * mouse_scale_y, # y 坐标累计
52 )
53
54 return key_data, mouse_data
55
56
57# 绘制圆角矩形

Callers 1

process_videoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected