refactor: random fixes and usage improvements
This commit is contained in:
@@ -32,10 +32,14 @@ impl UserData for Container {
|
||||
}
|
||||
|
||||
fn add_methods<M: UserDataMethods<Self>>(m: &mut M) {
|
||||
m.add_method("click", |_, this, operation: Table| {
|
||||
this.inner.click(click_operation_from_table(operation)?);
|
||||
Ok(())
|
||||
});
|
||||
m.add_method(
|
||||
"click",
|
||||
|_, this, (operation, operation_type): (Table, Option<u8>)| {
|
||||
this.inner
|
||||
.click(click_operation_from_table(operation, operation_type)?);
|
||||
Ok(())
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,59 +70,63 @@ impl UserData for ContainerRef {
|
||||
Ok(())
|
||||
});
|
||||
|
||||
m.add_method("click", |_, this, operation: Table| {
|
||||
this.inner.click(click_operation_from_table(operation)?);
|
||||
Ok(())
|
||||
});
|
||||
m.add_method(
|
||||
"click",
|
||||
|_, this, (operation, operation_type): (Table, Option<u8>)| {
|
||||
this.inner
|
||||
.click(click_operation_from_table(operation, operation_type)?);
|
||||
Ok(())
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn click_operation_from_table(o: Table) -> Result<ClickOperation> {
|
||||
Ok(match o.get("type")? {
|
||||
fn click_operation_from_table(op: Table, op_type: Option<u8>) -> Result<ClickOperation> {
|
||||
Ok(match op_type.unwrap_or_default() {
|
||||
0 => ClickOperation::Pickup(PickupClick::Left {
|
||||
slot: o.get("slot")?,
|
||||
slot: op.get("slot")?,
|
||||
}),
|
||||
1 => ClickOperation::Pickup(PickupClick::Right {
|
||||
slot: o.get("slot")?,
|
||||
slot: op.get("slot")?,
|
||||
}),
|
||||
2 => ClickOperation::Pickup(PickupClick::LeftOutside),
|
||||
3 => ClickOperation::Pickup(PickupClick::RightOutside),
|
||||
5 => ClickOperation::QuickMove(QuickMoveClick::Right {
|
||||
slot: o.get("slot")?,
|
||||
slot: op.get("slot")?,
|
||||
}),
|
||||
6 => ClickOperation::Swap(SwapClick {
|
||||
source_slot: o.get("source_slot")?,
|
||||
target_slot: o.get("target_slot")?,
|
||||
source_slot: op.get("source_slot")?,
|
||||
target_slot: op.get("target_slot")?,
|
||||
}),
|
||||
7 => ClickOperation::Clone(CloneClick {
|
||||
slot: o.get("slot")?,
|
||||
slot: op.get("slot")?,
|
||||
}),
|
||||
8 => ClickOperation::Throw(ThrowClick::Single {
|
||||
slot: o.get("slot")?,
|
||||
slot: op.get("slot")?,
|
||||
}),
|
||||
9 => ClickOperation::Throw(ThrowClick::All {
|
||||
slot: o.get("slot")?,
|
||||
slot: op.get("slot")?,
|
||||
}),
|
||||
10 => ClickOperation::QuickCraft(QuickCraftClick {
|
||||
kind: match o.get("kind").unwrap_or_default() {
|
||||
kind: match op.get("kind").unwrap_or_default() {
|
||||
1 => QuickCraftKind::Right,
|
||||
2 => QuickCraftKind::Middle,
|
||||
_ => QuickCraftKind::Left,
|
||||
},
|
||||
status: match o.get("status").unwrap_or_default() {
|
||||
status: match op.get("status").unwrap_or_default() {
|
||||
1 => QuickCraftStatus::Add {
|
||||
slot: o.get("slot")?,
|
||||
slot: op.get("slot")?,
|
||||
},
|
||||
2 => QuickCraftStatus::End,
|
||||
_ => QuickCraftStatus::Start,
|
||||
},
|
||||
}),
|
||||
11 => ClickOperation::PickupAll(PickupAllClick {
|
||||
slot: o.get("slot")?,
|
||||
reversed: o.get("reversed").unwrap_or_default(),
|
||||
slot: op.get("slot")?,
|
||||
reversed: op.get("reversed").unwrap_or_default(),
|
||||
}),
|
||||
_ => ClickOperation::QuickMove(QuickMoveClick::Left {
|
||||
slot: o.get("slot")?,
|
||||
slot: op.get("slot")?,
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user