MCPcopy Create free account
hub / github.com/PerroEngine/Perro / parse

Method parse

perro_source/core/perro_animation/src/panim/core.rs:21–90  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

19 }
20
21 fn parse(&mut self) -> Result<AnimationClip, String> {
22 let mut name = Cow::Borrowed("Animation");
23 let mut fps = 60.0f32;
24 let mut default_interpolation = AnimationInterpolation::Linear;
25 let mut default_ease = AnimationEase::Linear;
26 let mut objects: Vec<AnimationObject> = Vec::new();
27 let mut object_types = HashMap::<String, NodeType>::new();
28 let mut frame_actions: Vec<FrameAction> = Vec::new();
29 let mut max_frame = 0u32;
30
31 while let Some((line_no, line)) = self.next_line() {
32 let line = strip_comment(line).trim();
33 if line.is_empty() {
34 continue;
35 }
36 if let Some((name, value_src)) = parse_top_level_var_assign(line) {
37 let value = self.parse_value_with_vars(value_src, line_no)?;
38 self.vars.insert(name.to_string(), value);
39 continue;
40 }
41
42 if line.eq_ignore_ascii_case("[Animation]") {
43 let (n, f, interp, ease) = self.parse_animation_block(line_no)?;
44 name = Cow::Owned(n);
45 fps = f;
46 default_interpolation = interp;
47 default_ease = ease;
48 continue;
49 }
50 if line.eq_ignore_ascii_case("[Objects]") {
51 let parsed_objects = self.parse_objects_block(line_no)?;
52 object_types.clear();
53 for obj in &parsed_objects {
54 object_types.insert(obj.name.to_string(), obj.node_type);
55 }
56 objects = parsed_objects;
57 continue;
58 }
59 if let Some((frame, key_mode)) = parse_frame_header(line) {
60 max_frame = max_frame.max(frame);
61 frame_actions.extend(self.parse_frame_block(line_no, frame, key_mode, &object_types)?);
62 continue;
63 }
64
65 return Err(format!(
66 "line {}: unexpected top-level token `{}`",
67 line_no, line
68 ));
69 }
70
71 let (object_tracks, mut frame_events) =
72 build_tracks_and_events(
73 frame_actions,
74 &object_types,
75 default_interpolation,
76 default_ease,
77 )?;
78 frame_events.sort_by_key(|e| e.frame);

Callers 1

parse_panimFunction · 0.45

Calls 14

strip_commentFunction · 0.85
parse_frame_headerFunction · 0.85
build_tracks_and_eventsFunction · 0.85
next_lineMethod · 0.80
parse_value_with_varsMethod · 0.80
parse_animation_blockMethod · 0.80
parse_objects_blockMethod · 0.80
extendMethod · 0.80
parse_frame_blockMethod · 0.80
is_emptyMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected