diff --git a/README.md b/README.md index ba069ce..54e4304 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # bevy_dev_console -`bevy_dev_console` is a [Source](https://en.wikipedia.org/wiki/Source_(game_engine))-like developer console plugin for the [Bevy Game Engine](https://github.com/bevyengine/bevy). +`bevy_dev_console` is a Source-inspired developer console plugin for the [Bevy Game Engine](https://github.com/bevyengine/bevy). ![Image of the developer console](doc/console.png) diff --git a/src/builtin_parser/runner.rs b/src/builtin_parser/runner.rs index 2bf16d8..1acc15d 100644 --- a/src/builtin_parser/runner.rs +++ b/src/builtin_parser/runner.rs @@ -190,25 +190,28 @@ fn eval_expression( }; let Spanned { span, value } = *value_expr; match value { - Expression::Variable(variable) => { - if enum_info.contains_variant(&variable) { - let new_enum = DynamicEnum::new(variable, ()); - - dyn_enum.apply(&new_enum); - } else { - Err(RunError::EnumVariantNotFound { - name: variable, - span, - })? - } + Expression::Variable(name) => { + let variant_info = match enum_info.variant(&name) { + Some(variant_info) => variant_info, + None => { + return Err(RunError::EnumVariantNotFound(span.wrap(name))) + } + }; + let VariantInfo::Unit(_) = variant_info else { + return todo_error!("{variant_info:?}"); + }; + + let new_enum = DynamicEnum::new(name, ()); + + dyn_enum.apply(&new_enum); } Expression::StructObject { name, map } => { - let variant_info = enum_info.variant(&name).ok_or( - RunError::EnumVariantNotFound { - name: name.clone(), - span: span.clone(), - }, - )?; + let variant_info = match enum_info.variant(&name) { + Some(variant_info) => variant_info, + None => { + return Err(RunError::EnumVariantNotFound(span.wrap(name))) + } + }; let VariantInfo::Struct(variant_info) = variant_info else { return todo_error!("{variant_info:?}"); }; diff --git a/src/builtin_parser/runner/error.rs b/src/builtin_parser/runner/error.rs index 9365658..ca2233c 100644 --- a/src/builtin_parser/runner/error.rs +++ b/src/builtin_parser/runner/error.rs @@ -31,10 +31,7 @@ pub enum RunError { actual: String, span: Span, }, - EnumVariantNotFound { - name: String, - span: Span, - }, + EnumVariantNotFound(Spanned), CannotMoveOutOfResource(Spanned), CannotNegateUnsignedInteger(Spanned), IncompatibleNumberTypes { @@ -53,7 +50,8 @@ pub enum RunError { span: Span, }, ExpectedVariableGotFunction(Spanned), - CannotReflectReference(std::ops::Range), + CannotReflectReference(Span), + CannotReflectResource(Span), } impl RunError { @@ -72,7 +70,7 @@ impl RunError { VariableMoved(Spanned { span, .. }) => vec![span.clone()], CannotBorrowValue(Spanned { span, .. }) => vec![span.clone()], IncompatibleReflectTypes { span, .. } => vec![span.clone()], - EnumVariantNotFound { span, .. } => vec![span.clone()], + EnumVariantNotFound(Spanned { span, .. }) => vec![span.clone()], EnumVariantStructFieldNotFound { span, .. } => vec![span.clone()], CannotMoveOutOfResource(Spanned { span, .. }) => vec![span.clone()], CannotNegateUnsignedInteger(Spanned { span, .. }) => vec![span.clone()], @@ -80,6 +78,7 @@ impl RunError { IncompatibleFunctionParameter { span, .. } => vec![span.clone()], ExpectedVariableGotFunction(Spanned { span, .. }) => vec![span.clone()], CannotReflectReference(span) => vec![span.clone()], + CannotReflectResource(span) => vec![span.clone()], } } /// Returns all the hints for this error. @@ -119,7 +118,9 @@ impl RunError { "Cannot set incompatible reflect types. Expected `{expected}`, got `{actual}`" ) .into(), - EnumVariantNotFound { name, span } => todo!(), + EnumVariantNotFound(Spanned { value: name, .. }) => { + format!("Enum variant `{name}` was not found.").into() + } EnumVariantStructFieldNotFound { field_name, variant_name, @@ -150,6 +151,9 @@ impl RunError { CannotReflectReference(_) => { "Cannot reflect a reference. Try dereferencing it instead.".into() } + CannotReflectResource(_) => { + "Cannot reflecting resources is not possible at the moment.".into() + } } } } diff --git a/src/builtin_parser/runner/reflection.rs b/src/builtin_parser/runner/reflection.rs index 937cc57..b0565f9 100644 --- a/src/builtin_parser/runner/reflection.rs +++ b/src/builtin_parser/runner/reflection.rs @@ -49,7 +49,7 @@ pub fn object_to_dynamic_struct( let mut dynamic_struct = DynamicStruct::default(); for (key, (value, span, reflect)) in hashmap { - dynamic_struct.insert_boxed(&key, value.reflect(span, &reflect)?); + dynamic_struct.insert_boxed(&key, value.reflect(span, reflect)?); } Ok(dynamic_struct) diff --git a/src/builtin_parser/runner/value.rs b/src/builtin_parser/runner/value.rs index da50652..c3240a8 100644 --- a/src/builtin_parser/runner/value.rs +++ b/src/builtin_parser/runner/value.rs @@ -71,7 +71,7 @@ impl Value { Ok(Box::new(dyn_struct)) } - Value::Resource(_) => todo!(), + Value::Resource(_) => Err(RunError::CannotReflectResource(span)), } }