Skip to content

Commit

Permalink
SubGameHandle sends InitState as start
Browse files Browse the repository at this point in the history
  • Loading branch information
DogLooksGood committed Jan 1, 2024
1 parent 7e31507 commit 5617d4e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 3 additions & 2 deletions api/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use crate::{
effect::Effect,
error::{HandleError, HandleResult},
event::Event,
prelude::GamePlayer, types::EntryType,
prelude::GamePlayer,
types::EntryType,
};

/// A subset of on-chain account, used for game handler
Expand Down Expand Up @@ -66,7 +67,7 @@ impl Default for InitAccount {
entry_type: EntryType::Cash {
min_deposit: 100,
max_deposit: 200,
}
},
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions transactor/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::component::{
};
use crate::frame::{EventFrame, SignalFrame};
use race_api::error::{Error, Result};
use race_api::prelude::InitAccount;
use race_core::context::GameContext;
use race_core::transport::TransportT;
use race_core::types::{
Expand Down Expand Up @@ -228,6 +229,11 @@ impl SubGameHandle {
.await?
.ok_or(Error::GameBundleNotFound)?;

// Build an InitAccount
let mut init_account = InitAccount::default();
init_account.addr = addr.clone();
init_account.data = spec.init_data.clone();

let game_context = GameContext::try_new_with_sub_game_spec(spec)?;
let handler = WrappedHandler::load_by_bundle(&bundle_account, encryptor.clone()).await?;

Expand All @@ -244,6 +250,7 @@ impl SubGameHandle {
event_bus.attach(&mut bridge_handle).await;
event_bus.attach(&mut broadcaster_handle).await;
event_bus.attach(&mut event_loop_handle).await;
event_bus.send(EventFrame::InitState { init_account }).await;

Ok(Self {
addr: format!("{}:{}", game_addr, sub_id),
Expand Down
3 changes: 2 additions & 1 deletion transactor/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ pub fn base64_decode(data: &str) -> Result<Vec<u8>, race_api::error::Error> {
}

pub fn addr_shorthand(addr: &str) -> String {
format!("[{}]", &addr[0..3])
let l = addr.len();
format!("[{}]", &addr[(l - 6)..l])
}

0 comments on commit 5617d4e

Please sign in to comment.