diff --git a/Cargo.lock b/Cargo.lock index 4ee175c..881142a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2894,6 +2894,7 @@ dependencies = [ name = "pixlib_parser" version = "0.1.0" dependencies = [ + "anyhow", "chrono", "itertools 0.12.1", "keyboard-types", diff --git a/pixlib_parser/Cargo.toml b/pixlib_parser/Cargo.toml index fac5ad7..c11229a 100644 --- a/pixlib_parser/Cargo.toml +++ b/pixlib_parser/Cargo.toml @@ -8,6 +8,7 @@ edition = "2021" [dependencies] pixlib_formats = { path = "../pixlib_formats" } lazy_static = "1.4" +anyhow = "1.0" thiserror = "1.0" lalrpop-util = { version = "0.20", default-features = false, features = [ "lexer", diff --git a/pixlib_parser/src/parser/seq_parser.rs b/pixlib_parser/src/parser/seq_parser.rs index b305c0b..186b2a5 100644 --- a/pixlib_parser/src/parser/seq_parser.rs +++ b/pixlib_parser/src/parser/seq_parser.rs @@ -1,8 +1,15 @@ +use thiserror::Error; + use crate::{ common::{Bounds, IssueManager, Position, RemoveSearchable, Spanned}, - runner::{RunnerError, RunnerResult}, + runner::RunnerError, +}; +use std::{ + collections::HashMap, + fmt::{Display, Write}, + iter::Peekable, + sync::Arc, }; -use std::{collections::HashMap, iter::Peekable, sync::Arc}; use super::declarative_parser::{ParserError, ParserFatal, ParserIssue}; @@ -14,19 +21,56 @@ pub struct SeqBuilder { pub root_name: String, } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Error)] pub enum SeqParserError { + #[error("Sequence {0} not found in SEQ file")] ObjectNotFound(String), - LeftoverSequences(Vec), + #[error("Leftover sequences: {0}")] + LeftoverSequences(DisplayableVec), + #[error("Name missing for sequence {0}")] MissingNameDeclaration(String), + #[error("Type missing for sequence {0}")] MissingTypeDeclaration(String), + #[error("Mode missing for sequence {0}")] MissingModeDeclaration(String), + #[error("Parameter name missing for SEQEVENT of sequence {0}")] MissingParameterName(String), + #[error("Invalid parameter index {index} for sequence {name}")] InvalidParameterIndex { name: String, index: String }, + #[error("Invalid type {type_name} for sequence {name}")] InvalidSequenceType { name: String, type_name: String }, + #[error("Invalid mode {mode} for sequence {name}")] InvalidSequenceMode { name: String, mode: String }, + #[error("Invalid boolean value {value} for sequence {name}")] InvalidBooleanValue { name: String, value: String }, - LeftoverDeclarations(Vec), + #[error("Leftover declarations for sequence {name}: {declarations}")] + LeftoverDeclarations { + name: String, + declarations: DisplayableVec, + }, +} + +#[derive(Debug, Clone)] +pub struct DisplayableVec(pub Vec); + +impl DisplayableVec { + pub fn new(content: Vec) -> Self { + Self(content) + } +} + +impl Display for DisplayableVec { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_char('[')?; + if !self.0.is_empty() { + f.write_str(&self.0[0].to_string())?; + for element in self.0.iter().skip(1) { + f.write_str(", ")?; + f.write_str(&element.to_string())?; + } + } + f.write_char(']') + } } impl From for RunnerError { @@ -40,7 +84,10 @@ impl SeqBuilder { Self { root_name } } - pub fn build>(self, input: I) -> RunnerResult> { + pub fn build>( + self, + input: I, + ) -> anyhow::Result> { let mut cache: HashMap> = HashMap::new(); for next in input { let (_, declaration, _) = next.map_err(RunnerError::ParserError)?; @@ -58,7 +105,10 @@ impl SeqBuilder { } let result = Self::build_entry(self.root_name, &mut cache)?; if !cache.is_empty() { - Err(SeqParserError::LeftoverSequences(cache.into_keys().collect()).into()) + Err( + SeqParserError::LeftoverSequences(DisplayableVec(cache.into_keys().collect())) + .into(), + ) } else { Ok(result) } @@ -67,7 +117,7 @@ impl SeqBuilder { fn build_entry( name: String, cache: &mut HashMap>, - ) -> RunnerResult> { + ) -> anyhow::Result> { let Some(mut dec_list) = cache.remove(&name) else { return Err(SeqParserError::ObjectNotFound(name).into()); }; @@ -97,7 +147,7 @@ impl SeqBuilder { fn build_simple_type( name: String, mut dec_list: Vec, - ) -> RunnerResult> { + ) -> anyhow::Result> { let Some(SeqDeclaration::PropertyAssignment { value: filename, .. }) = dec_list.remove_found(|d| matches!(d, SeqDeclaration::PropertyAssignment { property, .. } if property.eq_ignore_ascii_case("FILENAME"))) else { @@ -109,7 +159,11 @@ impl SeqBuilder { return Err(SeqParserError::MissingTypeDeclaration(name).into()); }; if !dec_list.is_empty() { - Err(SeqParserError::LeftoverDeclarations(dec_list).into()) + Err(SeqParserError::LeftoverDeclarations { + name, + declarations: DisplayableVec(dec_list), + } + .into()) } else { Ok(Arc::new(SeqEntry { name, @@ -124,7 +178,7 @@ impl SeqBuilder { fn build_speaking_type( name: String, mut dec_list: Vec, - ) -> RunnerResult> { + ) -> anyhow::Result> { let Some(SeqDeclaration::PropertyAssignment { value: animation_filename, .. }) = dec_list.remove_found(|d| matches!(d, SeqDeclaration::PropertyAssignment { property, .. } if property.eq_ignore_ascii_case("ANIMOFN"))) else { @@ -173,7 +227,11 @@ impl SeqBuilder { } }; if !dec_list.is_empty() { - Err(SeqParserError::LeftoverDeclarations(dec_list).into()) + Err(SeqParserError::LeftoverDeclarations { + name, + declarations: DisplayableVec(dec_list), + } + .into()) } else { Ok(Arc::new(SeqEntry { name, @@ -192,7 +250,7 @@ impl SeqBuilder { name: String, mut dec_list: Vec, cache: &mut HashMap>, - ) -> RunnerResult> { + ) -> anyhow::Result> { let Some(SeqDeclaration::PropertyAssignment { value: mode, .. // TODO: check if property key is empty }) = dec_list.remove_found(|d| matches!(d, SeqDeclaration::PropertyAssignment { property, .. } if property.eq_ignore_ascii_case("MODE"))) else { @@ -225,7 +283,11 @@ impl SeqBuilder { children.push(Self::build_entry(child.trim().to_uppercase(), cache)?); } if !dec_list.is_empty() { - Err(SeqParserError::LeftoverDeclarations(dec_list).into()) + Err(SeqParserError::LeftoverDeclarations { + name, + declarations: DisplayableVec(dec_list), + } + .into()) } else { Ok(Arc::new(SeqEntry { name, @@ -260,6 +322,17 @@ pub enum SeqDeclaration { }, } +impl Display for SeqDeclaration { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str("SeqDeclaration::")?; + match self { + SeqDeclaration::SequenceInitialization(name) => f.write_fmt(format_args!("SequenceInitialization({name})")), + SeqDeclaration::PropertyAssignment { name, property, property_key, value } => f.write_fmt(format_args!("PropertyAssignment {{ name: {name}, property: {property}, property_key: {}, value: {value} }}", property_key.as_ref().map(|v| format!("Some({v})")).unwrap_or("None".to_owned()))), + SeqDeclaration::NestingRequest { parent, child } => f.write_fmt(format_args!("NestingRequest {{ parent: {parent}, child: {child} }}")), + } + } +} + #[derive(Debug, Clone)] pub struct SeqEntry { pub name: String, diff --git a/pixlib_parser/src/runner/classes/animation.rs b/pixlib_parser/src/runner/classes/animation.rs index 031f3a4..60321e1 100644 --- a/pixlib_parser/src/runner/classes/animation.rs +++ b/pixlib_parser/src/runner/classes/animation.rs @@ -198,51 +198,51 @@ impl Animation { animation } - pub fn is_visible(&self) -> RunnerResult { + pub fn is_visible(&self) -> anyhow::Result { self.state.borrow().is_visible() } - pub fn get_priority(&self) -> RunnerResult { + pub fn get_priority(&self) -> anyhow::Result { self.state.borrow().get_priority() } // custom - pub fn get_base_position(&self) -> RunnerResult<(isize, isize)> { + pub fn get_base_position(&self) -> anyhow::Result<(isize, isize)> { self.state.borrow().get_base_position() } - pub fn get_frame_position(&self) -> RunnerResult<(isize, isize)> { + pub fn get_frame_position(&self) -> anyhow::Result<(isize, isize)> { let context = RunnerContext::new_minimal(&self.parent.parent.runner, &self.parent); self.state.borrow().get_frame_position(context) } - pub fn get_frame_size(&self) -> RunnerResult<(usize, usize)> { + pub fn get_frame_size(&self) -> anyhow::Result<(usize, usize)> { let context = RunnerContext::new_minimal(&self.parent.parent.runner, &self.parent); self.state.borrow().get_frame_size(context) } - pub fn get_center_frame_position(&self) -> RunnerResult<(isize, isize)> { + pub fn get_center_frame_position(&self) -> anyhow::Result<(isize, isize)> { let context = RunnerContext::new_minimal(&self.parent.parent.runner, &self.parent); self.state.borrow().get_center_frame_position(context) } - pub fn does_monitor_collision(&self) -> RunnerResult { + pub fn does_monitor_collision(&self) -> anyhow::Result { Ok(self.state.borrow().does_monitor_collision) } - pub fn does_monitor_collision_pixel_perfect(&self) -> RunnerResult { + pub fn does_monitor_collision_pixel_perfect(&self) -> anyhow::Result { Ok(self.state.borrow().does_monitor_collision && self.should_collisions_respect_alpha) } - pub fn step(&self, seconds: f64) -> RunnerResult<()> { + pub fn step(&self, seconds: f64) -> anyhow::Result<()> { let context = RunnerContext::new_minimal(&self.parent.parent.runner, &self.parent); self.state.borrow_mut().step(context, seconds) } pub fn get_frame_to_show( &self, - ) -> RunnerResult> { + ) -> anyhow::Result> { // eprintln!("[ANIMO: {}] is_visible: {}", self.parent.name, self.is_visible); let context = RunnerContext::new_minimal(&self.parent.parent.runner, &self.parent); let state = self.state.borrow(); @@ -264,32 +264,34 @@ impl Animation { object_name: context.current_object.name.clone(), sequence_name: sequence.name.clone(), index: state.current_frame.frame_idx, - }); + } + .into()); }; let Some(sprite) = loaded_data.sprites.get(frame.sprite_idx) else { return Err(RunnerError::SpriteIndexNotFound { object_name: context.current_object.name.clone(), index: frame.sprite_idx, - }); + } + .into()); }; // eprintln!("[ANIMO: {}] [current frame] position: {:?} + {:?}, hash: {:?}", self.parent.name, sprite.0.offset_px, frame.offset_px, sprite.1.hash); Ok(Some((frame.clone(), sprite.0.clone(), sprite.1.clone()))) } - pub fn hide(&self) -> RunnerResult<()> { + pub fn hide(&self) -> anyhow::Result<()> { self.state.borrow_mut().hide() } - pub fn show(&self) -> RunnerResult<()> { + pub fn show(&self) -> anyhow::Result<()> { self.state.borrow_mut().show() } - pub fn play(&self, sequence_name: &str) -> RunnerResult<()> { + pub fn play(&self, sequence_name: &str) -> anyhow::Result<()> { let context = RunnerContext::new_minimal(&self.parent.parent.runner, &self.parent); self.state.borrow_mut().play(context, sequence_name) } - pub fn stop(&self, emit_on_finished: bool) -> RunnerResult<()> { + pub fn stop(&self, emit_on_finished: bool) -> anyhow::Result<()> { let context = RunnerContext::new_minimal(&self.parent.parent.runner, &self.parent); self.state.borrow_mut().stop(context, emit_on_finished) } @@ -313,7 +315,7 @@ impl CnvType for Animation { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { // println!("Calling method: {:?} of object: {:?}", name, self); match name { CallableIdentifier::Method("CLEARCLIPPING") => { @@ -585,13 +587,15 @@ impl CnvType for Animation { return Err(RunnerError::TooFewArguments { expected_min: 1, actual: 0, - }) + } + .into()) } arg_count => { return Err(RunnerError::TooManyArguments { expected_max: 2, actual: arg_count, - }) + } + .into()) } }; // if frame_no < 0 { @@ -664,7 +668,8 @@ impl CnvType for Animation { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -861,7 +866,7 @@ impl CnvType for Animation { } impl Initable for Animation { - fn initialize(&self, context: RunnerContext) -> RunnerResult<()> { + fn initialize(&self, context: RunnerContext) -> anyhow::Result<()> { let mut state = self.state.borrow_mut(); if self.should_preload { if let AnimationFileData::NotLoaded(ref filename) = *state.file_data { @@ -950,7 +955,7 @@ impl AnimationState { todo!() } - pub fn get_sequence_name(&self, context: RunnerContext) -> RunnerResult { + pub fn get_sequence_name(&self, context: RunnerContext) -> anyhow::Result { // GETEVENTNAME let sequence = self.get_sequence_data(context)?; Ok(sequence.name.clone()) @@ -976,7 +981,7 @@ impl AnimationState { todo!() } - pub fn get_frame_index(&self) -> RunnerResult { + pub fn get_frame_index(&self) -> anyhow::Result { // GETFRAMENO INTEGER Ok(self.current_frame.frame_idx) } @@ -1021,17 +1026,17 @@ impl AnimationState { todo!() } - pub fn get_frame_position_x(&self, context: RunnerContext) -> RunnerResult { + pub fn get_frame_position_x(&self, context: RunnerContext) -> anyhow::Result { // GETPOSITIONX self.get_frame_position(context).map(|p| p.0) } - pub fn get_frame_position_y(&self, context: RunnerContext) -> RunnerResult { + pub fn get_frame_position_y(&self, context: RunnerContext) -> anyhow::Result { // GETPOSITIONY self.get_frame_position(context).map(|p| p.1) } - pub fn get_priority(&self) -> RunnerResult { + pub fn get_priority(&self) -> anyhow::Result { // GETPRIORITY Ok(self.priority) } @@ -1041,7 +1046,7 @@ impl AnimationState { todo!() } - pub fn hide(&mut self) -> RunnerResult<()> { + pub fn hide(&mut self) -> anyhow::Result<()> { // HIDE self.is_visible = false; Ok(()) @@ -1067,14 +1072,14 @@ impl AnimationState { context: RunnerContext, other: Arc, min_iou_percent: usize, - ) -> RunnerResult { + ) -> anyhow::Result { // ISNEAR let current_position = self.get_frame_position(context.clone())?; let current_size = self.get_frame_size(context.clone())?; let (other_position, other_size) = match &other.content { CnvContent::Animation(a) => (a.get_frame_position()?, a.get_frame_size()?), CnvContent::Image(i) => (i.get_position()?, i.get_size()?), - _ => return Err(RunnerError::ExpectedGraphicsObject), + _ => return Err(RunnerError::ExpectedGraphicsObject.into()), }; let current_area = current_size.0 * current_size.1; let other_area = other_size.0 * other_size.1; @@ -1119,17 +1124,17 @@ impl AnimationState { Ok(intersection_area * 100 / union_area > min_iou_percent) } - pub fn is_playing(&self) -> RunnerResult { + pub fn is_playing(&self) -> anyhow::Result { // ISPLAYING BOOL Ok(self.is_playing) } - pub fn is_visible(&self) -> RunnerResult { + pub fn is_visible(&self) -> anyhow::Result { // ISVISIBLE Ok(self.is_visible) } - pub fn load(&mut self, context: RunnerContext, filename: &str) -> RunnerResult<()> { + pub fn load(&mut self, context: RunnerContext, filename: &str) -> anyhow::Result<()> { // LOAD let script = context.current_object.parent.as_ref(); let filesystem = Arc::clone(&script.runner.filesystem); @@ -1210,7 +1215,7 @@ impl AnimationState { self.does_monitor_collision = true; } - pub fn move_by(&mut self, x: isize, y: isize) -> RunnerResult<()> { + pub fn move_by(&mut self, x: isize, y: isize) -> anyhow::Result<()> { // MOVE self.position = (self.position.0 + x, self.position.1 + y); Ok(()) @@ -1226,7 +1231,7 @@ impl AnimationState { todo!() } - pub fn pause(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn pause(&mut self, context: RunnerContext) -> anyhow::Result<()> { // PAUSE self.is_paused = true; let current_sequence_name = match *self.file_data { @@ -1254,14 +1259,16 @@ impl AnimationState { Ok(()) } - pub fn play(&mut self, context: RunnerContext, sequence_name: &str) -> RunnerResult<()> { + pub fn play(&mut self, context: RunnerContext, sequence_name: &str) -> anyhow::Result<()> { // PLAY (STRING) if let AnimationFileData::NotLoaded(ref filename) = *self.file_data { let filename = filename.clone(); self.load(context.clone(), &filename)?; }; let AnimationFileData::Loaded(ref loaded_data) = *self.file_data.clone() else { - return Err(RunnerError::NoDataLoaded); + return Err( + RunnerError::NoAnimationDataLoaded(context.current_object.name.clone()).into(), + ); }; let (sequence_idx, sequence) = loaded_data .sequences @@ -1331,7 +1338,7 @@ impl AnimationState { todo!() } - pub fn resume(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn resume(&mut self, context: RunnerContext) -> anyhow::Result<()> { // RESUME self.is_paused = false; let current_sequence_name = match *self.file_data { @@ -1389,7 +1396,11 @@ impl AnimationState { self.fps = fps; } - pub fn set_frame(&mut self, sequence_name: Option<&str>, frame_no: usize) -> RunnerResult<()> { + pub fn set_frame( + &mut self, + sequence_name: Option<&str>, + frame_no: usize, + ) -> anyhow::Result<()> { // SETFRAME ([STRING], INTEGER) if let Some(_sequence_name) = sequence_name { todo!() @@ -1419,13 +1430,13 @@ impl AnimationState { todo!() } - pub fn set_position(&mut self, x: isize, y: isize) -> RunnerResult<()> { + pub fn set_position(&mut self, x: isize, y: isize) -> anyhow::Result<()> { // SETPOSITION self.position = (x, y); Ok(()) } - pub fn set_priority(&mut self, priority: isize) -> RunnerResult<()> { + pub fn set_priority(&mut self, priority: isize) -> anyhow::Result<()> { // SETPRIORITY self.priority = priority; Ok(()) @@ -1441,20 +1452,22 @@ impl AnimationState { todo!() } - pub fn show(&mut self) -> RunnerResult<()> { + pub fn show(&mut self) -> anyhow::Result<()> { // SHOW self.is_visible = true; Ok(()) } - pub fn stop(&mut self, context: RunnerContext, emit_on_finished: bool) -> RunnerResult<()> { + pub fn stop(&mut self, context: RunnerContext, emit_on_finished: bool) -> anyhow::Result<()> { // STOP ([BOOL]) if let AnimationFileData::NotLoaded(ref filename) = *self.file_data { let filename = filename.clone(); self.load(context.clone(), &filename)?; }; let AnimationFileData::Loaded(ref loaded_data) = *self.file_data.clone() else { - return Err(RunnerError::NoDataLoaded); + return Err( + RunnerError::NoAnimationDataLoaded(context.current_object.name.clone()).into(), + ); }; if !self.is_playing { return Ok(()); @@ -1497,11 +1510,11 @@ impl AnimationState { 1f64 / (self.fps as f64) } - pub fn get_base_position(&self) -> RunnerResult<(isize, isize)> { + pub fn get_base_position(&self) -> anyhow::Result<(isize, isize)> { Ok(self.position) } - pub fn get_frame_position(&self, context: RunnerContext) -> RunnerResult<(isize, isize)> { + pub fn get_frame_position(&self, context: RunnerContext) -> anyhow::Result<(isize, isize)> { let (_, frame, sprite) = self.get_sprite_data(context)?; Ok(( self.position.0 + frame.offset_px.0 as isize + sprite.0.offset_px.0 as isize, @@ -1509,7 +1522,7 @@ impl AnimationState { )) } - pub fn get_frame_size(&self, context: RunnerContext) -> RunnerResult<(usize, usize)> { + pub fn get_frame_size(&self, context: RunnerContext) -> anyhow::Result<(usize, usize)> { let (_, _, sprite) = self.get_sprite_data(context)?; Ok((sprite.0.size_px.0 as usize, sprite.0.size_px.1 as usize)) } @@ -1517,7 +1530,7 @@ impl AnimationState { pub fn get_center_frame_position( &self, context: RunnerContext, - ) -> RunnerResult<(isize, isize)> { + ) -> anyhow::Result<(isize, isize)> { let (_, frame, sprite) = self.get_sprite_data(context)?; Ok(( self.position.0 @@ -1531,15 +1544,18 @@ impl AnimationState { )) } - fn get_sequence_data(&self, context: RunnerContext) -> RunnerResult<&SequenceDefinition> { + fn get_sequence_data(&self, context: RunnerContext) -> anyhow::Result<&SequenceDefinition> { let AnimationFileData::Loaded(ref loaded_file) = *self.file_data else { - return Err(RunnerError::NoDataLoaded); + return Err( + RunnerError::NoAnimationDataLoaded(context.current_object.name.clone()).into(), + ); }; let Some(sequence) = loaded_file.sequences.get(self.current_frame.sequence_idx) else { return Err(RunnerError::SequenceIndexNotFound { object_name: context.current_object.name.clone(), index: self.current_frame.sequence_idx, - }); + } + .into()); }; Ok(sequence) } @@ -1547,14 +1563,15 @@ impl AnimationState { fn get_frame_data( &self, context: RunnerContext, - ) -> RunnerResult<(&SequenceDefinition, &FrameDefinition)> { + ) -> anyhow::Result<(&SequenceDefinition, &FrameDefinition)> { let sequence = self.get_sequence_data(context.clone())?; let Some(frame) = sequence.frames.get(self.current_frame.frame_idx) else { return Err(RunnerError::FrameIndexNotFound { object_name: context.current_object.name.clone(), sequence_name: sequence.name.clone(), index: self.current_frame.frame_idx, - }); + } + .into()); }; Ok((sequence, frame)) } @@ -1562,25 +1579,28 @@ impl AnimationState { fn get_sprite_data( &self, context: RunnerContext, - ) -> RunnerResult<( + ) -> anyhow::Result<( &SequenceDefinition, &FrameDefinition, &(SpriteDefinition, SpriteData), )> { let AnimationFileData::Loaded(ref loaded_file) = *self.file_data else { - return Err(RunnerError::NoDataLoaded); + return Err( + RunnerError::NoAnimationDataLoaded(context.current_object.name.clone()).into(), + ); }; let (sequence, frame) = self.get_frame_data(context.clone())?; let Some(sprite) = loaded_file.sprites.get(frame.sprite_idx) else { return Err(RunnerError::SpriteIndexNotFound { object_name: context.current_object.name.clone(), index: frame.sprite_idx, - }); + } + .into()); }; Ok((sequence, frame, sprite)) } - pub fn step(&mut self, context: RunnerContext, seconds: f64) -> RunnerResult<()> { + pub fn step(&mut self, context: RunnerContext, seconds: f64) -> anyhow::Result<()> { let file_data = self.file_data.clone(); let AnimationFileData::Loaded(ref loaded_data) = *file_data else { return Ok(()); @@ -1670,7 +1690,7 @@ impl AnimationState { Ok(()) } - fn load_sfx(&mut self, context: RunnerContext, path: &ScenePath) -> RunnerResult<()> { + fn load_sfx(&mut self, context: RunnerContext, path: &ScenePath) -> anyhow::Result<()> { let script = context.current_object.parent.as_ref(); let filesystem = Arc::clone(&script.runner.filesystem); let data = filesystem @@ -1705,7 +1725,7 @@ impl AnimationState { Ok(()) } - fn play_sfx(&mut self, context: RunnerContext, path: &str) -> RunnerResult<()> { + fn play_sfx(&mut self, context: RunnerContext, path: &str) -> anyhow::Result<()> { if !matches!(self.current_sfx, SoundFileData::Loaded(ref loaded) if loaded.filename.as_deref() == Some(path)) { self.load_sfx( diff --git a/pixlib_parser/src/runner/classes/application.rs b/pixlib_parser/src/runner/classes/application.rs index c169ea7..260543f 100644 --- a/pixlib_parser/src/runner/classes/application.rs +++ b/pixlib_parser/src/runner/classes/application.rs @@ -115,7 +115,7 @@ impl CnvType for Application { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { match name { CallableIdentifier::Method("DISABLEMUSIC") => { self.state.borrow_mut().disable_music().map(|_| None) @@ -173,7 +173,8 @@ impl CnvType for Application { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -222,82 +223,82 @@ impl CnvType for Application { } impl ApplicationState { - pub fn disable_music(&mut self) -> RunnerResult<()> { + pub fn disable_music(&mut self) -> anyhow::Result<()> { // DISABLEMUSIC todo!() } - pub fn enable_music(&mut self) -> RunnerResult<()> { + pub fn enable_music(&mut self) -> anyhow::Result<()> { // ENABLEMUSIC todo!() } - pub fn exists_env(&self) -> RunnerResult { + pub fn exists_env(&self) -> anyhow::Result { // EXISTSENV todo!() } - pub fn exit(&mut self) -> RunnerResult<()> { + pub fn exit(&mut self) -> anyhow::Result<()> { // EXIT todo!() } - pub fn get_language(&self) -> RunnerResult { + pub fn get_language(&self) -> anyhow::Result { // GETLANGUAGE todo!() } - pub fn get_player(&self) -> RunnerResult { + pub fn get_player(&self) -> anyhow::Result { // GETPLAYER todo!() } - pub fn goto(&mut self) -> RunnerResult<()> { + pub fn goto(&mut self) -> anyhow::Result<()> { // GOTO todo!() } - pub fn print(&mut self) -> RunnerResult<()> { + pub fn print(&mut self) -> anyhow::Result<()> { // PRINT todo!() } - pub fn reload(&mut self) -> RunnerResult<()> { + pub fn reload(&mut self) -> anyhow::Result<()> { // RELOAD todo!() } - pub fn restart(&mut self) -> RunnerResult<()> { + pub fn restart(&mut self) -> anyhow::Result<()> { // RESTART todo!() } - pub fn run(&mut self) -> RunnerResult<()> { + pub fn run(&mut self) -> anyhow::Result<()> { // RUN todo!() } - pub fn run_env(&mut self) -> RunnerResult<()> { + pub fn run_env(&mut self) -> anyhow::Result<()> { // RUNENV todo!() } - pub fn set_language(&mut self) -> RunnerResult<()> { + pub fn set_language(&mut self) -> anyhow::Result<()> { // SETLANGUAGE todo!() } - pub fn start_dragging_window(&mut self) -> RunnerResult<()> { + pub fn start_dragging_window(&mut self) -> anyhow::Result<()> { // STARTDRAGGINGWINDOW todo!() } - pub fn stop_dragging_window(&mut self) -> RunnerResult<()> { + pub fn stop_dragging_window(&mut self) -> anyhow::Result<()> { // STOPDRAGGINGWINDOW todo!() } - pub fn store_binary(&mut self) -> RunnerResult<()> { + pub fn store_binary(&mut self) -> anyhow::Result<()> { // STOREBINARY todo!() } diff --git a/pixlib_parser/src/runner/classes/array.rs b/pixlib_parser/src/runner/classes/array.rs index 8ad8506..9aed581 100644 --- a/pixlib_parser/src/runner/classes/array.rs +++ b/pixlib_parser/src/runner/classes/array.rs @@ -98,7 +98,7 @@ impl CnvType for Array { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { match name { CallableIdentifier::Method("ADD") => self.state.borrow_mut().add().map(|_| None), CallableIdentifier::Method("ADDAT") => self.state.borrow_mut().add_at().map(|_| None), @@ -206,7 +206,8 @@ impl CnvType for Array { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -254,7 +255,7 @@ impl CnvType for Array { } impl Initable for Array { - fn initialize(&self, context: RunnerContext) -> RunnerResult<()> { + fn initialize(&self, context: RunnerContext) -> anyhow::Result<()> { context .runner .internal_events @@ -271,272 +272,272 @@ impl Initable for Array { } impl ArrayState { - pub fn add(&mut self) -> RunnerResult<()> { + pub fn add(&mut self) -> anyhow::Result<()> { // ADD todo!() } - pub fn add_at(&mut self) -> RunnerResult<()> { + pub fn add_at(&mut self) -> anyhow::Result<()> { // ADDAT todo!() } - pub fn add_clones(&mut self) -> RunnerResult<()> { + pub fn add_clones(&mut self) -> anyhow::Result<()> { // ADDCLONES todo!() } - pub fn change_at(&mut self) -> RunnerResult<()> { + pub fn change_at(&mut self) -> anyhow::Result<()> { // CHANGEAT todo!() } - pub fn clamp_at(&mut self) -> RunnerResult<()> { + pub fn clamp_at(&mut self) -> anyhow::Result<()> { // CLAMPAT todo!() } - pub fn compare(&self) -> RunnerResult<()> { + pub fn compare(&self) -> anyhow::Result<()> { // COMPARE todo!() } - pub fn contains(&self) -> RunnerResult { + pub fn contains(&self) -> anyhow::Result { // CONTAINS todo!() } - pub fn copy_to(&mut self) -> RunnerResult<()> { + pub fn copy_to(&mut self) -> anyhow::Result<()> { // COPYTO todo!() } - pub fn dir(&mut self) -> RunnerResult<()> { + pub fn dir(&mut self) -> anyhow::Result<()> { // DIR todo!() } - pub fn div(&mut self) -> RunnerResult<()> { + pub fn div(&mut self) -> anyhow::Result<()> { // DIV todo!() } - pub fn div_a(&mut self) -> RunnerResult<()> { + pub fn div_a(&mut self) -> anyhow::Result<()> { // DIVA todo!() } - pub fn div_at(&mut self) -> RunnerResult<()> { + pub fn div_at(&mut self) -> anyhow::Result<()> { // DIVAT todo!() } - pub fn fill(&mut self) -> RunnerResult<()> { + pub fn fill(&mut self) -> anyhow::Result<()> { // FILL todo!() } - pub fn find(&self) -> RunnerResult> { + pub fn find(&self) -> anyhow::Result> { // FIND todo!() } - pub fn find_all(&self) -> RunnerResult> { + pub fn find_all(&self) -> anyhow::Result> { // FINDALL todo!() } - pub fn get(&self) -> RunnerResult> { + pub fn get(&self) -> anyhow::Result> { // GET todo!() } - pub fn get_marker_pos(&self) -> RunnerResult { + pub fn get_marker_pos(&self) -> anyhow::Result { // GETMARKERPOS todo!() } - pub fn get_size(&self) -> RunnerResult { + pub fn get_size(&self) -> anyhow::Result { // GETSIZE todo!() } - pub fn get_sum_value(&self) -> RunnerResult { + pub fn get_sum_value(&self) -> anyhow::Result { // GETSUMVALUE todo!() } - pub fn insert_at(&mut self) -> RunnerResult<()> { + pub fn insert_at(&mut self) -> anyhow::Result<()> { // INSERTAT todo!() } - pub fn load(&mut self) -> RunnerResult<()> { + pub fn load(&mut self) -> anyhow::Result<()> { // LOAD todo!() } - pub fn load_ini(&mut self) -> RunnerResult<()> { + pub fn load_ini(&mut self) -> anyhow::Result<()> { // LOADINI todo!() } - pub fn max(&mut self) -> RunnerResult<()> { + pub fn max(&mut self) -> anyhow::Result<()> { // MAX todo!() } - pub fn max_d(&mut self) -> RunnerResult<()> { + pub fn max_d(&mut self) -> anyhow::Result<()> { // MAXD todo!() } - pub fn min(&mut self) -> RunnerResult<()> { + pub fn min(&mut self) -> anyhow::Result<()> { // MIN todo!() } - pub fn min_d(&mut self) -> RunnerResult<()> { + pub fn min_d(&mut self) -> anyhow::Result<()> { // MIND todo!() } - pub fn mod_at(&mut self) -> RunnerResult<()> { + pub fn mod_at(&mut self) -> anyhow::Result<()> { // MODAT todo!() } - pub fn mul(&mut self) -> RunnerResult<()> { + pub fn mul(&mut self) -> anyhow::Result<()> { // MUL todo!() } - pub fn mul_a(&mut self) -> RunnerResult<()> { + pub fn mul_a(&mut self) -> anyhow::Result<()> { // MULA todo!() } - pub fn mul_at(&mut self) -> RunnerResult<()> { + pub fn mul_at(&mut self) -> anyhow::Result<()> { // MULAT todo!() } - pub fn next(&mut self) -> RunnerResult<()> { + pub fn next(&mut self) -> anyhow::Result<()> { // NEXT todo!() } - pub fn prev(&mut self) -> RunnerResult<()> { + pub fn prev(&mut self) -> anyhow::Result<()> { // PREV todo!() } - pub fn random_fill(&mut self) -> RunnerResult<()> { + pub fn random_fill(&mut self) -> anyhow::Result<()> { // RANDOMFILL todo!() } - pub fn remove(&mut self) -> RunnerResult<()> { + pub fn remove(&mut self) -> anyhow::Result<()> { // REMOVE todo!() } - pub fn remove_all(&mut self) -> RunnerResult<()> { + pub fn remove_all(&mut self) -> anyhow::Result<()> { // REMOVEALL todo!() } - pub fn remove_at(&mut self) -> RunnerResult<()> { + pub fn remove_at(&mut self) -> anyhow::Result<()> { // REMOVEAT todo!() } - pub fn reset_marker(&mut self) -> RunnerResult<()> { + pub fn reset_marker(&mut self) -> anyhow::Result<()> { // RESETMARKER todo!() } - pub fn reverse_find(&self) -> RunnerResult> { + pub fn reverse_find(&self) -> anyhow::Result> { // REVERSEFIND todo!() } - pub fn rotate_left(&mut self) -> RunnerResult<()> { + pub fn rotate_left(&mut self) -> anyhow::Result<()> { // ROTATELEFT todo!() } - pub fn rotate_right(&mut self) -> RunnerResult<()> { + pub fn rotate_right(&mut self) -> anyhow::Result<()> { // ROTATERIGHT todo!() } - pub fn save(&mut self) -> RunnerResult<()> { + pub fn save(&mut self) -> anyhow::Result<()> { // SAVE todo!() } - pub fn save_ini(&mut self) -> RunnerResult<()> { + pub fn save_ini(&mut self) -> anyhow::Result<()> { // SAVEINI todo!() } - pub fn send_on_change(&mut self) -> RunnerResult<()> { + pub fn send_on_change(&mut self) -> anyhow::Result<()> { // SENDONCHANGE todo!() } - pub fn set_marker_pos(&mut self) -> RunnerResult<()> { + pub fn set_marker_pos(&mut self) -> anyhow::Result<()> { // SETMARKERPOS todo!() } - pub fn shift_left(&mut self) -> RunnerResult<()> { + pub fn shift_left(&mut self) -> anyhow::Result<()> { // SHIFTLEFT todo!() } - pub fn shift_right(&mut self) -> RunnerResult<()> { + pub fn shift_right(&mut self) -> anyhow::Result<()> { // SHIFTRIGHT todo!() } - pub fn sort(&mut self) -> RunnerResult<()> { + pub fn sort(&mut self) -> anyhow::Result<()> { // SORT todo!() } - pub fn sort_many(&mut self) -> RunnerResult<()> { + pub fn sort_many(&mut self) -> anyhow::Result<()> { // SORTMANY todo!() } - pub fn sub(&mut self) -> RunnerResult<()> { + pub fn sub(&mut self) -> anyhow::Result<()> { // SUB todo!() } - pub fn sub_a(&mut self) -> RunnerResult<()> { + pub fn sub_a(&mut self) -> anyhow::Result<()> { // SUBA todo!() } - pub fn sub_at(&mut self) -> RunnerResult<()> { + pub fn sub_at(&mut self) -> anyhow::Result<()> { // SUBAT todo!() } - pub fn sum(&mut self) -> RunnerResult<()> { + pub fn sum(&mut self) -> anyhow::Result<()> { // SUM todo!() } - pub fn sum_a(&mut self) -> RunnerResult<()> { + pub fn sum_a(&mut self) -> anyhow::Result<()> { // SUMA todo!() } - pub fn swap(&mut self) -> RunnerResult<()> { + pub fn swap(&mut self) -> anyhow::Result<()> { // SWAP todo!() } diff --git a/pixlib_parser/src/runner/classes/behavior.rs b/pixlib_parser/src/runner/classes/behavior.rs index 4e3eacc..35000d9 100644 --- a/pixlib_parser/src/runner/classes/behavior.rs +++ b/pixlib_parser/src/runner/classes/behavior.rs @@ -82,7 +82,7 @@ impl Behavior { &self, context: RunnerContext, arguments: Vec, - ) -> RunnerResult> { + ) -> anyhow::Result> { if let Some(code) = self.code.as_ref() { self.state.borrow().run(context, code.clone(), arguments) } else { @@ -94,7 +94,7 @@ impl Behavior { &self, context: RunnerContext, arguments: Vec, - ) -> RunnerResult> { + ) -> anyhow::Result> { if let Some(code) = self.code.as_ref() { self.state .borrow() @@ -123,7 +123,7 @@ impl CnvType for Behavior { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { // println!("Calling method: {:?} of object: {:?}", name, self); let context = context.with_current_object(self.parent.clone()); match name { @@ -171,7 +171,8 @@ impl CnvType for Behavior { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -218,7 +219,7 @@ impl CnvType for Behavior { } impl Initable for Behavior { - fn initialize(&self, context: RunnerContext) -> RunnerResult<()> { + fn initialize(&self, context: RunnerContext) -> anyhow::Result<()> { context .runner .internal_events @@ -242,7 +243,7 @@ impl Initable for Behavior { } impl BehaviorState { - pub fn break_run(&self) -> RunnerResult<()> { + pub fn break_run(&self) -> anyhow::Result<()> { // BREAK todo!() } @@ -252,7 +253,7 @@ impl BehaviorState { context: RunnerContext, code: Arc, arguments: Vec, - ) -> RunnerResult> { + ) -> anyhow::Result> { // RUN // eprintln!( // "Running behavior {} with arguments [{}]", @@ -263,7 +264,7 @@ impl BehaviorState { code.calculate(context) } - pub fn disable(&mut self) -> RunnerResult<()> { + pub fn disable(&mut self) -> anyhow::Result<()> { // DISABLE self.is_enabled = false; Ok(()) @@ -275,7 +276,7 @@ impl BehaviorState { code: Arc, condition_name: Option<&str>, arguments: Vec, - ) -> RunnerResult> { + ) -> anyhow::Result> { // RUNC if let Some(condition) = condition_name { let condition_object = context.runner.get_object(condition).unwrap(); @@ -288,13 +289,13 @@ impl BehaviorState { return Ok(None); } } else { - return Err(RunnerError::ExpectedConditionObject); + return Err(RunnerError::ExpectedConditionObject.into()); } } self.run(context, code, arguments) } - pub fn run_looped(&self) -> RunnerResult<()> { + pub fn run_looped(&self) -> anyhow::Result<()> { // RUNLOOPED todo!() } diff --git a/pixlib_parser/src/runner/classes/bool.rs b/pixlib_parser/src/runner/classes/bool.rs index 78443af..c106d44 100644 --- a/pixlib_parser/src/runner/classes/bool.rs +++ b/pixlib_parser/src/runner/classes/bool.rs @@ -98,7 +98,7 @@ impl BoolVar { } } - pub fn get(&self) -> RunnerResult { + pub fn get(&self) -> anyhow::Result { self.state.borrow().get() } } @@ -121,7 +121,7 @@ impl CnvType for BoolVar { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { match name { CallableIdentifier::Method("AND") => self .state @@ -181,7 +181,8 @@ impl CnvType for BoolVar { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -271,7 +272,7 @@ impl CnvType for BoolVar { } impl Initable for BoolVar { - fn initialize(&self, context: RunnerContext) -> RunnerResult<()> { + fn initialize(&self, context: RunnerContext) -> anyhow::Result<()> { context .runner .internal_events @@ -290,24 +291,24 @@ impl Initable for BoolVar { const I32_WITH_CLEARED_U8: i32 = 0xffffff00u32 as i32; impl BoolVarState { - pub fn and(&mut self, context: RunnerContext, operand: i32) -> RunnerResult { + pub fn and(&mut self, context: RunnerContext, operand: i32) -> anyhow::Result { // AND self.change_value(context, self.value & operand); Ok(self.value) } - pub fn clear(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn clear(&mut self, context: RunnerContext) -> anyhow::Result<()> { // CLEAR self.change_value(context, self.value & I32_WITH_CLEARED_U8); Ok(()) } - pub fn copy_file(&mut self, _context: RunnerContext) -> RunnerResult<()> { + pub fn copy_file(&mut self, _context: RunnerContext) -> anyhow::Result<()> { // COPYFILE todo!() } - pub fn dec(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn dec(&mut self, context: RunnerContext) -> anyhow::Result<()> { // DEC let value = match self.value as u8 { 0 => (self.value & I32_WITH_CLEARED_U8) | 0x01, @@ -321,39 +322,39 @@ impl BoolVarState { Ok(()) } - pub fn get(&self) -> RunnerResult { + pub fn get(&self) -> anyhow::Result { // GET Ok(self.value as u8 == 1) } - pub fn inc(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn inc(&mut self, context: RunnerContext) -> anyhow::Result<()> { // INC self.dec(context) } - pub fn not(&mut self, context: RunnerContext) -> RunnerResult { + pub fn not(&mut self, context: RunnerContext) -> anyhow::Result { // NOT self.change_value(context, !self.value); Ok(self.value) } - pub fn or(&mut self, context: RunnerContext, operand: i32) -> RunnerResult { + pub fn or(&mut self, context: RunnerContext, operand: i32) -> anyhow::Result { // OR self.change_value(context, self.value | operand); Ok(self.value) } - pub fn random(&mut self, _context: RunnerContext) -> RunnerResult<()> { + pub fn random(&mut self, _context: RunnerContext) -> anyhow::Result<()> { // RANDOM todo!() } - pub fn reset_ini(&mut self, _context: RunnerContext) -> RunnerResult<()> { + pub fn reset_ini(&mut self, _context: RunnerContext) -> anyhow::Result<()> { // RESETINI todo!() } - pub fn set(&mut self, context: RunnerContext, value: bool) -> RunnerResult<()> { + pub fn set(&mut self, context: RunnerContext, value: bool) -> anyhow::Result<()> { // SET self.change_value( context, @@ -366,18 +367,18 @@ impl BoolVarState { &mut self, _context: RunnerContext, default_value: bool, - ) -> RunnerResult<()> { + ) -> anyhow::Result<()> { // SETDEFAULT self.default_value = default_value; Ok(()) } - pub fn switch(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn switch(&mut self, context: RunnerContext) -> anyhow::Result<()> { // SWITCH self.dec(context) } - pub fn xor(&mut self, context: RunnerContext, operand: i32) -> RunnerResult { + pub fn xor(&mut self, context: RunnerContext, operand: i32) -> anyhow::Result { // XOR self.change_value(context, self.value ^ operand); Ok(self.value) diff --git a/pixlib_parser/src/runner/classes/button.rs b/pixlib_parser/src/runner/classes/button.rs index 2e820ae..7aea5ce 100644 --- a/pixlib_parser/src/runner/classes/button.rs +++ b/pixlib_parser/src/runner/classes/button.rs @@ -156,11 +156,11 @@ impl Button { // custom - pub fn is_displaying(&self, object_name: &str) -> RunnerResult { + pub fn is_displaying(&self, object_name: &str) -> anyhow::Result { self.state.borrow().is_displaying(object_name) } - pub fn set_normal(&self) -> RunnerResult<()> { + pub fn set_normal(&self) -> anyhow::Result<()> { // println!("{}.set_normal()", self.parent.name); self.state.borrow_mut().try_set_interaction( RunnerContext::new_minimal(&self.parent.parent.runner, &self.parent), @@ -168,7 +168,7 @@ impl Button { ) } - pub fn set_hovering(&self) -> RunnerResult<()> { + pub fn set_hovering(&self) -> anyhow::Result<()> { // println!("{}.set_hovering()", self.parent.name); self.state.borrow_mut().try_set_interaction( RunnerContext::new_minimal(&self.parent.parent.runner, &self.parent), @@ -176,7 +176,7 @@ impl Button { ) } - pub fn set_pressing(&self) -> RunnerResult<()> { + pub fn set_pressing(&self) -> anyhow::Result<()> { // println!("{}.set_pressing()", self.parent.name); self.state.borrow_mut().try_set_interaction( RunnerContext::new_minimal(&self.parent.parent.runner, &self.parent), @@ -184,7 +184,7 @@ impl Button { ) } - pub fn promote_to_hovering_or_keep_pressing(&self) -> RunnerResult<()> { + pub fn promote_to_hovering_or_keep_pressing(&self) -> anyhow::Result<()> { // println!("{}.keep_pressing()", self.parent.name); self.state .borrow_mut() @@ -213,7 +213,7 @@ impl CnvType for Button { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { // println!("Calling method: {:?} of object: {:?}", name, self); match name { CallableIdentifier::Method("ACCENT") => self.state.borrow_mut().accent().map(|_| None), @@ -268,7 +268,8 @@ impl CnvType for Button { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -408,10 +409,10 @@ impl CnvType for Button { } impl Initable for Button { - fn initialize(&self, context: RunnerContext) -> RunnerResult<()> { + fn initialize(&self, context: RunnerContext) -> anyhow::Result<()> { self.state .borrow_mut() - .use_and_drop_mut::>(|state| { + .use_and_drop_mut(|state| -> anyhow::Result<()> { state.set_interaction(context.clone(), Interaction::Hidden)?; if state.is_enabled { state.set_interaction(context.clone(), Interaction::None)?; @@ -434,85 +435,85 @@ impl Initable for Button { } impl ButtonState { - pub fn accent(&mut self) -> RunnerResult<()> { + pub fn accent(&mut self) -> anyhow::Result<()> { // ACCENT todo!() } - pub fn disable(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn disable(&mut self, context: RunnerContext) -> anyhow::Result<()> { // DISABLE self.is_enabled = false; self.set_interaction(context, Interaction::Hidden) } - pub fn disable_but_visible(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn disable_but_visible(&mut self, context: RunnerContext) -> anyhow::Result<()> { // DISABLEBUTVISIBLE self.is_enabled = false; self.set_interaction(context, Interaction::None) } - pub fn disable_dragging(&mut self) -> RunnerResult<()> { + pub fn disable_dragging(&mut self) -> anyhow::Result<()> { // DISABLEDRAGGING todo!() } - pub fn enable(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn enable(&mut self, context: RunnerContext) -> anyhow::Result<()> { // ENABLE self.is_enabled = true; self.set_interaction(context, Interaction::None) } - pub fn enable_dragging(&mut self) -> RunnerResult<()> { + pub fn enable_dragging(&mut self) -> anyhow::Result<()> { // ENABLEDRAGGING todo!() } - pub fn get_on_click(&self) -> RunnerResult> { + pub fn get_on_click(&self) -> anyhow::Result> { // GETONCLICK todo!() } - pub fn get_on_move(&self) -> RunnerResult> { + pub fn get_on_move(&self) -> anyhow::Result> { // GETONMOVE todo!() } - pub fn get_priority(&self) -> RunnerResult { + pub fn get_priority(&self) -> anyhow::Result { // GETPRIORITY todo!() } - pub fn get_std(&self) -> RunnerResult> { + pub fn get_std(&self) -> anyhow::Result> { // GETSTD todo!() } - pub fn set_on_click(&mut self) -> RunnerResult<()> { + pub fn set_on_click(&mut self) -> anyhow::Result<()> { // SETONCLICK todo!() } - pub fn set_on_move(&mut self) -> RunnerResult<()> { + pub fn set_on_move(&mut self) -> anyhow::Result<()> { // SETONMOVE todo!() } - pub fn set_priority(&mut self) -> RunnerResult<()> { + pub fn set_priority(&mut self) -> anyhow::Result<()> { // SETPRIORITY todo!() } - pub fn set_rect(&mut self) -> RunnerResult<()> { + pub fn set_rect(&mut self) -> anyhow::Result<()> { // SETRECT todo!() } - pub fn set_std(&mut self) -> RunnerResult<()> { + pub fn set_std(&mut self) -> anyhow::Result<()> { // SETSTD todo!() } - pub fn syn(&mut self) -> RunnerResult<()> { + pub fn syn(&mut self) -> anyhow::Result<()> { // SYN todo!() } @@ -523,7 +524,7 @@ impl ButtonState { &mut self, context: RunnerContext, interaction: Interaction, - ) -> RunnerResult<()> { + ) -> anyhow::Result<()> { // println!( // "{}.set_interaction({:?})", // context.current_object.name, interaction @@ -555,7 +556,7 @@ impl ButtonState { normal_animation.hide() } } else { - Err(RunnerError::ExpectedGraphicsObject) + Err(RunnerError::ExpectedGraphicsObject.into()) }? } /*else { println!( @@ -569,7 +570,7 @@ impl ButtonState { .and_then(|name| context.runner.get_object(name)) { let CnvContent::Sound(normal_sound) = &normal_sound_obj.content else { - return Err(RunnerError::ExpectedSoundObject); + return Err(RunnerError::ExpectedSoundObject.into()); }; if interaction == Interaction::None { normal_sound.play() @@ -596,7 +597,7 @@ impl ButtonState { on_hover_animation.hide() } } else { - Err(RunnerError::ExpectedGraphicsObject) + Err(RunnerError::ExpectedGraphicsObject.into()) }? } /*else { println!( @@ -610,7 +611,7 @@ impl ButtonState { .and_then(|name| context.runner.get_object(name)) { let CnvContent::Sound(on_hover_sound) = &on_hover_sound_obj.content else { - return Err(RunnerError::ExpectedSoundObject); + return Err(RunnerError::ExpectedSoundObject.into()); }; if interaction == Interaction::Hovering { on_hover_sound.play() @@ -637,7 +638,7 @@ impl ButtonState { on_click_animation.hide() } } else { - Err(RunnerError::ExpectedGraphicsObject) + Err(RunnerError::ExpectedGraphicsObject.into()) }? } /*else { println!( @@ -651,7 +652,7 @@ impl ButtonState { .and_then(|name| context.runner.get_object(name)) { let CnvContent::Sound(on_click_sound) = &on_click_sound_obj.content else { - return Err(RunnerError::ExpectedSoundObject); + return Err(RunnerError::ExpectedSoundObject.into()); }; if interaction == Interaction::Pressing { on_click_sound.play() @@ -716,7 +717,7 @@ impl ButtonState { &mut self, context: RunnerContext, interaction: Interaction, - ) -> RunnerResult<()> { + ) -> anyhow::Result<()> { if !self.is_enabled { return Ok(()); } @@ -729,7 +730,7 @@ impl ButtonState { pub fn promote_to_hovering_or_keep_pressing( &mut self, context: RunnerContext, - ) -> RunnerResult<()> { + ) -> anyhow::Result<()> { if matches!( self.current_interaction, Interaction::Pressing | Interaction::Hovering @@ -739,7 +740,7 @@ impl ButtonState { self.try_set_interaction(context, Interaction::Hovering) } - pub fn is_displaying(&self, object_name: &str) -> RunnerResult { + pub fn is_displaying(&self, object_name: &str) -> anyhow::Result { Ok(match self.current_interaction { Interaction::Hidden => false, Interaction::None => self diff --git a/pixlib_parser/src/runner/classes/canvasobserver.rs b/pixlib_parser/src/runner/classes/canvasobserver.rs index af6f3bc..2457477 100644 --- a/pixlib_parser/src/runner/classes/canvasobserver.rs +++ b/pixlib_parser/src/runner/classes/canvasobserver.rs @@ -113,7 +113,7 @@ impl CnvType for CanvasObserver { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { // println!("Calling method: {:?} of object: {:?}", name, self); match name { CallableIdentifier::Method("ADD") => self.state.borrow_mut().add().map(|_| None), @@ -163,7 +163,8 @@ impl CnvType for CanvasObserver { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -234,7 +235,7 @@ impl CnvType for CanvasObserver { } impl Initable for CanvasObserver { - fn initialize(&self, context: RunnerContext) -> RunnerResult<()> { + fn initialize(&self, context: RunnerContext) -> anyhow::Result<()> { context .runner .internal_events @@ -251,67 +252,67 @@ impl Initable for CanvasObserver { } impl CanvasObserverState { - pub fn add(&mut self) -> RunnerResult<()> { + pub fn add(&mut self) -> anyhow::Result<()> { // ADD todo!() } - pub fn enable_notify(&mut self) -> RunnerResult<()> { + pub fn enable_notify(&mut self) -> anyhow::Result<()> { // ENABLENOTIFY todo!() } - pub fn get_bpp(&self) -> RunnerResult { + pub fn get_bpp(&self) -> anyhow::Result { // GETBPP Ok(32) } - pub fn get_graphics_at(&self) -> RunnerResult> { + pub fn get_graphics_at(&self) -> anyhow::Result> { // GETGRAPHICSAT todo!() } - pub fn get_graphics_at2(&self) -> RunnerResult> { + pub fn get_graphics_at2(&self) -> anyhow::Result> { // GETGRAPHICSAT2 todo!() } - pub fn move_bkg(&mut self) -> RunnerResult<()> { + pub fn move_bkg(&mut self) -> anyhow::Result<()> { // MOVEBKG todo!() } - pub fn paste(&mut self) -> RunnerResult<()> { + pub fn paste(&mut self) -> anyhow::Result<()> { // PASTE todo!() } - pub fn redraw(&mut self) -> RunnerResult<()> { + pub fn redraw(&mut self) -> anyhow::Result<()> { // REDRAW todo!() } - pub fn refresh(&mut self) -> RunnerResult<()> { + pub fn refresh(&mut self) -> anyhow::Result<()> { // REFRESH todo!() } - pub fn remove(&mut self) -> RunnerResult<()> { + pub fn remove(&mut self) -> anyhow::Result<()> { // REMOVE todo!() } - pub fn save(&mut self) -> RunnerResult<()> { + pub fn save(&mut self) -> anyhow::Result<()> { // SAVE todo!() } - pub fn set_background(&mut self) -> RunnerResult<()> { + pub fn set_background(&mut self) -> anyhow::Result<()> { // SETBACKGROUND todo!() } - pub fn set_bkg_pos(&mut self) -> RunnerResult<()> { + pub fn set_bkg_pos(&mut self) -> anyhow::Result<()> { // SETBKGPOS todo!() } diff --git a/pixlib_parser/src/runner/classes/cnvloader.rs b/pixlib_parser/src/runner/classes/cnvloader.rs index a26db5d..0af81d3 100644 --- a/pixlib_parser/src/runner/classes/cnvloader.rs +++ b/pixlib_parser/src/runner/classes/cnvloader.rs @@ -66,7 +66,7 @@ impl CnvType for CnvLoader { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { match name { CallableIdentifier::Method("LOAD") => self.state.borrow_mut().load().map(|_| None), CallableIdentifier::Method("RELEASE") => { @@ -84,7 +84,8 @@ impl CnvType for CnvLoader { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -101,12 +102,12 @@ impl CnvType for CnvLoader { } impl CnvLoaderState { - pub fn load(&mut self) -> RunnerResult<()> { + pub fn load(&mut self) -> anyhow::Result<()> { // LOAD todo!() } - pub fn release(&mut self) -> RunnerResult<()> { + pub fn release(&mut self) -> anyhow::Result<()> { // RELEASE todo!() } diff --git a/pixlib_parser/src/runner/classes/complexcondition.rs b/pixlib_parser/src/runner/classes/complexcondition.rs index 4174025..3496a35 100644 --- a/pixlib_parser/src/runner/classes/complexcondition.rs +++ b/pixlib_parser/src/runner/classes/complexcondition.rs @@ -69,7 +69,7 @@ impl ComplexCondition { } } - pub fn check(&self) -> RunnerResult { + pub fn check(&self) -> anyhow::Result { let context = RunnerContext::new_minimal(&self.parent.parent.runner, &self.parent); self.state.borrow().check(context) } @@ -93,7 +93,7 @@ impl CnvType for ComplexCondition { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { match name { CallableIdentifier::Method("BREAK") => self.state.borrow().break_run().map(|_| None), CallableIdentifier::Method("CHECK") => self @@ -116,7 +116,8 @@ impl CnvType for ComplexCondition { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -163,12 +164,12 @@ impl CnvType for ComplexCondition { } impl ComplexConditionState { - pub fn break_run(&self) -> RunnerResult<()> { + pub fn break_run(&self) -> anyhow::Result<()> { // BREAK todo!() } - pub fn check(&self, context: RunnerContext) -> RunnerResult { + pub fn check(&self, context: RunnerContext) -> anyhow::Result { // TODO: allow for complexconditions built on other complexconditions let CnvContent::ComplexCondition(ref complex_condition) = &context.current_object.content else { @@ -230,7 +231,7 @@ impl ComplexConditionState { result } - pub fn one_break(&self) -> RunnerResult<()> { + pub fn one_break(&self) -> anyhow::Result<()> { // ONE_BREAK todo!() } diff --git a/pixlib_parser/src/runner/classes/condition.rs b/pixlib_parser/src/runner/classes/condition.rs index 6b5a6b9..7abd7a8 100644 --- a/pixlib_parser/src/runner/classes/condition.rs +++ b/pixlib_parser/src/runner/classes/condition.rs @@ -72,7 +72,7 @@ impl Condition { } } - pub fn check(&self) -> RunnerResult { + pub fn check(&self) -> anyhow::Result { let context = RunnerContext::new_minimal(&self.parent.parent.runner, &self.parent); self.state.borrow().check(context) } @@ -96,7 +96,7 @@ impl CnvType for Condition { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { // eprintln!( // "Calling method {:?} of condition {}", // name, self.parent.name @@ -123,7 +123,8 @@ impl CnvType for Condition { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -173,11 +174,11 @@ impl CnvType for Condition { } impl ConditionState { - pub fn break_run(&self) -> RunnerResult<()> { + pub fn break_run(&self) -> anyhow::Result<()> { todo!() } - pub fn check(&self, context: RunnerContext) -> RunnerResult { + pub fn check(&self, context: RunnerContext) -> anyhow::Result { let CnvContent::Condition(ref condition) = &context.current_object.content else { panic!(); }; @@ -243,7 +244,7 @@ impl ConditionState { result } - pub fn one_break(&self) -> RunnerResult<()> { + pub fn one_break(&self) -> anyhow::Result<()> { todo!() } } diff --git a/pixlib_parser/src/runner/classes/double.rs b/pixlib_parser/src/runner/classes/double.rs index 414eb45..97d82c8 100644 --- a/pixlib_parser/src/runner/classes/double.rs +++ b/pixlib_parser/src/runner/classes/double.rs @@ -103,7 +103,7 @@ impl DoubleVar { } } - pub fn get(&self) -> RunnerResult { + pub fn get(&self) -> anyhow::Result { self.state.borrow().get() } } @@ -126,7 +126,7 @@ impl CnvType for DoubleVar { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { match name { CallableIdentifier::Method("ADD") => self .state @@ -189,7 +189,8 @@ impl CnvType for DoubleVar { return Err(RunnerError::TooFewArguments { expected_min: 1, actual: 0, - }); + } + .into()); } self.state .borrow_mut() @@ -201,7 +202,8 @@ impl CnvType for DoubleVar { return Err(RunnerError::TooFewArguments { expected_min: 1, actual: 0, - }); + } + .into()); } self.state .borrow_mut() @@ -281,7 +283,8 @@ impl CnvType for DoubleVar { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -371,7 +374,7 @@ impl CnvType for DoubleVar { } impl Initable for DoubleVar { - fn initialize(&self, context: RunnerContext) -> RunnerResult<()> { + fn initialize(&self, context: RunnerContext) -> anyhow::Result<()> { context .runner .internal_events @@ -391,13 +394,13 @@ const RADIANS_TO_DEGREES: f64 = 180f64 / f64::consts::PI; const DEGREES_TO_RADIANS: f64 = f64::consts::PI / 180f64; impl DoubleVarState { - pub fn add(&mut self, context: RunnerContext, operand: f64) -> RunnerResult { + pub fn add(&mut self, context: RunnerContext, operand: f64) -> anyhow::Result { // ADD self.change_value(context, self.value + operand); Ok(self.value) } - pub fn arc_tan(&mut self, context: RunnerContext, tangent: f64) -> RunnerResult { + pub fn arc_tan(&mut self, context: RunnerContext, tangent: f64) -> anyhow::Result { // ARCTAN self.change_value(context, tangent.atan() * RADIANS_TO_DEGREES); Ok(self.value) @@ -409,7 +412,7 @@ impl DoubleVarState { y: f64, x: f64, summand: Option, - ) -> RunnerResult { + ) -> anyhow::Result { // ARCTANEX let mut value = (libm::atan2(y, x) + f64::consts::PI) * RADIANS_TO_DEGREES; if let Some(summand) = summand { @@ -419,59 +422,59 @@ impl DoubleVarState { Ok(self.value) } - pub fn clamp(&mut self, context: RunnerContext, min: f64, max: f64) -> RunnerResult { + pub fn clamp(&mut self, context: RunnerContext, min: f64, max: f64) -> anyhow::Result { // CLAMP self.change_value(context, self.value.clamp(min, max)); Ok(self.value) } - pub fn clear(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn clear(&mut self, context: RunnerContext) -> anyhow::Result<()> { // CLEAR self.change_value(context, 0f64); Ok(()) } - pub fn copy_file(&mut self, _context: RunnerContext) -> RunnerResult { + pub fn copy_file(&mut self, _context: RunnerContext) -> anyhow::Result { // COPYFILE todo!() } - pub fn cosinus(&mut self, context: RunnerContext, angle_degrees: f64) -> RunnerResult { + pub fn cosinus(&mut self, context: RunnerContext, angle_degrees: f64) -> anyhow::Result { // COSINUS self.change_value(context, (angle_degrees * DEGREES_TO_RADIANS).cos()); Ok(self.value) } - pub fn dec(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn dec(&mut self, context: RunnerContext) -> anyhow::Result<()> { // DEC self.change_value(context, self.value - 1f64); Ok(()) } - pub fn div(&mut self, context: RunnerContext, divisor: f64) -> RunnerResult<()> { + pub fn div(&mut self, context: RunnerContext, divisor: f64) -> anyhow::Result<()> { // DIV self.change_value(context, self.value / divisor); Ok(()) } - pub fn get(&self) -> RunnerResult { + pub fn get(&self) -> anyhow::Result { // GET Ok(self.value) } - pub fn inc(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn inc(&mut self, context: RunnerContext) -> anyhow::Result<()> { // INC self.change_value(context, self.value + 1f64); Ok(()) } - pub fn length(&mut self, context: RunnerContext, x: f64, y: f64) -> RunnerResult { + pub fn length(&mut self, context: RunnerContext, x: f64, y: f64) -> anyhow::Result { // LENGTH self.change_value(context, (x.powi(2) + y.powi(2)).sqrt()); Ok(self.value) } - pub fn log(&mut self, context: RunnerContext, operand: f64) -> RunnerResult { + pub fn log(&mut self, context: RunnerContext, operand: f64) -> anyhow::Result { // LOG self.change_value(context, operand.ln()); Ok(self.value) @@ -481,7 +484,7 @@ impl DoubleVarState { &mut self, context: RunnerContext, arguments: impl Iterator, - ) -> RunnerResult { + ) -> anyhow::Result { // MAXA self.change_value(context, arguments.reduce(f64::max).unwrap()); Ok(self.value) @@ -491,59 +494,63 @@ impl DoubleVarState { &mut self, context: RunnerContext, arguments: impl Iterator, - ) -> RunnerResult { + ) -> anyhow::Result { // MINA self.change_value(context, arguments.reduce(f64::min).unwrap()); Ok(self.value) } - pub fn modulus(&mut self, context: RunnerContext, divisor: i32) -> RunnerResult<()> { + pub fn modulus(&mut self, context: RunnerContext, divisor: i32) -> anyhow::Result<()> { // MOD self.change_value(context, (self.value as i32 % divisor) as f64); Ok(()) } - pub fn mul(&mut self, context: RunnerContext, operand: f64) -> RunnerResult<()> { + pub fn mul(&mut self, context: RunnerContext, operand: f64) -> anyhow::Result<()> { // MUL self.change_value(context, self.value * operand); Ok(()) } - pub fn power(&mut self, context: RunnerContext, exponent: f64) -> RunnerResult { + pub fn power(&mut self, context: RunnerContext, exponent: f64) -> anyhow::Result { // POWER self.change_value(context, self.value.powf(exponent)); Ok(self.value) } - pub fn random(&mut self, _context: RunnerContext) -> RunnerResult { + pub fn random(&mut self, _context: RunnerContext) -> anyhow::Result { // RANDOM todo!() } - pub fn reset_ini(&mut self, _context: RunnerContext) -> RunnerResult<()> { + pub fn reset_ini(&mut self, _context: RunnerContext) -> anyhow::Result<()> { // RESETINI todo!() } - pub fn round(&mut self, context: RunnerContext) -> RunnerResult { + pub fn round(&mut self, context: RunnerContext) -> anyhow::Result { // ROUND self.change_value(context, self.value.round()); Ok(self.value as i32) } - pub fn set(&mut self, context: RunnerContext, value: f64) -> RunnerResult<()> { + pub fn set(&mut self, context: RunnerContext, value: f64) -> anyhow::Result<()> { // SET self.change_value(context, value); Ok(()) } - pub fn set_default(&mut self, _context: RunnerContext, default_value: f64) -> RunnerResult<()> { + pub fn set_default( + &mut self, + _context: RunnerContext, + default_value: f64, + ) -> anyhow::Result<()> { // SETDEFAULT self.default_value = default_value; Ok(()) } - pub fn sgn(&self) -> RunnerResult { + pub fn sgn(&self) -> anyhow::Result { // SGN Ok(if self.value == 0.0 || self.value.is_nan() { 0 @@ -554,25 +561,30 @@ impl DoubleVarState { }) } - pub fn sinus(&mut self, context: RunnerContext, angle_degrees: f64) -> RunnerResult { + pub fn sinus(&mut self, context: RunnerContext, angle_degrees: f64) -> anyhow::Result { // SINUS self.change_value(context, (angle_degrees * DEGREES_TO_RADIANS).sin()); Ok(self.value) } - pub fn sqrt(&mut self, context: RunnerContext) -> RunnerResult { + pub fn sqrt(&mut self, context: RunnerContext) -> anyhow::Result { // SQRT self.change_value(context, self.value.sqrt()); Ok(self.value) } - pub fn sub(&mut self, context: RunnerContext, subtrahend: f64) -> RunnerResult { + pub fn sub(&mut self, context: RunnerContext, subtrahend: f64) -> anyhow::Result { // SUB self.change_value(context, self.value - subtrahend); Ok(self.value) } - pub fn switch(&mut self, context: RunnerContext, first: f64, second: f64) -> RunnerResult<()> { + pub fn switch( + &mut self, + context: RunnerContext, + first: f64, + second: f64, + ) -> anyhow::Result<()> { // SWITCH self.change_value(context, if self.value == first { second } else { first }); Ok(()) diff --git a/pixlib_parser/src/runner/classes/episode.rs b/pixlib_parser/src/runner/classes/episode.rs index 95de8ac..7ac6201 100644 --- a/pixlib_parser/src/runner/classes/episode.rs +++ b/pixlib_parser/src/runner/classes/episode.rs @@ -101,7 +101,7 @@ impl CnvType for Episode { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { // println!("Calling method: {:?} of object: {:?}", name, self); match name { CallableIdentifier::Method("BACK") => self.state.borrow_mut().back().map(|_| None), @@ -133,7 +133,8 @@ impl CnvType for Episode { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -178,37 +179,37 @@ impl CnvType for Episode { } impl EpisodeState { - pub fn back(&mut self) -> RunnerResult<()> { + pub fn back(&mut self) -> anyhow::Result<()> { // BACK todo!() } - pub fn get_current_scene(&self) -> RunnerResult<()> { + pub fn get_current_scene(&self) -> anyhow::Result<()> { // GETCURRENTSCENE todo!() } - pub fn get_latest_scene(&self) -> RunnerResult<()> { + pub fn get_latest_scene(&self) -> anyhow::Result<()> { // GETLATESTSCENE todo!() } - pub fn go_to(&mut self, context: RunnerContext, scene_name: &str) -> RunnerResult<()> { + pub fn go_to(&mut self, context: RunnerContext, scene_name: &str) -> anyhow::Result<()> { // GOTO context.runner.change_scene(scene_name) } - pub fn next(&mut self) -> RunnerResult<()> { + pub fn next(&mut self) -> anyhow::Result<()> { // NEXT todo!() } - pub fn prev(&mut self) -> RunnerResult<()> { + pub fn prev(&mut self) -> anyhow::Result<()> { // PREV todo!() } - pub fn restart(&mut self) -> RunnerResult<()> { + pub fn restart(&mut self) -> anyhow::Result<()> { // RESTART todo!() } diff --git a/pixlib_parser/src/runner/classes/expression.rs b/pixlib_parser/src/runner/classes/expression.rs index 525cb5e..81b6521 100644 --- a/pixlib_parser/src/runner/classes/expression.rs +++ b/pixlib_parser/src/runner/classes/expression.rs @@ -58,7 +58,7 @@ impl Expression { // custom - pub fn calculate(&self) -> RunnerResult { + pub fn calculate(&self) -> anyhow::Result { let context = RunnerContext::new_minimal(&self.parent.parent.runner, &self.parent); let left = self .left @@ -110,7 +110,7 @@ impl CnvType for Expression { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { match name { CallableIdentifier::Event(event_name) => { if let Some(code) = self @@ -124,7 +124,8 @@ impl CnvType for Expression { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } diff --git a/pixlib_parser/src/runner/classes/font.rs b/pixlib_parser/src/runner/classes/font.rs index edeae84..7afce51 100644 --- a/pixlib_parser/src/runner/classes/font.rs +++ b/pixlib_parser/src/runner/classes/font.rs @@ -96,7 +96,7 @@ impl CnvType for Font { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { match name { CallableIdentifier::Method("GETHEIGHT") => self .state @@ -127,7 +127,8 @@ impl CnvType for Font { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -178,7 +179,7 @@ impl CnvType for Font { } impl Initable for Font { - fn initialize(&self, context: RunnerContext) -> RunnerResult<()> { + fn initialize(&self, context: RunnerContext) -> anyhow::Result<()> { context .runner .internal_events @@ -195,27 +196,27 @@ impl Initable for Font { } impl FontState { - pub fn get_height(&self) -> RunnerResult { + pub fn get_height(&self) -> anyhow::Result { // GETHEIGHT todo!() } - pub fn set_color(&mut self) -> RunnerResult<()> { + pub fn set_color(&mut self) -> anyhow::Result<()> { // SETCOLOR todo!() } - pub fn set_family(&mut self) -> RunnerResult<()> { + pub fn set_family(&mut self) -> anyhow::Result<()> { // SETFAMILY todo!() } - pub fn set_size(&mut self) -> RunnerResult<()> { + pub fn set_size(&mut self) -> anyhow::Result<()> { // SETSIZE todo!() } - pub fn set_style(&mut self) -> RunnerResult<()> { + pub fn set_style(&mut self) -> anyhow::Result<()> { // SETSTYLE todo!() } diff --git a/pixlib_parser/src/runner/classes/group.rs b/pixlib_parser/src/runner/classes/group.rs index 6f1bd22..9753bad 100644 --- a/pixlib_parser/src/runner/classes/group.rs +++ b/pixlib_parser/src/runner/classes/group.rs @@ -85,7 +85,7 @@ impl CnvType for Group { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { match name { CallableIdentifier::Method("ADD") => { let name = arguments[0].to_str(); @@ -196,7 +196,7 @@ impl CnvType for Group { } impl Initable for Group { - fn initialize(&self, context: RunnerContext) -> RunnerResult<()> { + fn initialize(&self, context: RunnerContext) -> anyhow::Result<()> { context .runner .internal_events @@ -213,63 +213,63 @@ impl Initable for Group { } impl GroupState { - pub fn add(&mut self, added_object: Arc) -> RunnerResult<()> { + pub fn add(&mut self, added_object: Arc) -> anyhow::Result<()> { // ADD self.objects.push(added_object); Ok(()) } - pub fn add_clones(&mut self) -> RunnerResult<()> { + pub fn add_clones(&mut self) -> anyhow::Result<()> { // ADDCLONES todo!() } - pub fn clone_object(&mut self) -> RunnerResult<()> { + pub fn clone_object(&mut self) -> anyhow::Result<()> { // CLONE todo!() } - pub fn contains(&mut self) -> RunnerResult<()> { + pub fn contains(&mut self) -> anyhow::Result<()> { // CONTAINS todo!() } - pub fn get_clone_index(&self) -> RunnerResult { + pub fn get_clone_index(&self) -> anyhow::Result { // GETCLONEINDEX todo!() } - pub fn get_marker_pos(&self) -> RunnerResult { + pub fn get_marker_pos(&self) -> anyhow::Result { // GETMARKERPOS todo!() } - pub fn get_name(&self) -> RunnerResult { + pub fn get_name(&self) -> anyhow::Result { // GETNAME todo!() } - pub fn get_name_at_marker(&self) -> RunnerResult { + pub fn get_name_at_marker(&self) -> anyhow::Result { // GETNAMEATMARKER todo!() } - pub fn get_size(&self) -> RunnerResult { + pub fn get_size(&self) -> anyhow::Result { // GETSIZE todo!() } - pub fn next(&mut self) -> RunnerResult<()> { + pub fn next(&mut self) -> anyhow::Result<()> { // NEXT todo!() } - pub fn prev(&mut self) -> RunnerResult<()> { + pub fn prev(&mut self) -> anyhow::Result<()> { // PREV todo!() } - pub fn remove(&mut self, name: &str) -> RunnerResult<()> { + pub fn remove(&mut self, name: &str) -> anyhow::Result<()> { // REMOVE let index = self.objects.iter().position(|o| o.name == name).ok_or( RunnerError::ObjectNotFound { @@ -280,18 +280,18 @@ impl GroupState { Ok(()) } - pub fn remove_all(&mut self) -> RunnerResult<()> { + pub fn remove_all(&mut self) -> anyhow::Result<()> { // REMOVEALL self.objects.clear(); Ok(()) } - pub fn reset_marker(&mut self) -> RunnerResult<()> { + pub fn reset_marker(&mut self) -> anyhow::Result<()> { // RESETMARKER todo!() } - pub fn set_marker_pos(&mut self) -> RunnerResult<()> { + pub fn set_marker_pos(&mut self) -> anyhow::Result<()> { // SETMARKERPOS todo!() } @@ -303,7 +303,7 @@ impl GroupState { context: RunnerContext, callable: CallableIdentifier, arguments: &[CnvValue], - ) -> RunnerResult<()> { + ) -> anyhow::Result<()> { let mut err_result = None; for object in self.objects.iter() { let result = object.call_method(callable.clone(), arguments, Some(context.clone())); diff --git a/pixlib_parser/src/runner/classes/image.rs b/pixlib_parser/src/runner/classes/image.rs index c850063..9640fb6 100644 --- a/pixlib_parser/src/runner/classes/image.rs +++ b/pixlib_parser/src/runner/classes/image.rs @@ -139,37 +139,39 @@ impl Image { image } - pub fn is_visible(&self) -> RunnerResult { + pub fn is_visible(&self) -> anyhow::Result { self.state.borrow().is_visible() } - pub fn get_priority(&self) -> RunnerResult { + pub fn get_priority(&self) -> anyhow::Result { self.state.borrow().get_priority() } // custom - pub fn get_position(&self) -> RunnerResult<(isize, isize)> { + pub fn get_position(&self) -> anyhow::Result<(isize, isize)> { self.state.borrow().get_position() } - pub fn get_size(&self) -> RunnerResult<(usize, usize)> { - self.state.borrow().get_size() + pub fn get_size(&self) -> anyhow::Result<(usize, usize)> { + let context = RunnerContext::new_minimal(&self.parent.parent.runner, &self.parent); + self.state.borrow().get_size(context) } - pub fn get_center_position(&self) -> RunnerResult<(isize, isize)> { - self.state.borrow().get_center_position() + pub fn get_center_position(&self) -> anyhow::Result<(isize, isize)> { + let context = RunnerContext::new_minimal(&self.parent.parent.runner, &self.parent); + self.state.borrow().get_center_position(context) } - pub fn does_monitor_collision(&self) -> RunnerResult { + pub fn does_monitor_collision(&self) -> anyhow::Result { Ok(self.state.borrow().does_monitor_collision) } - pub fn does_monitor_collision_pixel_perfect(&self) -> RunnerResult { + pub fn does_monitor_collision_pixel_perfect(&self) -> anyhow::Result { Ok(self.state.borrow().does_monitor_collision && self.should_collisions_respect_alpha) } - pub fn get_image_to_show(&self) -> RunnerResult> { + pub fn get_image_to_show(&self) -> anyhow::Result> { let state = self.state.borrow(); if !state.is_visible { return Ok(None); @@ -181,11 +183,11 @@ impl Image { Ok(Some((image.0.clone(), image.1.clone()))) } - pub fn hide(&self) -> RunnerResult<()> { + pub fn hide(&self) -> anyhow::Result<()> { self.state.borrow_mut().hide() } - pub fn show(&self) -> RunnerResult<()> { + pub fn show(&self) -> anyhow::Result<()> { self.state.borrow_mut().show() } } @@ -208,7 +210,7 @@ impl CnvType for Image { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { // println!("Calling method: {:?} of object: {:?}", name, self); match name { CallableIdentifier::Method("CLEARCLIPPING") => { @@ -286,7 +288,7 @@ impl CnvType for Image { .ok_or(RunnerError::ObjectNotFound { name })?; self.state .borrow() - .is_near(other, arguments[1].to_int().max(0) as usize) + .is_near(context, other, arguments[1].to_int().max(0) as usize) .map(|v| Some(CnvValue::Bool(v))) } CallableIdentifier::Method("ISVISIBLE") => self @@ -379,7 +381,8 @@ impl CnvType for Image { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -506,7 +509,7 @@ impl CnvType for Image { } impl Initable for Image { - fn initialize(&self, context: RunnerContext) -> RunnerResult<()> { + fn initialize(&self, context: RunnerContext) -> anyhow::Result<()> { let mut state = self.state.borrow_mut(); if self.should_preload { if let ImageFileData::NotLoaded(filename) = &state.file_data { @@ -530,132 +533,137 @@ impl Initable for Image { } impl ImageState { - pub fn clear_clipping(&mut self) -> RunnerResult<()> { + pub fn clear_clipping(&mut self) -> anyhow::Result<()> { // CLEARCLIPPING todo!() } - pub fn draw_onto(&mut self) -> RunnerResult<()> { + pub fn draw_onto(&mut self) -> anyhow::Result<()> { // DRAWONTO todo!() } - pub fn flip_h(&mut self) -> RunnerResult<()> { + pub fn flip_h(&mut self) -> anyhow::Result<()> { // FLIPH self.is_flipped_horizontally = !self.is_flipped_horizontally; Ok(()) } - pub fn flip_v(&mut self) -> RunnerResult<()> { + pub fn flip_v(&mut self) -> anyhow::Result<()> { // FLIPV self.is_flipped_vertically = !self.is_flipped_vertically; Ok(()) } - pub fn get_alpha(&mut self) -> RunnerResult<()> { + pub fn get_alpha(&mut self) -> anyhow::Result<()> { // GETALPHA todo!() } - pub fn get_center_x(&mut self) -> RunnerResult<()> { + pub fn get_center_x(&mut self) -> anyhow::Result<()> { // GETCENTERX todo!() } - pub fn get_center_y(&mut self) -> RunnerResult<()> { + pub fn get_center_y(&mut self) -> anyhow::Result<()> { // GETCENTERY todo!() } - pub fn get_color_at(&mut self) -> RunnerResult<()> { + pub fn get_color_at(&mut self) -> anyhow::Result<()> { // GETCOLORAT todo!() } - pub fn get_color_b_at(&mut self) -> RunnerResult<()> { + pub fn get_color_b_at(&mut self) -> anyhow::Result<()> { // GETCOLORBAT todo!() } - pub fn get_color_g_at(&mut self) -> RunnerResult<()> { + pub fn get_color_g_at(&mut self) -> anyhow::Result<()> { // GETCOLORGAT todo!() } - pub fn get_color_r_at(&mut self) -> RunnerResult<()> { + pub fn get_color_r_at(&mut self) -> anyhow::Result<()> { // GETCOLORRAT todo!() } - pub fn get_height(&mut self) -> RunnerResult<()> { + pub fn get_height(&mut self) -> anyhow::Result<()> { // GETHEIGHT todo!() } - pub fn get_opacity(&mut self) -> RunnerResult<()> { + pub fn get_opacity(&mut self) -> anyhow::Result<()> { // GETOPACITY todo!() } - pub fn get_pixel(&mut self) -> RunnerResult<()> { + pub fn get_pixel(&mut self) -> anyhow::Result<()> { // GETPIXEL todo!() } - pub fn get_position_x(&self) -> RunnerResult { + pub fn get_position_x(&self) -> anyhow::Result { // GETPOSITIONX Ok(self.position.0) } - pub fn get_position_y(&self) -> RunnerResult { + pub fn get_position_y(&self) -> anyhow::Result { // GETPOSITIONY Ok(self.position.1) } - pub fn get_priority(&self) -> RunnerResult { + pub fn get_priority(&self) -> anyhow::Result { // GETPRIORITY Ok(self.priority) } - pub fn get_slide_comps(&mut self) -> RunnerResult<()> { + pub fn get_slide_comps(&mut self) -> anyhow::Result<()> { // GETSLIDECOMPS todo!() } - pub fn get_width(&mut self) -> RunnerResult<()> { + pub fn get_width(&mut self) -> anyhow::Result<()> { // GETWIDTH todo!() } - pub fn hide(&mut self) -> RunnerResult<()> { + pub fn hide(&mut self) -> anyhow::Result<()> { // HIDE self.is_visible = false; Ok(()) } - pub fn invalidate(&mut self) -> RunnerResult<()> { + pub fn invalidate(&mut self) -> anyhow::Result<()> { // INVALIDATE todo!() } - pub fn is_at(&mut self) -> RunnerResult<()> { + pub fn is_at(&mut self) -> anyhow::Result<()> { // ISAT todo!() } - pub fn is_inside(&mut self) -> RunnerResult<()> { + pub fn is_inside(&mut self) -> anyhow::Result<()> { // ISINSIDE todo!() } - pub fn is_near(&self, other: Arc, min_iou_percent: usize) -> RunnerResult { + pub fn is_near( + &self, + context: RunnerContext, + other: Arc, + min_iou_percent: usize, + ) -> anyhow::Result { // ISNEAR let current_position = self.get_position()?; - let current_size = self.get_size()?; + let current_size = self.get_size(context.clone())?; let (other_position, other_size) = match &other.content { CnvContent::Animation(a) => (a.get_frame_position()?, a.get_frame_size()?), CnvContent::Image(i) => (i.get_position()?, i.get_size()?), - _ => return Err(RunnerError::ExpectedGraphicsObject), + _ => return Err(RunnerError::ExpectedGraphicsObject.into()), }; let current_area = current_size.0 * current_size.1; let other_area = other_size.0 * other_size.1; @@ -700,17 +708,17 @@ impl ImageState { Ok(intersection_area * 100 / union_area > min_iou_percent) } - pub fn is_visible(&self) -> RunnerResult { + pub fn is_visible(&self) -> anyhow::Result { // ISVISIBLE Ok(self.is_visible) } - pub fn link(&mut self) -> RunnerResult<()> { + pub fn link(&mut self) -> anyhow::Result<()> { // LINK todo!() } - pub fn load(&mut self, context: RunnerContext, filename: &str) -> RunnerResult<()> { + pub fn load(&mut self, context: RunnerContext, filename: &str) -> anyhow::Result<()> { // LOAD let script = context.current_object.parent.as_ref(); let filesystem = Arc::clone(&script.runner.filesystem); @@ -748,96 +756,96 @@ impl ImageState { Ok(()) } - pub fn merge_alpha(&mut self) -> RunnerResult<()> { + pub fn merge_alpha(&mut self) -> anyhow::Result<()> { // MERGEALPHA todo!() } - pub fn merge_alpha2(&mut self) -> RunnerResult<()> { + pub fn merge_alpha2(&mut self) -> anyhow::Result<()> { // MERGEALPHA2 todo!() } - pub fn monitor_collision(&mut self) -> RunnerResult<()> { + pub fn monitor_collision(&mut self) -> anyhow::Result<()> { // MONITORCOLLISION todo!() } - pub fn move_by(&mut self, x: isize, y: isize) -> RunnerResult<()> { + pub fn move_by(&mut self, x: isize, y: isize) -> anyhow::Result<()> { // MOVE self.position = (self.position.0 + x, self.position.1 + y); Ok(()) } - pub fn remove_monitor_collision(&mut self) -> RunnerResult<()> { + pub fn remove_monitor_collision(&mut self) -> anyhow::Result<()> { // REMOVEMONITORCOLLISION todo!() } - pub fn replace_color(&mut self) -> RunnerResult<()> { + pub fn replace_color(&mut self) -> anyhow::Result<()> { // REPLACECOLOR todo!() } - pub fn reset_flips(&mut self) -> RunnerResult<()> { + pub fn reset_flips(&mut self) -> anyhow::Result<()> { // RESETFLIPS todo!() } - pub fn reset_position(&mut self) -> RunnerResult<()> { + pub fn reset_position(&mut self) -> anyhow::Result<()> { // RESETPOSITION self.position = self.default_position; Ok(()) } - pub fn save(&mut self) -> RunnerResult<()> { + pub fn save(&mut self) -> anyhow::Result<()> { // SAVE todo!() } - pub fn set_anchor(&mut self) -> RunnerResult<()> { + pub fn set_anchor(&mut self) -> anyhow::Result<()> { // SETANCHOR todo!() } - pub fn set_as_button(&mut self) -> RunnerResult<()> { + pub fn set_as_button(&mut self) -> anyhow::Result<()> { // SETASBUTTON todo!() } - pub fn set_clipping(&mut self) -> RunnerResult<()> { + pub fn set_clipping(&mut self) -> anyhow::Result<()> { // SETCLIPPING todo!() } - pub fn set_opacity(&mut self) -> RunnerResult<()> { + pub fn set_opacity(&mut self) -> anyhow::Result<()> { // SETOPACITY todo!() } - pub fn set_position(&mut self, x: isize, y: isize) -> RunnerResult<()> { + pub fn set_position(&mut self, x: isize, y: isize) -> anyhow::Result<()> { // SETPOSITION self.position = (x, y); Ok(()) } - pub fn set_priority(&mut self) -> RunnerResult<()> { + pub fn set_priority(&mut self) -> anyhow::Result<()> { // SETPRIORITY todo!() } - pub fn set_reset_position(&mut self, x: isize, y: isize) -> RunnerResult<()> { + pub fn set_reset_position(&mut self, x: isize, y: isize) -> anyhow::Result<()> { // SETRESETPOSITION self.default_position = (x, y); Ok(()) } - pub fn set_scale_factor(&mut self) -> RunnerResult<()> { + pub fn set_scale_factor(&mut self) -> anyhow::Result<()> { // SETSCALEFACTOR todo!() } - pub fn show(&mut self) -> RunnerResult<()> { + pub fn show(&mut self) -> anyhow::Result<()> { // SHOW self.is_visible = true; Ok(()) @@ -845,21 +853,21 @@ impl ImageState { // custom - pub fn get_position(&self) -> RunnerResult<(isize, isize)> { + pub fn get_position(&self) -> anyhow::Result<(isize, isize)> { Ok(self.position) } - pub fn get_size(&self) -> RunnerResult<(usize, usize)> { + pub fn get_size(&self, context: RunnerContext) -> anyhow::Result<(usize, usize)> { let ImageFileData::Loaded(loaded_data) = &self.file_data else { - return Err(RunnerError::NoDataLoaded); + return Err(RunnerError::NoImageDataLoaded(context.current_object.name.clone()).into()); }; let size = loaded_data.image.0.size_px; Ok((size.0 as usize, size.1 as usize)) } - pub fn get_center_position(&self) -> RunnerResult<(isize, isize)> { + pub fn get_center_position(&self, context: RunnerContext) -> anyhow::Result<(isize, isize)> { let ImageFileData::Loaded(loaded_data) = &self.file_data else { - return Err(RunnerError::NoDataLoaded); + return Err(RunnerError::NoImageDataLoaded(context.current_object.name.clone()).into()); }; let position = self.position; let size = loaded_data.image.0.size_px; diff --git a/pixlib_parser/src/runner/classes/integer.rs b/pixlib_parser/src/runner/classes/integer.rs index be18e12..83e738b 100644 --- a/pixlib_parser/src/runner/classes/integer.rs +++ b/pixlib_parser/src/runner/classes/integer.rs @@ -98,7 +98,7 @@ impl IntegerVar { } } - pub fn get(&self) -> RunnerResult { + pub fn get(&self) -> anyhow::Result { self.state.borrow().get(RunnerContext::new_minimal( &self.parent.parent.runner, &self.parent, @@ -124,7 +124,7 @@ impl CnvType for IntegerVar { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { match name { CallableIdentifier::Method("ABS") => self .state @@ -232,7 +232,8 @@ impl CnvType for IntegerVar { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -322,7 +323,7 @@ impl CnvType for IntegerVar { } impl Initable for IntegerVar { - fn initialize(&self, context: RunnerContext) -> RunnerResult<()> { + fn initialize(&self, context: RunnerContext) -> anyhow::Result<()> { context .runner .internal_events @@ -339,89 +340,89 @@ impl Initable for IntegerVar { } impl IntegerVarState { - pub fn abs(&mut self, context: RunnerContext) -> RunnerResult { + pub fn abs(&mut self, context: RunnerContext) -> anyhow::Result { // ABS self.change_value(context, self.value.abs()); Ok(self.value) } - pub fn add(&mut self, context: RunnerContext, operand: i32) -> RunnerResult { + pub fn add(&mut self, context: RunnerContext, operand: i32) -> anyhow::Result { // ADD self.change_value(context, self.value + operand); Ok(self.value) } - pub fn and(&mut self, context: RunnerContext, operand: i32) -> RunnerResult { + pub fn and(&mut self, context: RunnerContext, operand: i32) -> anyhow::Result { // AND self.change_value(context, self.value & operand); Ok(self.value) } - pub fn clamp(&mut self, context: RunnerContext, min: i32, max: i32) -> RunnerResult { + pub fn clamp(&mut self, context: RunnerContext, min: i32, max: i32) -> anyhow::Result { // CLAMP self.change_value(context, self.value.clamp(min, max)); Ok(self.value) } - pub fn clear(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn clear(&mut self, context: RunnerContext) -> anyhow::Result<()> { // CLEAR self.change_value(context, 0); Ok(()) } - pub fn copy_file(&mut self, _context: RunnerContext) -> RunnerResult<()> { + pub fn copy_file(&mut self, _context: RunnerContext) -> anyhow::Result<()> { // COPYFILE todo!() } - pub fn dec(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn dec(&mut self, context: RunnerContext) -> anyhow::Result<()> { // DEC self.change_value(context, self.value - 1); Ok(()) } - pub fn div(&mut self, context: RunnerContext, divisor: i32) -> RunnerResult<()> { + pub fn div(&mut self, context: RunnerContext, divisor: i32) -> anyhow::Result<()> { // DIV self.change_value(context, self.value / divisor); Ok(()) } - pub fn get(&self, _context: RunnerContext) -> RunnerResult { + pub fn get(&self, _context: RunnerContext) -> anyhow::Result { // GET Ok(self.value) } - pub fn inc(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn inc(&mut self, context: RunnerContext) -> anyhow::Result<()> { // INC self.change_value(context, self.value + 1); Ok(()) } - pub fn modulus(&mut self, context: RunnerContext, divisor: i32) -> RunnerResult<()> { + pub fn modulus(&mut self, context: RunnerContext, divisor: i32) -> anyhow::Result<()> { // MOD self.change_value(context, self.value % divisor); Ok(()) } - pub fn mul(&mut self, context: RunnerContext, operand: i32) -> RunnerResult<()> { + pub fn mul(&mut self, context: RunnerContext, operand: i32) -> anyhow::Result<()> { // MUL self.change_value(context, self.value * operand); Ok(()) } - pub fn not(&mut self, context: RunnerContext) -> RunnerResult { + pub fn not(&mut self, context: RunnerContext) -> anyhow::Result { // NOT self.change_value(context, !self.value); Ok(self.value) } - pub fn or(&mut self, context: RunnerContext, operand: i32) -> RunnerResult { + pub fn or(&mut self, context: RunnerContext, operand: i32) -> anyhow::Result { // OR self.change_value(context, self.value | operand); Ok(self.value) } - pub fn power(&mut self, context: RunnerContext, exponent: i32) -> RunnerResult { + pub fn power(&mut self, context: RunnerContext, exponent: i32) -> anyhow::Result { // POWER self.change_value( context, @@ -434,42 +435,51 @@ impl IntegerVarState { Ok(self.value) } - pub fn random(&mut self, _context: RunnerContext) -> RunnerResult<()> { + pub fn random(&mut self, _context: RunnerContext) -> anyhow::Result<()> { // RANDOM todo!() } - pub fn reset_ini(&mut self, _context: RunnerContext) -> RunnerResult<()> { + pub fn reset_ini(&mut self, _context: RunnerContext) -> anyhow::Result<()> { // RESETINI eprintln!("Skipping INTEGER^RESETINI() call"); Ok(()) } - pub fn set(&mut self, context: RunnerContext, value: i32) -> RunnerResult<()> { + pub fn set(&mut self, context: RunnerContext, value: i32) -> anyhow::Result<()> { // SET self.change_value(context, value); Ok(()) } - pub fn set_default(&mut self, _context: RunnerContext, default_value: i32) -> RunnerResult<()> { + pub fn set_default( + &mut self, + _context: RunnerContext, + default_value: i32, + ) -> anyhow::Result<()> { // SETDEFAULT self.default_value = default_value; Ok(()) } - pub fn sub(&mut self, context: RunnerContext, subtrahend: i32) -> RunnerResult { + pub fn sub(&mut self, context: RunnerContext, subtrahend: i32) -> anyhow::Result { // SUB self.change_value(context, self.value - subtrahend); Ok(self.value) } - pub fn switch(&mut self, context: RunnerContext, first: i32, second: i32) -> RunnerResult<()> { + pub fn switch( + &mut self, + context: RunnerContext, + first: i32, + second: i32, + ) -> anyhow::Result<()> { // SWITCH self.change_value(context, if self.value == first { second } else { first }); Ok(()) } - pub fn xor(&mut self, context: RunnerContext, operand: i32) -> RunnerResult { + pub fn xor(&mut self, context: RunnerContext, operand: i32) -> anyhow::Result { // XOR self.change_value(context, self.value ^ operand); Ok(self.value) diff --git a/pixlib_parser/src/runner/classes/keyboard.rs b/pixlib_parser/src/runner/classes/keyboard.rs index ea2172c..0b4b3ec 100644 --- a/pixlib_parser/src/runner/classes/keyboard.rs +++ b/pixlib_parser/src/runner/classes/keyboard.rs @@ -103,7 +103,7 @@ impl CnvType for Keyboard { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { match name { CallableIdentifier::Method("DISABLE") => { self.state.borrow_mut().disable().map(|_| None) @@ -136,7 +136,8 @@ impl CnvType for Keyboard { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -191,7 +192,7 @@ impl CnvType for Keyboard { } impl Initable for Keyboard { - fn initialize(&self, context: RunnerContext) -> RunnerResult<()> { + fn initialize(&self, context: RunnerContext) -> anyhow::Result<()> { context .runner .internal_events @@ -208,37 +209,37 @@ impl Initable for Keyboard { } impl KeyboardState { - pub fn disable(&mut self) -> RunnerResult<()> { + pub fn disable(&mut self) -> anyhow::Result<()> { // DISABLE todo!() } - pub fn enable(&mut self) -> RunnerResult<()> { + pub fn enable(&mut self) -> anyhow::Result<()> { // ENABLE todo!() } - pub fn get_latest_key(&mut self) -> RunnerResult<()> { + pub fn get_latest_key(&mut self) -> anyhow::Result<()> { // GETLATESTKEY todo!() } - pub fn get_latest_keys(&mut self) -> RunnerResult<()> { + pub fn get_latest_keys(&mut self) -> anyhow::Result<()> { // GETLATESTKEYS todo!() } - pub fn is_enabled(&mut self) -> RunnerResult<()> { + pub fn is_enabled(&mut self) -> anyhow::Result<()> { // ISENABLED todo!() } - pub fn is_key_down(&mut self) -> RunnerResult<()> { + pub fn is_key_down(&mut self) -> anyhow::Result<()> { // ISKEYDOWN todo!() } - pub fn set_auto_repeat(&mut self) -> RunnerResult<()> { + pub fn set_auto_repeat(&mut self) -> anyhow::Result<()> { // SETAUTOREPEAT todo!() } diff --git a/pixlib_parser/src/runner/classes/mod.rs b/pixlib_parser/src/runner/classes/mod.rs index 1b4ddc3..5d03592 100644 --- a/pixlib_parser/src/runner/classes/mod.rs +++ b/pixlib_parser/src/runner/classes/mod.rs @@ -5,7 +5,7 @@ use lazy_static::lazy_static; use regex::Regex; use super::{content::CnvContent, parsers::TypeParsingError, CallableIdentifier, CnvObject}; -use crate::runner::{CnvValue, RunnerContext, RunnerResult}; +use crate::runner::{CnvValue, RunnerContext}; pub trait CnvType: std::fmt::Debug { fn get_type_id(&self) -> &'static str; @@ -17,7 +17,7 @@ pub trait CnvType: std::fmt::Debug { identifier: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult>; + ) -> anyhow::Result>; fn new_content( parent: Arc, @@ -50,7 +50,7 @@ impl CnvType for DummyCnvType { name: CallableIdentifier, _arguments: &[CnvValue], _context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { todo!("{:?} {:?}", self.get_type_id(), name) } diff --git a/pixlib_parser/src/runner/classes/mouse.rs b/pixlib_parser/src/runner/classes/mouse.rs index f6ca1d2..68c1251 100644 --- a/pixlib_parser/src/runner/classes/mouse.rs +++ b/pixlib_parser/src/runner/classes/mouse.rs @@ -126,7 +126,7 @@ impl Mouse { } } - pub fn handle_incoming_event(event: MouseEvent) -> RunnerResult<()> { + pub fn handle_incoming_event(event: MouseEvent) -> anyhow::Result<()> { let mut mouse_state = GLOBAL_MOUSE_STATE.write().unwrap(); match event { MouseEvent::MovedTo { x, y } => mouse_state.set_position(x, y), @@ -140,8 +140,8 @@ impl Mouse { } pub fn handle_outgoing_events( - mut handler: impl FnMut(InternalMouseEvent) -> RunnerResult<()>, - ) -> RunnerResult<()> { + mut handler: impl FnMut(InternalMouseEvent) -> anyhow::Result<()>, + ) -> anyhow::Result<()> { let mut mouse_state = GLOBAL_MOUSE_STATE.write().unwrap(); for event in mouse_state.events_out.drain(..) { handler(event)?; @@ -149,12 +149,12 @@ impl Mouse { Ok(()) } - pub fn get_position() -> RunnerResult<(isize, isize)> { + pub fn get_position() -> anyhow::Result<(isize, isize)> { let mouse_state = GLOBAL_MOUSE_STATE.read().unwrap(); Ok(mouse_state.position) } - pub fn is_left_button_down() -> RunnerResult { + pub fn is_left_button_down() -> anyhow::Result { let mouse_state = GLOBAL_MOUSE_STATE.read().unwrap(); Ok(mouse_state.is_left_button_down) } @@ -178,7 +178,7 @@ impl CnvType for Mouse { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { // println!("Calling method: {:?} of object: {:?}", name, self); match name { CallableIdentifier::Method("CLICK") => self @@ -289,7 +289,8 @@ impl CnvType for Mouse { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -365,7 +366,7 @@ impl CnvType for Mouse { } impl Initable for Mouse { - fn initialize(&self, context: RunnerContext) -> RunnerResult<()> { + fn initialize(&self, context: RunnerContext) -> anyhow::Result<()> { context .runner .internal_events @@ -382,84 +383,84 @@ impl Initable for Mouse { } impl MouseState { - pub fn click_left_button(&mut self) -> RunnerResult<()> { + pub fn click_left_button(&mut self) -> anyhow::Result<()> { // CLICK self.set_left_button_down(true) } - pub fn disable(&mut self) -> RunnerResult<()> { + pub fn disable(&mut self) -> anyhow::Result<()> { // DISABLE self.is_enabled = false; Ok(()) } - pub fn disable_event_handling(&mut self) -> RunnerResult<()> { + pub fn disable_event_handling(&mut self) -> anyhow::Result<()> { // DISABLESIGNAL self.are_events_enabled = false; Ok(()) } - pub fn enable(&mut self) -> RunnerResult<()> { + pub fn enable(&mut self) -> anyhow::Result<()> { // ENABLE self.is_enabled = true; Ok(()) } - pub fn enable_event_handling(&mut self) -> RunnerResult<()> { + pub fn enable_event_handling(&mut self) -> anyhow::Result<()> { // ENABLESIGNAL self.are_events_enabled = true; Ok(()) } - pub fn get_last_click_position_x(&self) -> RunnerResult { + pub fn get_last_click_position_x(&self) -> anyhow::Result { // GETLASTCLICKPOSX Ok(self.last_left_click_position.0) } - pub fn get_last_click_position_y(&self) -> RunnerResult { + pub fn get_last_click_position_y(&self) -> anyhow::Result { // GETLASTCLICKPOSY Ok(self.last_left_click_position.1) } - pub fn get_position_x(&self) -> RunnerResult { + pub fn get_position_x(&self) -> anyhow::Result { // GETPOSX Ok(self.position.0) } - pub fn get_position_y(&self) -> RunnerResult { + pub fn get_position_y(&self) -> anyhow::Result { // GETPOSY Ok(self.position.1) } - pub fn hide(&mut self) -> RunnerResult<()> { + pub fn hide(&mut self) -> anyhow::Result<()> { // HIDE self.is_visible = false; Ok(()) } - pub fn is_left_button_down(&self) -> RunnerResult { + pub fn is_left_button_down(&self) -> anyhow::Result { // ISLBUTTONDOWN Ok(self.is_left_button_down) } - pub fn is_right_button_down(&self) -> RunnerResult { + pub fn is_right_button_down(&self) -> anyhow::Result { // ISRBUTTONDOWN Ok(self.is_right_button_down) } - pub fn lock_cursor(&mut self) -> RunnerResult<()> { + pub fn lock_cursor(&mut self) -> anyhow::Result<()> { // LOCKACTIVECURSOR self.is_locked = true; self.events_out.push_back(InternalMouseEvent::CursorLocked); Ok(()) } - pub fn release_left_button(&mut self) -> RunnerResult<()> { + pub fn release_left_button(&mut self) -> anyhow::Result<()> { // MOUSERELEASE self.set_left_button_down(false) } - pub fn move_by(&mut self, x: isize, y: isize) -> RunnerResult<()> { + pub fn move_by(&mut self, x: isize, y: isize) -> anyhow::Result<()> { // MOVE self.position = (self.position.0 + x, self.position.1 + y); self.events_out @@ -467,22 +468,22 @@ impl MouseState { Ok(()) } - pub fn set(&mut self) -> RunnerResult<()> { + pub fn set(&mut self) -> anyhow::Result<()> { // SET todo!() } - pub fn set_active_rect(&mut self) -> RunnerResult<()> { + pub fn set_active_rect(&mut self) -> anyhow::Result<()> { // SETACTIVERECT todo!() } - pub fn set_clip_rect(&mut self) -> RunnerResult<()> { + pub fn set_clip_rect(&mut self) -> anyhow::Result<()> { // SETCLIPRECT todo!() } - pub fn set_position(&mut self, x: isize, y: isize) -> RunnerResult<()> { + pub fn set_position(&mut self, x: isize, y: isize) -> anyhow::Result<()> { // SETPOSITION let position_diff = (x - self.position.0, y - self.position.1); self.position = (x, y); @@ -495,7 +496,7 @@ impl MouseState { Ok(()) } - pub fn show(&mut self) -> RunnerResult<()> { + pub fn show(&mut self) -> anyhow::Result<()> { // SHOW self.is_visible = true; Ok(()) @@ -503,7 +504,7 @@ impl MouseState { // custom - pub fn set_left_button_down(&mut self, is_down: bool) -> RunnerResult<()> { + pub fn set_left_button_down(&mut self, is_down: bool) -> anyhow::Result<()> { if is_down != self.is_left_button_down { if is_down { self.events_out @@ -536,7 +537,7 @@ impl MouseState { Ok(()) } - pub fn set_middle_button_down(&mut self, is_down: bool) -> RunnerResult<()> { + pub fn set_middle_button_down(&mut self, is_down: bool) -> anyhow::Result<()> { if is_down != self.is_middle_button_down { if is_down { self.events_out @@ -556,7 +557,7 @@ impl MouseState { Ok(()) } - pub fn set_right_button_down(&mut self, is_down: bool) -> RunnerResult<()> { + pub fn set_right_button_down(&mut self, is_down: bool) -> anyhow::Result<()> { if is_down != self.is_right_button_down { if is_down { self.events_out diff --git a/pixlib_parser/src/runner/classes/multiarray.rs b/pixlib_parser/src/runner/classes/multiarray.rs index 9b5287a..ca3f7e9 100644 --- a/pixlib_parser/src/runner/classes/multiarray.rs +++ b/pixlib_parser/src/runner/classes/multiarray.rs @@ -71,7 +71,7 @@ impl CnvType for MultiArray { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { match name { CallableIdentifier::Method("COUNT") => self.state.borrow_mut().count().map(|_| None), CallableIdentifier::Method("LOAD") => self.state.borrow_mut().load().map(|_| None), @@ -96,7 +96,8 @@ impl CnvType for MultiArray { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -118,37 +119,37 @@ impl CnvType for MultiArray { } impl MultiArrayState { - pub fn count(&mut self) -> RunnerResult<()> { + pub fn count(&mut self) -> anyhow::Result<()> { // COUNT todo!() } - pub fn load(&mut self) -> RunnerResult<()> { + pub fn load(&mut self) -> anyhow::Result<()> { // LOAD todo!() } - pub fn get(&self) -> RunnerResult> { + pub fn get(&self) -> anyhow::Result> { // GET todo!() } - pub fn get_size(&self) -> RunnerResult { + pub fn get_size(&self) -> anyhow::Result { // GETSIZE todo!() } - pub fn safe_get(&self) -> RunnerResult> { + pub fn safe_get(&self) -> anyhow::Result> { // SAFEGET todo!() } - pub fn save(&mut self) -> RunnerResult<()> { + pub fn save(&mut self) -> anyhow::Result<()> { // SAVE todo!() } - pub fn set(&mut self) -> RunnerResult<()> { + pub fn set(&mut self) -> anyhow::Result<()> { // SET todo!() } diff --git a/pixlib_parser/src/runner/classes/music.rs b/pixlib_parser/src/runner/classes/music.rs index 141d41c..6fc0b64 100644 --- a/pixlib_parser/src/runner/classes/music.rs +++ b/pixlib_parser/src/runner/classes/music.rs @@ -71,7 +71,7 @@ impl CnvType for Music { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { match name { CallableIdentifier::Event(event_name) => { if let Some(code) = self @@ -85,7 +85,8 @@ impl CnvType for Music { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } diff --git a/pixlib_parser/src/runner/classes/rand.rs b/pixlib_parser/src/runner/classes/rand.rs index e5e2524..992b317 100644 --- a/pixlib_parser/src/runner/classes/rand.rs +++ b/pixlib_parser/src/runner/classes/rand.rs @@ -62,13 +62,14 @@ impl CnvType for Rand { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { match name { CallableIdentifier::Method("GET") => match arguments.len() { 0 => Err(RunnerError::TooFewArguments { expected_min: 1, actual: 0, - }), + } + .into()), 1 => self.state.borrow().get(arguments[0].to_int() as usize, 0), 2 => self.state.borrow().get( arguments[1].to_int() as usize, @@ -77,7 +78,8 @@ impl CnvType for Rand { arg_count => Err(RunnerError::TooManyArguments { expected_max: 2, actual: arg_count, - }), + } + .into()), } .map(|v| Some(CnvValue::Integer(v as i32))), CallableIdentifier::Method("GETPLENTY") => { @@ -95,7 +97,8 @@ impl CnvType for Rand { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -111,13 +114,13 @@ impl CnvType for Rand { } impl RandState { - pub fn get(&self, max_exclusive: usize, offset: isize) -> RunnerResult { + pub fn get(&self, max_exclusive: usize, offset: isize) -> anyhow::Result { // GET let mut rng = thread_rng(); Ok(rng.gen_range(0..max_exclusive) as isize + offset) } - pub fn get_plenty(&self) -> RunnerResult<()> { + pub fn get_plenty(&self) -> anyhow::Result<()> { // GETPLENTY todo!() } diff --git a/pixlib_parser/src/runner/classes/scene.rs b/pixlib_parser/src/runner/classes/scene.rs index a2dda87..e9984bf 100644 --- a/pixlib_parser/src/runner/classes/scene.rs +++ b/pixlib_parser/src/runner/classes/scene.rs @@ -159,14 +159,14 @@ impl Scene { !matches!(&self.state.borrow().music_data, SoundFileData::Empty) } - pub fn get_background_to_show(&self) -> RunnerResult<(ImageDefinition, ImageData)> { + pub fn get_background_to_show(&self) -> anyhow::Result<(ImageDefinition, ImageData)> { let mut state = self.state.borrow_mut(); if let ImageFileData::NotLoaded(filename) = &state.background_data { let context = RunnerContext::new_minimal(&self.parent.parent.runner, &self.parent); let path = ScenePath::new(self.path.as_ref().unwrap(), filename); state.load_background(context, &path)?; } else if let ImageFileData::Empty = &state.background_data { - return Err(RunnerError::MissingFilenameToLoad); + return Err(RunnerError::MissingFilenameToLoad.into()); } let ImageFileData::Loaded(loaded_background) = &state.background_data else { unreachable!(); @@ -175,7 +175,7 @@ impl Scene { Ok((image.0.clone(), image.1.clone())) } - pub fn get_music_volume_pan_freq(&self) -> RunnerResult<(f32, i32, usize)> { + pub fn get_music_volume_pan_freq(&self) -> anyhow::Result<(f32, i32, usize)> { Ok(self.state.borrow().use_and_drop(|state| { ( state.music_volume_permilles as f32 / 1000f32, @@ -185,7 +185,7 @@ impl Scene { })) } - pub fn handle_music_finished(&self) -> RunnerResult<()> { + pub fn handle_music_finished(&self) -> anyhow::Result<()> { let context = RunnerContext::new_minimal(&self.parent.parent.runner, &self.parent); if !self.state.borrow().use_and_drop(|s| s.is_music_playing) { return Ok(()); @@ -212,7 +212,7 @@ impl Scene { Ok(()) } - pub fn handle_scene_loaded(&self) -> RunnerResult<()> { + pub fn handle_scene_loaded(&self) -> anyhow::Result<()> { let context = RunnerContext::new_minimal(&self.parent.parent.runner, &self.parent); self.state .borrow_mut() @@ -257,7 +257,7 @@ impl CnvType for Scene { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { match name { CallableIdentifier::Method("CREATEOBJECT") => { self.state.borrow_mut().create_object().map(|_| None) @@ -363,7 +363,8 @@ impl CnvType for Scene { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -469,7 +470,7 @@ impl CnvType for Scene { } impl Initable for Scene { - fn initialize(&self, context: RunnerContext) -> RunnerResult<()> { + fn initialize(&self, context: RunnerContext) -> anyhow::Result<()> { let mut state = self.state.borrow_mut(); if let ImageFileData::NotLoaded(filename) = &state.background_data { let path = ScenePath::new(self.path.as_ref().unwrap(), filename); @@ -492,87 +493,87 @@ impl Initable for Scene { } impl SceneState { - pub fn create_object(&mut self) -> RunnerResult<()> { + pub fn create_object(&mut self) -> anyhow::Result<()> { // CREATEOBJECT todo!() } - pub fn get_dragged_name(&self) -> RunnerResult { + pub fn get_dragged_name(&self) -> anyhow::Result { // GETDRAGGEDNAME todo!() } - pub fn get_elements_no(&self) -> RunnerResult { + pub fn get_elements_no(&self) -> anyhow::Result { // GETELEMENTSNO todo!() } - pub fn get_max_hs_priority(&self) -> RunnerResult { + pub fn get_max_hs_priority(&self) -> anyhow::Result { // GETMAXHSPRIORITY todo!() } - pub fn get_min_hs_priority(&self) -> RunnerResult { + pub fn get_min_hs_priority(&self) -> anyhow::Result { // GETMINHSPRIORITY todo!() } - pub fn get_music_volume(&self) -> RunnerResult { + pub fn get_music_volume(&self) -> anyhow::Result { // GETMUSICVOLUME Ok(self.music_volume_permilles) } - pub fn get_objects(&self) -> RunnerResult<()> { + pub fn get_objects(&self) -> anyhow::Result<()> { // GETOBJECTS todo!() } - pub fn get_playing_animo(&self) -> RunnerResult<()> { + pub fn get_playing_animo(&self) -> anyhow::Result<()> { // GETPLAYINGANIMO todo!() } - pub fn get_playing_seq(&self) -> RunnerResult<()> { + pub fn get_playing_seq(&self) -> anyhow::Result<()> { // GETPLAYINGSEQ todo!() } - pub fn get_running_timer(&self) -> RunnerResult<()> { + pub fn get_running_timer(&self) -> anyhow::Result<()> { // GETRUNNINGTIMER todo!() } - pub fn is_paused(&self) -> RunnerResult { + pub fn is_paused(&self) -> anyhow::Result { // ISPAUSED todo!() } - pub fn pause(&mut self) -> RunnerResult<()> { + pub fn pause(&mut self) -> anyhow::Result<()> { // PAUSE todo!() } - pub fn remove(&mut self) -> RunnerResult<()> { + pub fn remove(&mut self) -> anyhow::Result<()> { // REMOVE todo!() } - pub fn remove_clones(&mut self) -> RunnerResult<()> { + pub fn remove_clones(&mut self) -> anyhow::Result<()> { // REMOVECLONES todo!() } - pub fn resume(&mut self) -> RunnerResult<()> { + pub fn resume(&mut self) -> anyhow::Result<()> { // RESUME todo!() } - pub fn resume_only(&mut self) -> RunnerResult<()> { + pub fn resume_only(&mut self) -> anyhow::Result<()> { // RESUMEONLY todo!() } - pub fn resume_seq_only(&mut self) -> RunnerResult<()> { + pub fn resume_seq_only(&mut self) -> anyhow::Result<()> { // RESUMESEQONLY todo!() } @@ -583,10 +584,10 @@ impl SceneState { object_name: String, method_name: String, arguments: Vec, - ) -> RunnerResult<()> { + ) -> anyhow::Result<()> { // RUN let Some(object) = context.runner.get_object(&object_name) else { - return Err(RunnerError::ObjectNotFound { name: object_name }); + return Err(RunnerError::ObjectNotFound { name: object_name }.into()); }; context .runner @@ -602,37 +603,37 @@ impl SceneState { Ok(()) } - pub fn run_clones(&mut self) -> RunnerResult<()> { + pub fn run_clones(&mut self) -> anyhow::Result<()> { // RUNCLONES todo!() } - pub fn set_max_hs_priority(&mut self) -> RunnerResult<()> { + pub fn set_max_hs_priority(&mut self) -> anyhow::Result<()> { // SETMAXHSPRIORITY todo!() } - pub fn set_min_hs_priority(&mut self) -> RunnerResult<()> { + pub fn set_min_hs_priority(&mut self) -> anyhow::Result<()> { // SETMINHSPRIORITY todo!() } - pub fn set_music_freq(&mut self) -> RunnerResult<()> { + pub fn set_music_freq(&mut self) -> anyhow::Result<()> { // SETMUSICFREQ todo!() } - pub fn set_music_pan(&mut self) -> RunnerResult<()> { + pub fn set_music_pan(&mut self) -> anyhow::Result<()> { // SETMUSICPAN todo!() } - pub fn set_music_volume(&mut self) -> RunnerResult<()> { + pub fn set_music_volume(&mut self) -> anyhow::Result<()> { // SETMUSICVOLUME todo!() } - pub fn start_music(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn start_music(&mut self, context: RunnerContext) -> anyhow::Result<()> { // STARTMUSIC if self.is_music_playing { return Ok(()); @@ -655,7 +656,7 @@ impl SceneState { Ok(()) } - pub fn stop_music(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn stop_music(&mut self, context: RunnerContext) -> anyhow::Result<()> { // STOPMUSIC if !self.is_music_playing { return Ok(()); @@ -678,7 +679,7 @@ impl SceneState { Ok(()) } - pub fn convert_to_time(&mut self) -> RunnerResult<()> { + pub fn convert_to_time(&mut self) -> anyhow::Result<()> { // TOTIME todo!() } @@ -689,7 +690,7 @@ impl SceneState { &mut self, context: RunnerContext, path: &ScenePath, - ) -> RunnerResult<()> { + ) -> anyhow::Result<()> { let script = context.current_object.parent.as_ref(); let filesystem = Arc::clone(&script.runner.filesystem); let data = filesystem @@ -718,7 +719,7 @@ impl SceneState { Ok(()) } - pub fn load_music(&mut self, context: RunnerContext, path: &ScenePath) -> RunnerResult<()> { + pub fn load_music(&mut self, context: RunnerContext, path: &ScenePath) -> anyhow::Result<()> { let script = context.current_object.parent.as_ref(); let filesystem = Arc::clone(&script.runner.filesystem); let data = filesystem @@ -739,7 +740,7 @@ impl SceneState { Ok(()) } - pub fn load_music_if_not_loaded(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn load_music_if_not_loaded(&mut self, context: RunnerContext) -> anyhow::Result<()> { if let SoundFileData::NotLoaded(filename) = &self.music_data { let path = context.current_object.parent.path.with_file_path(filename); self.load_music(context.clone(), &path) diff --git a/pixlib_parser/src/runner/classes/sequence.rs b/pixlib_parser/src/runner/classes/sequence.rs index 2be22b1..cd6aa44 100644 --- a/pixlib_parser/src/runner/classes/sequence.rs +++ b/pixlib_parser/src/runner/classes/sequence.rs @@ -110,7 +110,7 @@ impl CnvType for Sequence { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { // println!("Calling method: {:?} of object: {:?}", name, self); match name { CallableIdentifier::Method("GETEVENTNAME") => self @@ -153,7 +153,8 @@ impl CnvType for Sequence { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -202,7 +203,7 @@ impl CnvType for Sequence { } impl Initable for Sequence { - fn initialize(&self, context: RunnerContext) -> RunnerResult<()> { + fn initialize(&self, context: RunnerContext) -> anyhow::Result<()> { context .runner .internal_events @@ -219,62 +220,62 @@ impl Initable for Sequence { } impl SequenceState { - pub fn get_event_name(&self) -> RunnerResult { + pub fn get_event_name(&self) -> anyhow::Result { // GETEVENTNAME todo!() } - pub fn get_playing(&self) -> RunnerResult { + pub fn get_playing(&self) -> anyhow::Result { // GETPLAYING todo!() } - pub fn hide(&mut self) -> RunnerResult<()> { + pub fn hide(&mut self) -> anyhow::Result<()> { // HIDE todo!() } - pub fn is_playing(&self) -> RunnerResult { + pub fn is_playing(&self) -> anyhow::Result { // ISPLAYING todo!() } - pub fn pause(&mut self) -> RunnerResult<()> { + pub fn pause(&mut self) -> anyhow::Result<()> { // PAUSE todo!() } - pub fn play(&mut self) -> RunnerResult<()> { + pub fn play(&mut self) -> anyhow::Result<()> { // PLAY todo!() } - pub fn resume(&mut self) -> RunnerResult<()> { + pub fn resume(&mut self) -> anyhow::Result<()> { // RESUME todo!() } - pub fn set_freq(&mut self) -> RunnerResult<()> { + pub fn set_freq(&mut self) -> anyhow::Result<()> { // SETFREQ todo!() } - pub fn set_pan(&mut self) -> RunnerResult<()> { + pub fn set_pan(&mut self) -> anyhow::Result<()> { // SETPAN todo!() } - pub fn set_volume(&mut self) -> RunnerResult<()> { + pub fn set_volume(&mut self) -> anyhow::Result<()> { // SETVOLUME todo!() } - pub fn show(&mut self) -> RunnerResult<()> { + pub fn show(&mut self) -> anyhow::Result<()> { // SHOW todo!() } - pub fn stop(&mut self) -> RunnerResult<()> { + pub fn stop(&mut self) -> anyhow::Result<()> { // STOP todo!() } diff --git a/pixlib_parser/src/runner/classes/sound.rs b/pixlib_parser/src/runner/classes/sound.rs index 12f2e29..a47b4af 100644 --- a/pixlib_parser/src/runner/classes/sound.rs +++ b/pixlib_parser/src/runner/classes/sound.rs @@ -110,7 +110,7 @@ impl Sound { // custom - pub fn get_sound_to_play(&self) -> RunnerResult> { + pub fn get_sound_to_play(&self) -> anyhow::Result> { let state = self.state.borrow(); if !state.is_playing { return Ok(None); @@ -121,7 +121,7 @@ impl Sound { Ok(Some(loaded_data.sound.clone())) } - pub fn handle_finished(&self) -> RunnerResult<()> { + pub fn handle_finished(&self) -> anyhow::Result<()> { let context = RunnerContext::new_minimal(&self.parent.parent.runner, &self.parent); self.state.borrow_mut().use_and_drop_mut(|s| { s.is_playing = false; @@ -141,14 +141,14 @@ impl Sound { Ok(()) } - pub fn play(&self) -> RunnerResult<()> { + pub fn play(&self) -> anyhow::Result<()> { self.state.borrow_mut().play(RunnerContext::new_minimal( &self.parent.parent.runner, &self.parent, )) } - pub fn stop(&self) -> RunnerResult<()> { + pub fn stop(&self) -> anyhow::Result<()> { self.state.borrow_mut().stop(RunnerContext::new_minimal( &self.parent.parent.runner, &self.parent, @@ -174,7 +174,7 @@ impl CnvType for Sound { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { // println!("Calling method: {:?} of object: {:?}", name, self); match name { CallableIdentifier::Method("ISPLAYING") => self @@ -218,7 +218,8 @@ impl CnvType for Sound { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -285,10 +286,10 @@ impl CnvType for Sound { } impl Initable for Sound { - fn initialize(&self, context: RunnerContext) -> RunnerResult<()> { + fn initialize(&self, context: RunnerContext) -> anyhow::Result<()> { self.state .borrow_mut() - .use_and_drop_mut::>(|state| { + .use_and_drop_mut(|state| -> anyhow::Result<()> { if self.should_preload { if let SoundFileData::NotLoaded(filename) = &state.file_data { let filename = filename.clone(); @@ -313,12 +314,12 @@ impl Initable for Sound { } impl SoundState { - pub fn is_playing(&self) -> RunnerResult { + pub fn is_playing(&self) -> anyhow::Result { // ISPLAYING todo!() } - pub fn load(&mut self, context: RunnerContext, filename: &str) -> RunnerResult<()> { + pub fn load(&mut self, context: RunnerContext, filename: &str) -> anyhow::Result<()> { // LOAD let script = context.current_object.parent.as_ref(); let filesystem = Arc::clone(&script.runner.filesystem); @@ -357,7 +358,7 @@ impl SoundState { Ok(()) } - pub fn pause(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn pause(&mut self, context: RunnerContext) -> anyhow::Result<()> { // PAUSE self.is_paused = true; context @@ -385,14 +386,14 @@ impl SoundState { Ok(()) } - pub fn play(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn play(&mut self, context: RunnerContext) -> anyhow::Result<()> { // PLAY if let SoundFileData::NotLoaded(filename) = &self.file_data { let filename = filename.clone(); self.load(context.clone(), &filename)?; }; if !matches!(&self.file_data, SoundFileData::Loaded(_)) { - return Err(RunnerError::NoDataLoaded); + return Err(RunnerError::NoSoundDataLoaded(context.current_object.name.clone()).into()); }; self.is_playing = true; context @@ -420,7 +421,7 @@ impl SoundState { Ok(()) } - pub fn resume(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn resume(&mut self, context: RunnerContext) -> anyhow::Result<()> { // RESUME self.is_paused = false; context @@ -448,22 +449,22 @@ impl SoundState { Ok(()) } - pub fn set_freq(&mut self) -> RunnerResult<()> { + pub fn set_freq(&mut self) -> anyhow::Result<()> { // SETFREQ todo!() } - pub fn set_pan(&mut self) -> RunnerResult<()> { + pub fn set_pan(&mut self) -> anyhow::Result<()> { // SETPAN todo!() } - pub fn set_volume(&mut self) -> RunnerResult<()> { + pub fn set_volume(&mut self) -> anyhow::Result<()> { // SETVOLUME todo!() } - pub fn stop(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn stop(&mut self, context: RunnerContext) -> anyhow::Result<()> { // STOP self.is_playing = false; self.is_paused = false; diff --git a/pixlib_parser/src/runner/classes/string.rs b/pixlib_parser/src/runner/classes/string.rs index 3a8f04e..b6fa2db 100644 --- a/pixlib_parser/src/runner/classes/string.rs +++ b/pixlib_parser/src/runner/classes/string.rs @@ -98,7 +98,7 @@ impl StringVar { } } - pub fn get(&self) -> RunnerResult { + pub fn get(&self) -> anyhow::Result { self.state.borrow().get(None, None) } } @@ -121,7 +121,7 @@ impl CnvType for StringVar { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { // eprintln!( // "Calling method {:?} with arguments [{}]", // name, @@ -248,7 +248,8 @@ impl CnvType for StringVar { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -330,7 +331,7 @@ impl CnvType for StringVar { } impl Initable for StringVar { - fn initialize(&self, context: RunnerContext) -> RunnerResult<()> { + fn initialize(&self, context: RunnerContext) -> anyhow::Result<()> { context .runner .internal_events @@ -347,24 +348,29 @@ impl Initable for StringVar { } impl StringVarState { - pub fn add(&mut self, context: RunnerContext, suffix: &str) -> RunnerResult { + pub fn add(&mut self, context: RunnerContext, suffix: &str) -> anyhow::Result { // ADD self.change_value(context, self.value.clone() + suffix); Ok(self.value.clone()) } - pub fn clear(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn clear(&mut self, context: RunnerContext) -> anyhow::Result<()> { // CLEAR self.change_value(context, "".to_owned()); Ok(()) } - pub fn copy_file(&mut self, _context: RunnerContext) -> RunnerResult { + pub fn copy_file(&mut self, _context: RunnerContext) -> anyhow::Result { // COPYFILE todo!() } - pub fn cut(&mut self, context: RunnerContext, index: usize, length: usize) -> RunnerResult<()> { + pub fn cut( + &mut self, + context: RunnerContext, + index: usize, + length: usize, + ) -> anyhow::Result<()> { // CUT let value = if length > 0 { self.value[index..(index + length)].to_owned() @@ -376,7 +382,7 @@ impl StringVarState { Ok(()) } - pub fn find(&self, needle: &str, start_index: Option) -> RunnerResult> { + pub fn find(&self, needle: &str, start_index: Option) -> anyhow::Result> { // FIND Ok(self .value @@ -391,7 +397,7 @@ impl StringVarState { .map(|m| m.0)) } - pub fn get(&self, index: Option, length: Option) -> RunnerResult { + pub fn get(&self, index: Option, length: Option) -> anyhow::Result { // GET let index = index.unwrap_or_default(); let length = length.unwrap_or(self.value.len() - index); @@ -404,7 +410,7 @@ impl StringVarState { index: usize, value: &str, times: usize, - ) -> RunnerResult<()> { + ) -> anyhow::Result<()> { // INSERTAT if times == 0 || value.is_empty() { return Ok(()); @@ -416,7 +422,7 @@ impl StringVarState { todo!() } - pub fn is_upper_letter(&self, index: usize) -> RunnerResult { + pub fn is_upper_letter(&self, index: usize) -> anyhow::Result { // ISUPPERLETTER Ok(self .value @@ -427,25 +433,25 @@ impl StringVarState { .unwrap_or_default()) } - pub fn length(&self) -> RunnerResult { + pub fn length(&self) -> anyhow::Result { // LENGTH Ok(self.value.len()) } - pub fn lower(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn lower(&mut self, context: RunnerContext) -> anyhow::Result<()> { // LOWER self.change_value(context, self.value.to_ascii_lowercase()); Ok(()) } - pub fn not(&mut self, context: RunnerContext) -> RunnerResult { + pub fn not(&mut self, context: RunnerContext) -> anyhow::Result { // NOT self.value = String::from_utf8(self.value.bytes().rev().collect()).unwrap(); // doesn't emit onchanged self.change_value(context, self.value.clone()); Ok(self.value.clone()) } - pub fn random(&mut self, _context: RunnerContext) -> RunnerResult { + pub fn random(&mut self, _context: RunnerContext) -> anyhow::Result { // RANDOM todo!() } @@ -455,7 +461,7 @@ impl StringVarState { context: RunnerContext, search: &str, replace: &str, - ) -> RunnerResult<()> { + ) -> anyhow::Result<()> { // REPLACE std::mem::drop(self.value.replace(search, replace)); // doesn't emit onchanged self.change_value(context, self.value.clone()); // but emits onbrutalchanged even when not changed @@ -467,20 +473,20 @@ impl StringVarState { context: RunnerContext, index: usize, replace: &str, - ) -> RunnerResult<()> { + ) -> anyhow::Result<()> { // REPLACEAT std::mem::drop(self.value.replace(&self.value[index..].to_owned(), replace)); // doesn't emit onchanged self.change_value(context, self.value.clone()); // but emits onbrutalchanged even when not changed Ok(()) } - pub fn reset_ini(&mut self, _context: RunnerContext) -> RunnerResult<()> { + pub fn reset_ini(&mut self, _context: RunnerContext) -> anyhow::Result<()> { // RESETINI eprintln!("Skipping STRING^RESETINI() call"); Ok(()) } - pub fn set(&mut self, context: RunnerContext, value: &str) -> RunnerResult<()> { + pub fn set(&mut self, context: RunnerContext, value: &str) -> anyhow::Result<()> { // SET self.change_value(context, value.to_owned()); Ok(()) @@ -490,13 +496,18 @@ impl StringVarState { &mut self, _context: RunnerContext, default_value: &str, - ) -> RunnerResult<()> { + ) -> anyhow::Result<()> { // SETDEFAULT self.default_value = default_value.to_owned(); Ok(()) } - pub fn sub(&mut self, context: RunnerContext, index: usize, length: usize) -> RunnerResult<()> { + pub fn sub( + &mut self, + context: RunnerContext, + index: usize, + length: usize, + ) -> anyhow::Result<()> { // SUB self.value.drain(index..(index + length)); // doesn't emit onchanged self.change_value(context, self.value.clone()); // but emits onbrutalchanged even when not changed @@ -508,7 +519,7 @@ impl StringVarState { context: RunnerContext, first: &str, second: &str, - ) -> RunnerResult<()> { + ) -> anyhow::Result<()> { // SWITCH self.change_value( context, @@ -521,7 +532,7 @@ impl StringVarState { Ok(()) } - pub fn upper(&mut self, context: RunnerContext) -> RunnerResult<()> { + pub fn upper(&mut self, context: RunnerContext) -> anyhow::Result<()> { // UPPER self.change_value(context, self.value.to_ascii_uppercase()); Ok(()) diff --git a/pixlib_parser/src/runner/classes/struct.rs b/pixlib_parser/src/runner/classes/struct.rs index 26dea41..89a5eae 100644 --- a/pixlib_parser/src/runner/classes/struct.rs +++ b/pixlib_parser/src/runner/classes/struct.rs @@ -89,7 +89,7 @@ impl CnvType for Struct { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { match name { CallableIdentifier::Method("GETFIELD") => self .state @@ -114,7 +114,8 @@ impl CnvType for Struct { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -161,7 +162,7 @@ impl CnvType for Struct { } impl Initable for Struct { - fn initialize(&self, context: RunnerContext) -> RunnerResult<()> { + fn initialize(&self, context: RunnerContext) -> anyhow::Result<()> { context .runner .internal_events @@ -178,17 +179,17 @@ impl Initable for Struct { } impl StructState { - pub fn get_field(&self, _name: &str) -> RunnerResult { + pub fn get_field(&self, _name: &str) -> anyhow::Result { // GETFIELD todo!() } - pub fn set(&mut self) -> RunnerResult<()> { + pub fn set(&mut self) -> anyhow::Result<()> { // SET todo!() } - pub fn set_field(&mut self, _name: &str, _value: CnvValue) -> RunnerResult<()> { + pub fn set_field(&mut self, _name: &str, _value: CnvValue) -> anyhow::Result<()> { // SETFIELD todo!() } diff --git a/pixlib_parser/src/runner/classes/system.rs b/pixlib_parser/src/runner/classes/system.rs index 73e16d6..2f4b09d 100644 --- a/pixlib_parser/src/runner/classes/system.rs +++ b/pixlib_parser/src/runner/classes/system.rs @@ -68,7 +68,7 @@ impl CnvType for System { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { match name { CallableIdentifier::Method("COPYFILE") => { self.state.borrow_mut().copy_file().map(|_| None) @@ -196,7 +196,8 @@ impl CnvType for System { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -213,132 +214,132 @@ impl CnvType for System { } impl SystemState { - pub fn copy_file(&mut self) -> RunnerResult<()> { + pub fn copy_file(&mut self) -> anyhow::Result<()> { // COPYFILE todo!() } - pub fn create_dir(&mut self) -> RunnerResult<()> { + pub fn create_dir(&mut self) -> anyhow::Result<()> { // CREATEDIR todo!() } - pub fn delay(&mut self) -> RunnerResult<()> { + pub fn delay(&mut self) -> anyhow::Result<()> { // DELAY todo!() } - pub fn get_cmd_line_parameter(&self) -> RunnerResult { + pub fn get_cmd_line_parameter(&self) -> anyhow::Result { // GETCMDLINEPARAMETER todo!() } - pub fn get_command_line(&self) -> RunnerResult { + pub fn get_command_line(&self) -> anyhow::Result { // GETCOMMANDLINE todo!() } - pub fn get_date(&self) -> RunnerResult { + pub fn get_date(&self) -> anyhow::Result { // GETDATE Ok(Local::now().format("%y%m%d").to_string()) } - pub fn get_date_string(&self) -> RunnerResult { + pub fn get_date_string(&self) -> anyhow::Result { // GETDATESTRING todo!() } - pub fn get_day(&self) -> RunnerResult { + pub fn get_day(&self) -> anyhow::Result { // GETDAY todo!() } - pub fn get_day_of_week(&self) -> RunnerResult { + pub fn get_day_of_week(&self) -> anyhow::Result { // GETDAYOFWEEK todo!() } - pub fn get_day_of_week_string(&self) -> RunnerResult { + pub fn get_day_of_week_string(&self) -> anyhow::Result { // GETDAYOFWEEKSTRING todo!() } - pub fn get_folder_location(&self) -> RunnerResult { + pub fn get_folder_location(&self) -> anyhow::Result { // GETFOLDERLOCATION todo!() } - pub fn get_hour(&self) -> RunnerResult { + pub fn get_hour(&self) -> anyhow::Result { // GETHOUR todo!() } - pub fn get_mhz(&self) -> RunnerResult { + pub fn get_mhz(&self) -> anyhow::Result { // GETMHZ todo!() } - pub fn get_minutes(&self) -> RunnerResult { + pub fn get_minutes(&self) -> anyhow::Result { // GETMINUTES todo!() } - pub fn get_month(&self) -> RunnerResult { + pub fn get_month(&self) -> anyhow::Result { // GETMONTH todo!() } - pub fn get_month_string(&self) -> RunnerResult { + pub fn get_month_string(&self) -> anyhow::Result { // GETMONTHSTRING todo!() } - pub fn get_seconds(&self) -> RunnerResult { + pub fn get_seconds(&self) -> anyhow::Result { // GETSECONDS todo!() } - pub fn get_system_time(&self) -> RunnerResult { + pub fn get_system_time(&self) -> anyhow::Result { // GETSYSTEMTIME todo!() } - pub fn get_time_string(&self) -> RunnerResult { + pub fn get_time_string(&self) -> anyhow::Result { // GETTIMESTRING todo!() } - pub fn get_user_name(&self) -> RunnerResult { + pub fn get_user_name(&self) -> anyhow::Result { // GETUSERNAME todo!() } - pub fn get_year(&self) -> RunnerResult { + pub fn get_year(&self) -> anyhow::Result { // GETYEAR todo!() } - pub fn install(&mut self) -> RunnerResult<()> { + pub fn install(&mut self) -> anyhow::Result<()> { // INSTALL todo!() } - pub fn is_cmd_line_parameter(&self) -> RunnerResult { + pub fn is_cmd_line_parameter(&self) -> anyhow::Result { // ISCMDLINEPARAMETER todo!() } - pub fn is_file_exist(&self) -> RunnerResult { + pub fn is_file_exist(&self) -> anyhow::Result { // ISFILEEXIST todo!() } - pub fn minimize(&mut self) -> RunnerResult<()> { + pub fn minimize(&mut self) -> anyhow::Result<()> { // MINIMIZE todo!() } - pub fn uninstall(&mut self) -> RunnerResult<()> { + pub fn uninstall(&mut self) -> anyhow::Result<()> { // UNINSTALL todo!() } diff --git a/pixlib_parser/src/runner/classes/text.rs b/pixlib_parser/src/runner/classes/text.rs index d764ff1..ccf9bcf 100644 --- a/pixlib_parser/src/runner/classes/text.rs +++ b/pixlib_parser/src/runner/classes/text.rs @@ -131,7 +131,7 @@ impl CnvType for Text { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { match name { CallableIdentifier::Method("CLEARCLIPPING") => { self.state.borrow_mut().clear_clipping().map(|_| None) @@ -247,7 +247,8 @@ impl CnvType for Text { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -352,7 +353,7 @@ impl CnvType for Text { } impl Initable for Text { - fn initialize(&self, context: RunnerContext) -> RunnerResult<()> { + fn initialize(&self, context: RunnerContext) -> anyhow::Result<()> { context .runner .internal_events @@ -369,152 +370,152 @@ impl Initable for Text { } impl TextState { - pub fn clear_clipping(&mut self) -> RunnerResult<()> { + pub fn clear_clipping(&mut self) -> anyhow::Result<()> { // CLEARCLIPPING todo!() } - pub fn draw_onto(&mut self) -> RunnerResult<()> { + pub fn draw_onto(&mut self) -> anyhow::Result<()> { // DRAWONTO todo!() } - pub fn get_height(&self) -> RunnerResult { + pub fn get_height(&self) -> anyhow::Result { // GETHEIGHT todo!() } - pub fn get_num_words(&self) -> RunnerResult { + pub fn get_num_words(&self) -> anyhow::Result { // GETNUMWORDS todo!() } - pub fn get_position_x(&self) -> RunnerResult { + pub fn get_position_x(&self) -> anyhow::Result { // GETPOSITIONX todo!() } - pub fn get_position_y(&self) -> RunnerResult { + pub fn get_position_y(&self) -> anyhow::Result { // GETPOSITIONY todo!() } - pub fn get_width(&self) -> RunnerResult { + pub fn get_width(&self) -> anyhow::Result { // GETWIDTH todo!() } - pub fn get_word_at(&self) -> RunnerResult { + pub fn get_word_at(&self) -> anyhow::Result { // GETWORDAT todo!() } - pub fn get_word_at_xy(&self) -> RunnerResult { + pub fn get_word_at_xy(&self) -> anyhow::Result { // GETWORDATXY todo!() } - pub fn get_word_pos_x(&self) -> RunnerResult { + pub fn get_word_pos_x(&self) -> anyhow::Result { // GETWORDPOSX todo!() } - pub fn get_word_pos_y(&self) -> RunnerResult { + pub fn get_word_pos_y(&self) -> anyhow::Result { // GETWORDPOSY todo!() } - pub fn get_word_width(&self) -> RunnerResult { + pub fn get_word_width(&self) -> anyhow::Result { // GETWORDWIDTH todo!() } - pub fn hide(&mut self) -> RunnerResult<()> { + pub fn hide(&mut self) -> anyhow::Result<()> { // HIDE todo!() } - pub fn invalidate(&mut self) -> RunnerResult<()> { + pub fn invalidate(&mut self) -> anyhow::Result<()> { // INVALIDATE todo!() } - pub fn is_near(&self) -> RunnerResult { + pub fn is_near(&self) -> anyhow::Result { // ISNEAR todo!() } - pub fn load(&mut self) -> RunnerResult<()> { + pub fn load(&mut self) -> anyhow::Result<()> { // LOAD todo!() } - pub fn move_by(&mut self) -> RunnerResult<()> { + pub fn move_by(&mut self) -> anyhow::Result<()> { // MOVE todo!() } - pub fn search(&mut self) -> RunnerResult<()> { + pub fn search(&mut self) -> anyhow::Result<()> { // SEARCH todo!() } - pub fn set_clipping(&mut self) -> RunnerResult<()> { + pub fn set_clipping(&mut self) -> anyhow::Result<()> { // SETCLIPPING todo!() } - pub fn set_color(&mut self) -> RunnerResult<()> { + pub fn set_color(&mut self) -> anyhow::Result<()> { // SETCOLOR todo!() } - pub fn set_font(&mut self) -> RunnerResult<()> { + pub fn set_font(&mut self) -> anyhow::Result<()> { // SETFONT todo!() } - pub fn set_justify(&mut self) -> RunnerResult<()> { + pub fn set_justify(&mut self) -> anyhow::Result<()> { // SETJUSTIFY todo!() } - pub fn set_opacity(&mut self) -> RunnerResult<()> { + pub fn set_opacity(&mut self) -> anyhow::Result<()> { // SETOPACITY todo!() } - pub fn set_position(&mut self) -> RunnerResult<()> { + pub fn set_position(&mut self) -> anyhow::Result<()> { // SETPOSITION todo!() } - pub fn set_priority(&mut self) -> RunnerResult<()> { + pub fn set_priority(&mut self) -> anyhow::Result<()> { // SETPRIORITY todo!() } - pub fn set_rect(&mut self) -> RunnerResult<()> { + pub fn set_rect(&mut self) -> anyhow::Result<()> { // SETRECT todo!() } - pub fn set_text(&mut self) -> RunnerResult<()> { + pub fn set_text(&mut self) -> anyhow::Result<()> { // SETTEXT todo!() } - pub fn set_text_double(&mut self) -> RunnerResult<()> { + pub fn set_text_double(&mut self) -> anyhow::Result<()> { // SETTEXTDOUBLE todo!() } - pub fn set_word_color(&mut self) -> RunnerResult<()> { + pub fn set_word_color(&mut self) -> anyhow::Result<()> { // SETWORDCOLOR todo!() } - pub fn show(&mut self) -> RunnerResult<()> { + pub fn show(&mut self) -> anyhow::Result<()> { // SHOW todo!() } diff --git a/pixlib_parser/src/runner/classes/timer.rs b/pixlib_parser/src/runner/classes/timer.rs index b84421b..8ceb649 100644 --- a/pixlib_parser/src/runner/classes/timer.rs +++ b/pixlib_parser/src/runner/classes/timer.rs @@ -94,7 +94,7 @@ impl Timer { // custom - pub fn step(&self, seconds: f64) -> RunnerResult<()> { + pub fn step(&self, seconds: f64) -> anyhow::Result<()> { let context = RunnerContext::new_minimal(&self.parent.parent.runner, &self.parent); self.state.borrow_mut().step(context, seconds * 1000f64) } @@ -118,7 +118,7 @@ impl CnvType for Timer { name: CallableIdentifier, arguments: &[CnvValue], context: RunnerContext, - ) -> RunnerResult> { + ) -> anyhow::Result> { // println!("Calling method: {:?} of object: {:?}", name, self); match name { CallableIdentifier::Method("DISABLE") => { @@ -155,7 +155,8 @@ impl CnvType for Timer { ident => Err(RunnerError::InvalidCallable { object_name: self.parent.name.clone(), callable: ident.to_owned(), - }), + } + .into()), } } @@ -217,7 +218,7 @@ impl CnvType for Timer { } impl Initable for Timer { - fn initialize(&self, context: RunnerContext) -> RunnerResult<()> { + fn initialize(&self, context: RunnerContext) -> anyhow::Result<()> { context .runner .internal_events @@ -234,7 +235,7 @@ impl Initable for Timer { } impl TimerState { - pub fn disable(&mut self) -> RunnerResult<()> { + pub fn disable(&mut self) -> anyhow::Result<()> { // DISABLE self.is_enabled = false; self.current_ms = 0.0; @@ -242,44 +243,44 @@ impl TimerState { Ok(()) } - pub fn enable(&mut self) -> RunnerResult<()> { + pub fn enable(&mut self) -> anyhow::Result<()> { // ENABLE self.current_ms = self.interval_ms as f64; self.is_enabled = true; Ok(()) } - pub fn get_ticks(&self) -> RunnerResult { + pub fn get_ticks(&self) -> anyhow::Result { // GETTICKS Ok(self.current_ticks) } - pub fn pause(&mut self) -> RunnerResult<()> { + pub fn pause(&mut self) -> anyhow::Result<()> { // PAUSE self.is_paused = true; Ok(()) } - pub fn reset(&mut self) -> RunnerResult<()> { + pub fn reset(&mut self) -> anyhow::Result<()> { // RESET self.current_ms = self.interval_ms as f64; self.current_ticks = 0; Ok(()) } - pub fn resume(&mut self) -> RunnerResult<()> { + pub fn resume(&mut self) -> anyhow::Result<()> { // RESUME self.is_paused = false; Ok(()) } - pub fn set(&mut self, current_ms: f64) -> RunnerResult<()> { + pub fn set(&mut self, current_ms: f64) -> anyhow::Result<()> { // SET self.current_ms = current_ms; Ok(()) } - pub fn set_elapse(&mut self, interval_ms: usize) -> RunnerResult<()> { + pub fn set_elapse(&mut self, interval_ms: usize) -> anyhow::Result<()> { // SETELAPSE self.interval_ms = interval_ms; Ok(()) @@ -287,7 +288,7 @@ impl TimerState { // custom - pub fn step(&mut self, context: RunnerContext, duration_ms: f64) -> RunnerResult<()> { + pub fn step(&mut self, context: RunnerContext, duration_ms: f64) -> anyhow::Result<()> { // eprintln!("Stepping timer {} by {} ms", timer.parent.name, duration_ms); let CnvContent::Timer(timer) = &context.current_object.content else { panic!(); diff --git a/pixlib_parser/src/runner/common.rs b/pixlib_parser/src/runner/common.rs index 199a7f3..86cd0f3 100644 --- a/pixlib_parser/src/runner/common.rs +++ b/pixlib_parser/src/runner/common.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::{fmt::Display, sync::Arc}; use pixlib_formats::file_formats::ann::LoopingSettings; @@ -32,6 +32,16 @@ impl<'a> From<&'a CallableIdentifierOwned> for CallableIdentifier<'a> { } } +impl Display for CallableIdentifierOwned { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str("CallableIdentifierOwned::")?; + match self { + CallableIdentifierOwned::Method(name) => f.write_fmt(format_args!("::Method({name})")), + CallableIdentifierOwned::Event(name) => f.write_fmt(format_args!("::Event({name})")), + } + } +} + #[derive(Debug, Clone, Default)] pub enum SoundFileData { #[default] diff --git a/pixlib_parser/src/runner/containers/object_container.rs b/pixlib_parser/src/runner/containers/object_container.rs index 39e9e04..f3a0147 100644 --- a/pixlib_parser/src/runner/containers/object_container.rs +++ b/pixlib_parser/src/runner/containers/object_container.rs @@ -1,6 +1,6 @@ use std::{collections::HashMap, sync::Arc}; -use super::super::{CnvObject, RunnerError, RunnerResult}; +use super::super::{CnvObject, RunnerError}; #[derive(Debug, Clone, Default)] pub struct ObjectContainer { @@ -34,16 +34,17 @@ impl ObjectContainer { self.vec.len() } - pub fn remove_object(&mut self, name: &str) -> RunnerResult<()> { + pub fn remove_object(&mut self, name: &str) -> anyhow::Result<()> { let Some(index) = self.vec.iter().position(|s| *s.name == *name) else { return Err(RunnerError::ObjectNotFound { name: name.to_owned(), - }); + } + .into()); }; self.remove_object_at(index) } - pub fn remove_object_at(&mut self, index: usize) -> RunnerResult<()> { + pub fn remove_object_at(&mut self, index: usize) -> anyhow::Result<()> { let removed_object = self.vec.remove(index); self.map.remove(&removed_object.name); Ok(()) @@ -54,7 +55,7 @@ impl ObjectContainer { self.map.clear(); } - pub fn push_object(&mut self, object: Arc) -> RunnerResult<()> { + pub fn push_object(&mut self, object: Arc) -> anyhow::Result<()> { self.map.insert(object.name.clone(), object.clone()); self.vec.push(object); Ok(()) @@ -63,7 +64,7 @@ impl ObjectContainer { pub fn push_objects>>( &mut self, objects: I, - ) -> RunnerResult<()> { + ) -> anyhow::Result<()> { for object in objects { self.map.insert(object.name.clone(), object.clone()); self.vec.push(object); diff --git a/pixlib_parser/src/runner/containers/script_container.rs b/pixlib_parser/src/runner/containers/script_container.rs index 50b6f9b..e203005 100644 --- a/pixlib_parser/src/runner/containers/script_container.rs +++ b/pixlib_parser/src/runner/containers/script_container.rs @@ -3,7 +3,7 @@ use std::{ sync::Arc, }; -use super::super::{path::ScenePath, CnvScript, RunnerError, RunnerResult, ScriptSource}; +use super::super::{path::ScenePath, CnvScript, RunnerError, ScriptSource}; #[derive(Debug, Clone, Default)] pub struct ScriptContainer { @@ -47,16 +47,17 @@ impl ScriptContainer { self.vec.len() } - pub fn remove_script(&mut self, path: &ScenePath) -> RunnerResult<()> { + pub fn remove_script(&mut self, path: &ScenePath) -> anyhow::Result<()> { let Some(index) = self.vec.iter().position(|s| s.path == *path) else { return Err(RunnerError::ScriptNotFound { path: path.to_str(), - }); + } + .into()); }; self.remove_script_at(index) } - pub fn remove_script_at(&mut self, index: usize) -> RunnerResult<()> { + pub fn remove_script_at(&mut self, index: usize) -> anyhow::Result<()> { let mut to_remove = VecDeque::new(); to_remove.push_back(self.vec.remove(index)); while let Some(script) = to_remove.pop_front() { @@ -93,7 +94,7 @@ impl ScriptContainer { Ok(()) } - pub fn remove_scene_script(&mut self) -> RunnerResult> { + pub fn remove_scene_script(&mut self) -> anyhow::Result> { let Some(ref current_scene) = self.scene_script else { return Ok(None); }; @@ -103,7 +104,7 @@ impl ScriptContainer { self.remove_script_at(index).map(|_| Some(())) } - pub fn remove_episode_script(&mut self) -> RunnerResult> { + pub fn remove_episode_script(&mut self) -> anyhow::Result> { let Some(ref current_episode) = self.episode_script else { return Ok(None); }; @@ -113,7 +114,7 @@ impl ScriptContainer { self.remove_script_at(index).map(|_| Some(())) } - pub fn remove_application_script(&mut self) -> RunnerResult> { + pub fn remove_application_script(&mut self) -> anyhow::Result> { let Some(ref current_application) = self.application_script else { return Ok(None); }; @@ -135,21 +136,21 @@ impl ScriptContainer { self.application_script = None; } - pub fn push_script(&mut self, script: Arc) -> RunnerResult<()> { + pub fn push_script(&mut self, script: Arc) -> anyhow::Result<()> { match script.source_kind { ScriptSource::Root if !self.vec.is_empty() => { - return Err(RunnerError::RootScriptAlreadyLoaded) + return Err(RunnerError::RootScriptAlreadyLoaded.into()) } ScriptSource::Application if self.application_script.is_some() => { - return Err(RunnerError::ApplicationScriptAlreadyLoaded) + return Err(RunnerError::ApplicationScriptAlreadyLoaded.into()) } ScriptSource::Application => self.application_script = Some(Arc::clone(&script)), ScriptSource::Episode if self.episode_script.is_some() => { - return Err(RunnerError::EpisodeScriptAlreadyLoaded) + return Err(RunnerError::EpisodeScriptAlreadyLoaded.into()) } ScriptSource::Episode => self.episode_script = Some(Arc::clone(&script)), ScriptSource::Scene if self.scene_script.is_some() => { - return Err(RunnerError::SceneScriptAlreadyLoaded) + return Err(RunnerError::SceneScriptAlreadyLoaded.into()) } ScriptSource::Scene => self.scene_script = Some(Arc::clone(&script)), _ => {} diff --git a/pixlib_parser/src/runner/initable.rs b/pixlib_parser/src/runner/initable.rs index acd18e0..bf7d86a 100644 --- a/pixlib_parser/src/runner/initable.rs +++ b/pixlib_parser/src/runner/initable.rs @@ -1,9 +1,9 @@ -use crate::runner::{RunnerContext, RunnerResult}; +use crate::runner::RunnerContext; use super::content::CnvContent; pub trait Initable { - fn initialize(&self, context: RunnerContext) -> RunnerResult<()>; + fn initialize(&self, context: RunnerContext) -> anyhow::Result<()>; } impl<'a> From<&'a CnvContent> for Option<&'a dyn Initable> { diff --git a/pixlib_parser/src/runner/mod.rs b/pixlib_parser/src/runner/mod.rs index 4425d8f..6cb4256 100644 --- a/pixlib_parser/src/runner/mod.rs +++ b/pixlib_parser/src/runner/mod.rs @@ -73,76 +73,78 @@ where } } -#[derive(Debug)] +#[derive(Debug, Error)] pub enum RunnerError { - TooManyArguments { - expected_max: usize, - actual: usize, - }, - TooFewArguments { - expected_min: usize, - actual: usize, - }, - ExpectedUnsignedInteger { - actual: i32, - }, - MissingLeftOperand { - object_name: String, - }, - MissingRightOperand { - object_name: String, - }, - MissingOperator { - object_name: String, - }, - ObjectNotFound { - name: String, - }, + #[error("Too many arguments (expected at most {expected_max}, got {actual})")] + TooManyArguments { expected_max: usize, actual: usize }, + #[error("Too few arguments (expected at least {expected_min}, got {actual})")] + TooFewArguments { expected_min: usize, actual: usize }, + #[error("Integer {actual} cannot be cast to unsigned")] + ExpectedUnsignedInteger { actual: i32 }, + #[error("Left operand missing for object {object_name}")] + MissingLeftOperand { object_name: String }, + #[error("Right operand missing for object {object_name}")] + MissingRightOperand { object_name: String }, + #[error("Operator missing for object {object_name}")] + MissingOperator { object_name: String }, + #[error("Object {name} not found")] + ObjectNotFound { name: String }, + #[error("Expected graphics object")] ExpectedGraphicsObject, + #[error("Expected sound object")] ExpectedSoundObject, + #[error("Expected condition object")] ExpectedConditionObject, - NoDataLoaded, + #[error("No animation data loaded for object {0}")] + NoAnimationDataLoaded(String), + #[error("No sound data loaded for object {0}")] + NoSoundDataLoaded(String), + #[error("No image data loaded for object {0}")] + NoImageDataLoaded(String), + #[error("Sequence {sequence_name} not found in object {object_name}")] SequenceNameNotFound { object_name: String, sequence_name: String, }, - SequenceIndexNotFound { - object_name: String, - index: usize, - }, + #[error("Sequence #{index} not found in object {object_name}")] + SequenceIndexNotFound { object_name: String, index: usize }, + #[error("Frame #{index} not found in sequence {sequence_name} of object {object_name}")] FrameIndexNotFound { object_name: String, sequence_name: String, index: usize, }, - SpriteIndexNotFound { - object_name: String, - index: usize, - }, + #[error("Sprite #{index} not found in object {object_name}")] + SpriteIndexNotFound { object_name: String, index: usize }, + #[error("Method or event handler missing on object {object_name} for callable {callable}")] InvalidCallable { object_name: String, callable: CallableIdentifierOwned, }, + #[error("Missing filename to load")] MissingFilenameToLoad, - ScriptNotFound { - path: String, - }, + #[error("Script {path} not found")] + ScriptNotFound { path: String }, + #[error("Root script is loaded already")] RootScriptAlreadyLoaded, + #[error("Application script is loaded already")] ApplicationScriptAlreadyLoaded, + #[error("Episode script is loaded already")] EpisodeScriptAlreadyLoaded, + #[error("Scene script is loaded already")] SceneScriptAlreadyLoaded, - OrphanedContent, + #[error("Parser error: {0}")] ParserError(ParserFatal), + #[error("SEQ parser error: {0}")] SeqParserError(SeqParserError), - IoError { - source: std::io::Error, - }, - ObjectBuilderError { - source: ObjectBuilderError, - }, + #[error("IO error: {source}")] + IoError { source: std::io::Error }, + #[error("Object builder error: {source}")] + ObjectBuilderError { source: ObjectBuilderError }, + #[error("Other error")] Other, } @@ -351,7 +353,7 @@ impl CnvRunner { game_paths: Arc, window_resolution: (usize, usize), issue_manager: IssueManager, - ) -> RunnerResult> { + ) -> anyhow::Result> { let runner = Arc::new(Self { scripts: RefCell::new(ScriptContainer::default()), filesystem, @@ -381,7 +383,7 @@ impl CnvRunner { runner .global_objects .borrow_mut() - .use_and_drop_mut::>(|objects| { + .use_and_drop_mut::>(|objects| { let mut range = 0usize..; objects .push_object({ @@ -432,7 +434,7 @@ impl CnvRunner { Ok(runner) } - pub fn step(self: &Arc) -> RunnerResult<()> { + pub fn step(self: &Arc) -> anyhow::Result<()> { let mut to_init = Vec::new(); self.find_objects(|o| !*o.initialized.borrow(), &mut to_init); for object in to_init { @@ -441,7 +443,7 @@ impl CnvRunner { self.events_in .timer .borrow_mut() - .use_and_drop_mut::>(|events| { + .use_and_drop_mut::>(|events| { while let Some(evt) = events.pop_front() { match evt { TimerEvent::Elapsed { seconds } => { @@ -475,7 +477,7 @@ impl CnvRunner { self.events_in .mouse .borrow_mut() - .use_and_drop_mut::>(|events| { + .use_and_drop_mut::>(|events| { while let Some(evt) = events.pop_front() { // eprintln!("Handling incoming mouse event: {:?}", evt); Mouse::handle_incoming_event(evt)?; @@ -485,7 +487,7 @@ impl CnvRunner { self.events_in .multimedia .borrow_mut() - .use_and_drop_mut::>(|events| { + .use_and_drop_mut::>(|events| { while let Some(evt) = events.pop_front() { match &evt { MultimediaEvents::SoundFinishedPlaying(source) => { @@ -755,7 +757,7 @@ impl CnvRunner { &self, buttons: &[Arc], mouse_position: (isize, isize), - ) -> RunnerResult> { + ) -> anyhow::Result> { let mut result_index = None; for graphics in self.visible_graphics.borrow().iter() { if result_index.is_some() { @@ -784,7 +786,7 @@ impl CnvRunner { contents: impl Iterator, parent_object: Option>, source_kind: ScriptSource, - ) -> RunnerResult<()> { + ) -> anyhow::Result<()> { let mut parser_issue_manager: IssueManager = Default::default(); parser_issue_manager.set_handler(Box::new(IssuePrinter)); let mut issue_manager: IssueManager = Default::default(); @@ -836,7 +838,7 @@ impl CnvRunner { } } if let Some(Err(err)) = dec_parser.next_if(|result| result.is_err()) { - return Err(RunnerError::ParserError(err)); + return Err(RunnerError::ParserError(err).into()); } script .objects @@ -883,7 +885,7 @@ impl CnvRunner { self.scripts.borrow_mut().remove_all_scripts(); } - pub fn unload_script(&self, path: &ScenePath) -> RunnerResult<()> { + pub fn unload_script(&self, path: &ScenePath) -> anyhow::Result<()> { self.scripts.borrow_mut().remove_script(path) } @@ -932,9 +934,9 @@ impl CnvRunner { pub fn filter_map_objects( &self, - f: impl Fn(ObjectIndex, &Arc) -> RunnerResult>, + f: impl Fn(ObjectIndex, &Arc) -> anyhow::Result>, buffer: &mut Vec, - ) -> RunnerResult<()> { + ) -> anyhow::Result<()> { buffer.clear(); for object in self.global_objects.borrow().iter() { if let Some(result) = f(ObjectIndex::default(), object)? { @@ -957,7 +959,7 @@ impl CnvRunner { Ok(()) } - pub fn change_scene(self: &Arc, scene_name: &str) -> RunnerResult<()> { + pub fn change_scene(self: &Arc, scene_name: &str) -> anyhow::Result<()> { self.internal_events .borrow_mut() .use_and_drop_mut(|events| events.clear()); @@ -965,7 +967,8 @@ impl CnvRunner { let Some(scene_object) = self.get_object(scene_name) else { return Err(RunnerError::ObjectNotFound { name: scene_name.to_owned(), - }); + } + .into()); }; let CnvContent::Scene(ref scene) = &scene_object.content else { panic!(); diff --git a/pixlib_parser/src/runner/object.rs b/pixlib_parser/src/runner/object.rs index d2facfe..65a8967 100644 --- a/pixlib_parser/src/runner/object.rs +++ b/pixlib_parser/src/runner/object.rs @@ -18,7 +18,7 @@ use super::{ classes::{CnvTypeFactory, DummyCnvType}, initable::Initable, parsers::{discard_if_empty, ProgramParsingError, TypeParsingError}, - CallableIdentifier, CnvContent, RunnerResult, + CallableIdentifier, CnvContent, }; #[derive(Debug, Clone)] @@ -158,7 +158,7 @@ impl CnvObject { identifier: CallableIdentifier, arguments: &[CnvValue], context: Option, - ) -> RunnerResult> { + ) -> anyhow::Result> { let context = context .map(|c| c.with_current_object(self.clone())) .unwrap_or(RunnerContext::new_minimal(&self.parent.runner, self)); @@ -178,7 +178,7 @@ impl CnvObject { // println!("Result is {:?}", result); } - pub fn init(self: &Arc, context: Option) -> RunnerResult<()> { + pub fn init(self: &Arc, context: Option) -> anyhow::Result<()> { let as_initable: Option<&dyn Initable> = (&self.content).into(); let Some(initable) = as_initable else { *self.initialized.borrow_mut() = true; diff --git a/pixlib_parser/src/runner/tree_walking/expression.rs b/pixlib_parser/src/runner/tree_walking/expression.rs index 73dae02..0e43bef 100644 --- a/pixlib_parser/src/runner/tree_walking/expression.rs +++ b/pixlib_parser/src/runner/tree_walking/expression.rs @@ -3,14 +3,14 @@ use crate::{ runner::{CallableIdentifier, RunnerError}, }; -use super::super::{CnvStatement, CnvValue, RunnerContext, RunnerResult}; +use super::super::{CnvStatement, CnvValue, RunnerContext}; pub trait CnvExpression { - fn calculate(&self, context: RunnerContext) -> RunnerResult>; + fn calculate(&self, context: RunnerContext) -> anyhow::Result>; } impl CnvExpression for IgnorableExpression { - fn calculate(&self, context: RunnerContext) -> RunnerResult> { + fn calculate(&self, context: RunnerContext) -> anyhow::Result> { // println!("IgnorableExpression::calculate: {:?}", self); if self.ignored { return Ok(None); @@ -20,7 +20,7 @@ impl CnvExpression for IgnorableExpression { } impl CnvExpression for Expression { - fn calculate(&self, context: RunnerContext) -> RunnerResult> { + fn calculate(&self, context: RunnerContext) -> anyhow::Result> { // println!("Expression::calculate: {:?} with context: {}", self, context); let result = match self { Expression::LiteralBool(b) => Ok(Some(CnvValue::Bool(*b))), @@ -72,7 +72,7 @@ impl CnvExpression for Expression { } impl CnvExpression for Invocation { - fn calculate(&self, context: RunnerContext) -> RunnerResult> { + fn calculate(&self, context: RunnerContext) -> anyhow::Result> { // println!("Invocation::calculate: {:?} with context {}", self, context); if self.parent.is_none() { Ok(None) // TODO: match &self.name @@ -87,7 +87,7 @@ impl CnvExpression for Invocation { .arguments .iter() .map(|e| e.calculate(context.clone())) - .collect::>>()?; + .collect::>>()?; let arguments: Vec<_> = arguments.into_iter().map(|e| e.unwrap()).collect(); // println!("Calling method: {:?} of: {:?}", self.name, self.parent); let name = parent.to_str(); diff --git a/pixlib_parser/src/runner/tree_walking/statement.rs b/pixlib_parser/src/runner/tree_walking/statement.rs index 9c035ab..efcf4a1 100644 --- a/pixlib_parser/src/runner/tree_walking/statement.rs +++ b/pixlib_parser/src/runner/tree_walking/statement.rs @@ -1,13 +1,13 @@ use crate::parser::ast::{ParsedScript, Statement}; -use super::super::{CnvExpression, RunnerContext, RunnerResult}; +use super::super::{CnvExpression, RunnerContext}; pub trait CnvStatement { - fn run(&self, context: RunnerContext) -> RunnerResult<()>; + fn run(&self, context: RunnerContext) -> anyhow::Result<()>; } impl CnvStatement for Statement { - fn run(&self, context: RunnerContext) -> RunnerResult<()> { + fn run(&self, context: RunnerContext) -> anyhow::Result<()> { // println!("Statement::run: {:?}", self); match self { Statement::ExpressionStatement(expression) => { @@ -19,7 +19,7 @@ impl CnvStatement for Statement { } impl CnvStatement for ParsedScript { - fn run(&self, context: RunnerContext) -> RunnerResult<()> { + fn run(&self, context: RunnerContext) -> anyhow::Result<()> { // println!("ParsedScript::run: {:?}", self); self.calculate(context)?; Ok(()) diff --git a/pixlib_parser/src/runner/value.rs b/pixlib_parser/src/runner/value.rs index c9a3001..cadb129 100644 --- a/pixlib_parser/src/runner/value.rs +++ b/pixlib_parser/src/runner/value.rs @@ -6,7 +6,7 @@ use std::{ use crate::runner::{content::CnvContent, CnvObject}; -use super::{RunnerContext, RunnerResult}; +use super::RunnerContext; #[derive(Debug, Clone)] pub enum CnvValue { @@ -97,7 +97,7 @@ impl CnvValue { } } -fn get_reference_value(r: &Arc) -> RunnerResult> { +fn get_reference_value(r: &Arc) -> anyhow::Result> { let context = RunnerContext::new_minimal(&r.parent.runner, r); match &r.content { CnvContent::Expression(e) => Some(e.calculate()).transpose(),