vbox accept

This commit is contained in:
ntr 2019-02-16 19:45:04 +11:00
parent 01468c7081
commit 04714dfdfd
4 changed files with 24 additions and 14 deletions

View File

@ -28,8 +28,8 @@ function registerEvents(registry, events, tutorial) {
registry.set('activeSkill', skill);
}
function setItems(items) {
registry.set('itemList', items);
function setVbox(items) {
registry.set('vbox', items);
}
function setZone(zone) {
@ -177,7 +177,7 @@ function registerEvents(registry, events, tutorial) {
setActiveSkill,
setCryps,
setGame,
setItems,
setVbox,
setWs,
setGameList,
setZone,

View File

@ -111,10 +111,6 @@ function createSocket(events) {
events.setActiveSkill(null);
}
function sendItemUse(item, target) {
send({ method: 'item_use', params: { item, target } });
}
function sendZoneCreate() {
send({ method: 'zone_create', params: {} });
}
@ -187,7 +183,7 @@ function createSocket(events) {
zone_create: res => console.log(res),
zone_state: zoneState,
zone_close: res => console.log(res),
vbox_state: res => console.log(res),
};
function errHandler(error) {
@ -274,7 +270,6 @@ function createSocket(events) {
sendCrypSpawn,
sendCrypLearn,
sendCrypForget,
sendItemUse,
sendSpecForget,
sendZoneCreate,
sendZoneJoin,

View File

@ -80,7 +80,7 @@ impl Rpc {
"vbox_state" => Rpc::vbox_state(data, &mut tx, account.unwrap(), client),
"vbox_accept" => Rpc::vbox_accept(data, &mut tx, account.unwrap(), client),
"vbox_discard" => Rpc::vbox_accept(data, &mut tx, account.unwrap(), client),
"vbox_discard" => Rpc::vbox_discard(data, &mut tx, account.unwrap(), client),
"vbox_combine" => Rpc::vbox_combine(data, &mut tx, account.unwrap(), client),
_ => Err(format_err!("unknown method - {:?}", v.method)),
@ -633,7 +633,7 @@ struct VboxAcceptMsg {
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct VboxAcceptParams {
pub game_id: Uuid,
pub index: u8,
pub index: usize,
}
#[derive(Debug,Clone,Serialize,Deserialize)]

View File

@ -63,6 +63,18 @@ impl Vbox {
self
}
pub fn accept(&mut self, i: usize) -> Result<&mut Vbox, Error> {
if self.bound.len() > 8 {
return Err(err_msg("too many vars bound"));
}
self.free.get(i).ok_or(format_err!("no var at index {:?}", i))?;
self.bound.push(self.free.remove(i));
Ok(self)
}
}
pub fn vbox_write(vbox: Vbox, tx: &mut Transaction, account: &Account) -> Result<Vbox, Error> {
@ -109,7 +121,7 @@ pub fn vbox_get(tx: &mut Transaction, game_id: Uuid, account: &Account) -> Resul
pub fn vbox_state(params: VboxStateParams, tx: &mut Transaction, account: &Account) -> Result<Vbox, Error> {
match vbox_get(tx, params.game_id, account) {
Ok(v) => Ok(v),
Ok(v) => Ok(v.fill()),
Err(e) => {
println!("{:?}", e);
vbox_write(Vbox::new(account.id, params.game_id).fill(), tx, account)
@ -123,8 +135,11 @@ pub fn vbox_discard(params: VboxDiscardParams, tx: &mut Transaction, account: &A
}
pub fn vbox_accept(params: VboxAcceptParams, tx: &mut Transaction, account: &Account) -> Result<Vbox, Error> {
let vbox = vbox_get(tx, params.game_id, account)?;
return Ok(vbox);
let mut vbox = vbox_get(tx, params.game_id, account)?;
vbox.accept(params.index)?;
return vbox_write(vbox, tx, account);
}
pub fn vbox_combine(params: VboxCombineParams, tx: &mut Transaction, account: &Account) -> Result<Vbox, Error> {