1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00

Add emotigram support; close #115

This commit is contained in:
NG (Graham)
2026-07-09 21:05:32 -04:00
parent 9aaf1b5b5f
commit bab455dc00
6 changed files with 132 additions and 9 deletions

View File

@@ -209,7 +209,7 @@ pub(super) fn all_customisations_provider() -> SimpleFunc<216, crate::UserTy, im
params.insert(OWNED_SKINS_KEY, Typed::StrArr(all_skins().into_iter().map(|x| x.id.into()).collect::<Vec<_>>().into()));
params.insert(OWNED_SPAWNS_KEY, Typed::StrArr(all_spawns().into_iter().map(|x| x.id.into()).collect::<Vec<_>>().into()));
params.insert(OWNED_DEATHS_KEY, Typed::StrArr(all_deaths().into_iter().map(|x| x.id.into()).collect::<Vec<_>>().into()));
params.insert(OWNED_EMOTES_KEY, Typed::StrArr(vec![].into()));
params.insert(OWNED_EMOTES_KEY, Typed::StrArr(vec![].into())); // this isn't used??? (see owned_cosmetics)
Ok(params.into())
})
}

View File

@@ -258,4 +258,5 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy>
.add(custom_game_player_state::game_player_status_update_provider(init_ctx))
.add(custom_game_can_join_queue::game_can_queue_provider(init_ctx))
.add(custom_game_team::game_team_change_provider(init_ctx))
.add(owned_cosmetics::save_selected_cosmetics_provider())
}

View File

@@ -1,21 +1,30 @@
use polariton_server::operations::SimpleFunc;
use polariton::{operation::{Arr, ParameterTable, Typed}, serdes::TypePrefix};
use polariton_server::operations::{SimpleFunc, SimpleOperation, SimpleOpError, SimpleOpImpl};
use polariton::operation::{ParameterTable, Typed};
const PARAM_KEY: u8 = 50;
fn all_emotes() -> Vec<String> {
vec![
// for future reference: part of EmotigramsConfigurableData (-2824383771674178305)
"Craywave".to_owned(),
"Chicken".to_owned(),
"Heart".to_owned(),
"Lol".to_owned(),
"Thumbsdown".to_owned(),
"Thumbsup".to_owned(),
"Facepalm".to_owned(),
]
}
pub(super) fn owned_cosmetics_provider() -> SimpleFunc<23, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
SimpleFunc::new(|params, _| {
let mut params = params.to_dict();
params.insert(PARAM_KEY, Typed::Arr(Arr {
ty: TypePrefix::Str, // str
custom_ty: None,
items: vec![Typed::Str("1".into())],
}));
params.insert(PARAM_KEY, Typed::StrArr(all_emotes().into_iter().map(|x| x.into()).collect::<Vec<_>>().into()));
Ok(params.into())
})
}
pub(super) fn selected_cosmetics_provider() -> SimpleFunc<21, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
/*pub(super) fn selected_cosmetics_provider() -> SimpleFunc<21, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
SimpleFunc::new(|params, _| {
let mut params = params.to_dict();
params.insert(PARAM_KEY, Typed::Arr(Arr {
@@ -25,4 +34,57 @@ pub(super) fn selected_cosmetics_provider() -> SimpleFunc<21, crate::UserTy, imp
}));
Ok(params.into())
})
}*/
pub(super) struct EmoteListSelected;
#[async_trait::async_trait]
impl <C: Send + 'static> SimpleOperation<C> for EmoteListSelected {
type User = crate::UserTy;
const CODE: u8 = 21;
async fn handle(&self, mut params: ParameterTable<C>, user: &Self::User) -> Result<ParameterTable<C>, SimpleOpError> {
let user_info = user.user()?;
let emotes_list = user_info.get_emotes().await?;
params.insert(PARAM_KEY, Typed::StrArr(emotes_list.into_iter().map(|x| x.into()).collect::<Vec<_>>().into()));
Ok(params)
}
}
pub(super) fn selected_cosmetics_provider<C: Send + 'static>() -> SimpleOpImpl<C, crate::UserTy, EmoteListSelected> {
SimpleOpImpl::new(EmoteListSelected)
}
pub(super) struct EmoteListSaver;
#[async_trait::async_trait]
impl <C: Send + 'static> SimpleOperation<C> for EmoteListSaver {
type User = crate::UserTy;
const CODE: u8 = 22;
async fn handle(&self, mut params: ParameterTable<C>, user: &Self::User) -> Result<ParameterTable<C>, SimpleOpError> {
if let Some(emotes) = params.remove(&PARAM_KEY) {
if let Typed::StrArr(str_arr) = emotes {
// unused? code path
let user_info = user.user()?;
let emotes_list: Vec<String> = str_arr.vec.into_iter().map(|x| x.string).collect();
user_info.set_emotes(&emotes_list).await?;
} else if let Typed::Arr(reg_arr) = emotes {
let user_info = user.user()?;
let emotes_list: Vec<String> = reg_arr.items.into_iter().filter_map(|x| {
if let Typed::Str(s) = x {
Some(s.string)
} else {
None
}
}).collect();
user_info.set_emotes(&emotes_list).await?;
}
}
Ok(params)
}
}
pub(super) fn save_selected_cosmetics_provider<C: Send + 'static>() -> SimpleOpImpl<C, crate::UserTy, EmoteListSaver> {
SimpleOpImpl::new(EmoteListSaver)
}