Add slot machine support.

GitOrigin-RevId: e0c3c5d9b2cff2870162f11983bd546aba101caf
This commit is contained in:
levlam 2020-10-15 15:59:51 +03:00
parent 33b7ba57a9
commit fd9732dcfa
5 changed files with 61 additions and 15 deletions

View File

@ -1589,12 +1589,12 @@ messageVenue venue:venue = MessageContent;
messageContact contact:contact = MessageContent;
//@description A dice message. The dice value is randomly generated by the server
//@initial_state_sticker The animated sticker with the initial dice animation; may be null if unknown. updateMessageContent will be sent when the sticker became known
//@final_state_sticker The animated sticker with the final dice animation; may be null if unknown. updateMessageContent will be sent when the sticker became known
//@initial_state The animated stickers with the initial dice animation; may be null if unknown. updateMessageContent will be sent when the sticker became known
//@final_state The animated stickers with the final dice animation; may be null if unknown. updateMessageContent will be sent when the sticker became known
//@emoji Emoji on which the dice throw animation is based
//@value The dice value. If the value is 0, the dice don't have final state yet
//@success_animation_frame_number Number of frame after which a success animation like a shower of confetti needs to be shown on updateMessageSendSucceeded
messageDice initial_state_sticker:sticker final_state_sticker:sticker emoji:string value:int32 success_animation_frame_number:int32 = MessageContent;
messageDice initial_state:DiceStickers final_state:DiceStickers emoji:string value:int32 success_animation_frame_number:int32 = MessageContent;
//@description A message with a game @game The game description
messageGame game:game = MessageContent;
@ -2066,6 +2066,20 @@ phoneNumberAuthenticationSettings allow_flash_call:Bool is_current_phone_number:
animations animations:vector<animation> = Animations;
//@class DiceStickers @description Contains animated stickers which should be used for dice animation rendering
//@description A regular animated sticker @sticker The animated sticker with the dice animation
diceStickersRegular sticker:sticker = DiceStickers;
//@description Animated stickers to be combined into a slot machine
//@background The animated sticker with the slot machine background
//@lever The animated sticker with the lever animation
//@left_reel The animated sticker with the left reel
//@center_reel The animated sticker with the center reel
//@right_reel The animated sticker with the right reel
diceStickersSlotMachine background:sticker lever:sticker left_reel:sticker center_reel:sticker right_reel:sticker = DiceStickers;
//@description Represents the result of an ImportContacts request @user_ids User identifiers of the imported contacts in the same order as they were specified in the request; 0 if the contact is not yet a registered user
//@importer_count The number of users that imported the corresponding contact; 0 for already registered users or if unavailable
importedContacts user_ids:vector<int32> importer_count:vector<int32> = ImportedContacts;

Binary file not shown.

View File

