[oden] Move scaling entirely into JavaScript

Now the game controls its own resolution. We might want to further
copy Love2D and generate resize events, I don't know.
This commit is contained in:
John Doty 2023-09-02 09:58:58 -07:00
parent 994be3e493
commit 1cb30034f8
9 changed files with 176 additions and 58 deletions

View file

@ -149,3 +149,10 @@ impl TryIntoValue for () {
Ok(ctx.undefined())
}
}
impl<T: TryIntoValue> TryIntoValue for &[T] {
#[inline]
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
Ok(ctx.undefined())
}
}

View file

@ -232,8 +232,11 @@ impl ValueRef {
Ok(Value::from_raw(result, ctx))
}
pub fn get_property(&self, ctx: &ContextRef, prop: &str) -> Result<Value> {
let atom = ctx.new_atom(prop)?;
pub fn get_property<'a, T>(&self, ctx: &ContextRef, prop: T) -> Result<Value>
where
T: Into<&'a str>,
{
let atom = ctx.new_atom(prop.into())?;
self.get_property_atom(ctx, &atom)
}
@ -241,6 +244,10 @@ impl ValueRef {
ctx.check_exception(unsafe { sys::JS_GetProperty(ctx.ctx, self.val, prop.atom) })
}
pub fn get_index(&self, ctx: &ContextRef, index: u32) -> Result<Value> {
ctx.check_exception(unsafe { sys::JS_GetPropertyUint32(ctx.ctx, self.val, index) })
}
pub fn set_property(&mut self, ctx: &ContextRef, prop: &str, val: &ValueRef) -> Result<()> {
// TODO: Consume API
let atom = ctx.new_atom(prop)?;
@ -264,6 +271,18 @@ impl ValueRef {
}
}
pub fn set_index(&mut self, ctx: &ContextRef, index: u32, val: &ValueRef) -> Result<()> {
unsafe {
sys::JS_DupValue(ctx.ctx, val.val);
let result = sys::JS_SetPropertyUint32(ctx.ctx, self.val, index, val.val);
if result == -1 {
Err(ctx.exception_error())
} else {
Ok(())
}
}
}
pub fn set_fn<F>(
&mut self,
ctx: &ContextRef,