@ -4539,9 +4539,9 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
}
case MessageContentType::Dice: {
const MessageDice *m = static_cast<const MessageDice *>(content);
auto initial_state = td->stickers_manager_->get_dice_sticker_object(m->emoji, 0);
auto initial_state = td->stickers_manager_->get_dice_stickers_object(m->emoji, 0);
auto final_state =
m->dice_value == 0 ? nullptr : td->stickers_manager_->get_dice_sticker_object(m->emoji, m->dice_value);
m->dice_value == 0 ? nullptr : td->stickers_manager_->get_dice_stickers_object(m->emoji, m->dice_value);
auto success_animation_frame_number =
td->stickers_manager_->get_dice_success_animation_frame_number(m->emoji, m->dice_value);
return make_tl_object<td_api::messageDice>(std::move(initial_state), std::move(final_state), m->emoji,

View File

@ -1163,7 +1163,8 @@ void StickersManager::init() {
animated_emoji_sticker_set.short_name_);
}
dice_emojis_str_ = G()->shared_config().get_option_string("dice_emojis", "🎲\x01🎯\x01🏀\x01\x01⚽️");
dice_emojis_str_ =
G()->shared_config().get_option_string("dice_emojis", "🎲\x01🎯\x01🏀\x01\x01⚽️\x01🎰");
dice_emojis_ = full_split(dice_emojis_str_, '\x01');
for (auto &dice_emoji : dice_emojis_) {
auto &animated_dice_sticker_set = add_special_sticker_set(SpecialStickerSetType::animated_dice(dice_emoji));
@ -1373,7 +1374,7 @@ tl_object_ptr<td_api::stickers> StickersManager::get_stickers_object(const vecto
return result;
}
tl_object_ptr<td_api::sticker> StickersManager::get_dice_sticker_object(const string &emoji, int32 value) const {
tl_object_ptr<td_api::DiceStickers> StickersManager::get_dice_stickers_object(const string &emoji, int32 value) const {
if (td_->auth_manager_->is_bot()) {
return nullptr;
}
@ -1387,12 +1388,42 @@ tl_object_ptr<td_api::sticker> StickersManager::get_dice_sticker_object(const st
}
auto sticker_set_id = it->second.id_;
if (sticker_set_id.is_valid()) {
auto sticker_set = get_sticker_set(sticker_set_id);
CHECK(sticker_set != nullptr);
if (sticker_set->was_loaded && value >= 0 && value < static_cast<int32>(sticker_set->sticker_ids.size())) {
return get_sticker_object(sticker_set->sticker_ids[value]);
if (!sticker_set_id.is_valid()) {
return nullptr;
}
auto sticker_set = get_sticker_set(sticker_set_id);
CHECK(sticker_set != nullptr);
if (!sticker_set->was_loaded) {
return nullptr;
}
auto get_sticker = [&](int32 value) {
return get_sticker_object(sticker_set->sticker_ids[value]);
};
if (emoji == "🎰") {
if (sticker_set->sticker_ids.size() < 21 || value < 0 || value > 64) {
return nullptr;
}
int32 background_id = value == 64 ? 1 : 0;
int32 lever_id = 2;
int32 left_reel_id = value == 64 ? 3 : 8;
int32 center_reel_id = value == 64 ? 9 : 14;
int32 right_reel_id = value == 64 ? 15 : 20;
if (value != 0 && value != 64) {
left_reel_id = 4 + (value % 4);
center_reel_id = 10 + ((value + 3) / 4 % 4);
right_reel_id = 16 + ((value + 15) / 16 % 4);
}
return td_api::make_object<td_api::diceStickersSlotMachine>(get_sticker(background_id), get_sticker(lever_id),
get_sticker(left_reel_id), get_sticker(center_reel_id),
get_sticker(right_reel_id));
}
if (value >= 0 && value < static_cast<int32>(sticker_set->sticker_ids.size())) {
return td_api::make_object<td_api::diceStickersRegular>(get_sticker(value));
}
return nullptr;
}
@ -3447,7 +3478,8 @@ void StickersManager::on_update_dice_emojis() {
return;
}
auto dice_emojis_str = G()->shared_config().get_option_string("dice_emojis", "🎲\x01🎯\x01🏀\x01\x01⚽️");
auto dice_emojis_str =
G()->shared_config().get_option_string("dice_emojis", "🎲\x01🎯\x01🏀\x01\x01⚽️\x01🎰");
if (dice_emojis_str == dice_emojis_str_) {
return;
}
@ -3482,7 +3514,7 @@ void StickersManager::on_update_dice_success_values() {
}
auto dice_success_values_str =
G()->shared_config().get_option_string("dice_success_values", "0,6:62,5:110,5:110,5:110");
G()->shared_config().get_option_string("dice_success_values", "0,6:62,5:110,5:110,5:110,64:110");
if (dice_success_values_str == dice_success_values_str_) {
return;
}

View File

@ -53,7 +53,7 @@ class StickersManager : public Actor {
tl_object_ptr<td_api::stickers> get_stickers_object(const vector<FileId> &sticker_ids) const;
tl_object_ptr<td_api::sticker> get_dice_sticker_object(const string &emoji, int32 value) const;
tl_object_ptr<td_api::DiceStickers> get_dice_stickers_object(const string &emoji, int32 value) const;
int32 get_dice_success_animation_frame_number(const string &emoji, int32 value) const;