mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-04-22 06:02:04 +02:00
Give Discord.user_avatar an optional size argument
This commit is contained in:
parent
4fbe56803f
commit
1e3661fdee
6 changed files with 30 additions and 14 deletions
|
@ -72,7 +72,7 @@ The syntax is: `--<option>=<value>`
|
||||||
|
|
||||||
Example: `./mkxp --gameFolder="my game" --vsync=true --fixedFramerate=60`
|
Example: `./mkxp --gameFolder="my game" --vsync=true --fixedFramerate=60`
|
||||||
|
|
||||||
## Discord Support
|
## Discord GameSDK
|
||||||
|
|
||||||
mkxp-z can optionally be built with support for the Discord GameSDK. Currently only basic Activity (rich presence) functionality is implemented. The Discord module is being actively fleshed out.
|
mkxp-z can optionally be built with support for the Discord GameSDK. Currently only basic Activity (rich presence) functionality is implemented. The Discord module is being actively fleshed out.
|
||||||
|
|
||||||
|
@ -82,9 +82,15 @@ A different Client ID may be specified in the configuration file.
|
||||||
if Discord.connected?
|
if Discord.connected?
|
||||||
p Discord.user_name, Discord.user_discriminator, Discord.user_id
|
p Discord.user_name, Discord.user_discriminator, Discord.user_id
|
||||||
|
|
||||||
|
avatar = Sprite.new
|
||||||
|
avatar.bitmap = Discord.user_avatar(64)
|
||||||
|
avatar.visible = true
|
||||||
|
|
||||||
Discord::Activity.new do |activity|
|
Discord::Activity.new do |activity|
|
||||||
activity.start_time = Time.now.to_i
|
activity.start_time = Time.now.to_i
|
||||||
activity.details = MKXP.game_title
|
activity.details = MKXP.game_title
|
||||||
|
activity.large_image = "someimage"
|
||||||
|
activity.large_text = "sometext"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
|
@ -50,8 +50,10 @@ void bitmapInitProps(Bitmap *b, VALUE self);
|
||||||
RB_METHOD(DiscordGetUserAvatar)
|
RB_METHOD(DiscordGetUserAvatar)
|
||||||
{
|
{
|
||||||
RB_UNUSED_PARAM;
|
RB_UNUSED_PARAM;
|
||||||
|
int size = 32;
|
||||||
|
rb_get_args(argc, argv, "|i", &size RB_ARG_END);
|
||||||
|
|
||||||
Bitmap *result = shState->discord().userAvatar();
|
Bitmap *result = shState->discord().userAvatar(size);
|
||||||
if (!result) return RUBY_Qnil;
|
if (!result) return RUBY_Qnil;
|
||||||
|
|
||||||
VALUE ret = wrapObject(result, BitmapType);
|
VALUE ret = wrapObject(result, BitmapType);
|
||||||
|
|
BIN
screenshot.png
BIN
screenshot.png
Binary file not shown.
Before Width: | Height: | Size: 226 KiB After Width: | Height: | Size: 53 KiB |
|
@ -211,30 +211,38 @@ DiscordUserId DiscordState::userId()
|
||||||
typedef struct { DiscordStatePrivate *pri; Bitmap *bmp; } AvatarCbData;
|
typedef struct { DiscordStatePrivate *pri; Bitmap *bmp; } AvatarCbData;
|
||||||
Bitmap *DiscordState::getAvatar(DiscordUserId userId, int size)
|
Bitmap *DiscordState::getAvatar(DiscordUserId userId, int size)
|
||||||
{
|
{
|
||||||
|
size = clamp(size, 32, 256);
|
||||||
|
while ((size & (size-1)) != 0) {
|
||||||
|
size++;
|
||||||
|
}
|
||||||
|
|
||||||
if (!isConnected()) return 0;
|
if (!isConnected()) return 0;
|
||||||
AvatarCbData cbData{};
|
AvatarCbData *cbData = new AvatarCbData;
|
||||||
cbData.bmp = new Bitmap(size, size);
|
Bitmap *ret = new Bitmap(size, size);
|
||||||
cbData.pri = p;
|
cbData->bmp = ret;
|
||||||
|
cbData->pri = p;
|
||||||
DiscordImageHandle handle{};
|
DiscordImageHandle handle{};
|
||||||
handle.id = userId;
|
handle.id = userId;
|
||||||
handle.size = size;
|
handle.size = size;
|
||||||
|
|
||||||
p->app.images->fetch(p->app.images, handle, true, &cbData,
|
p->app.images->fetch(p->app.images, handle, true, cbData,
|
||||||
[](void *callback_data, enum EDiscordResult result, struct DiscordImageHandle handle_result){
|
[](void *callback_data, enum EDiscordResult result, struct DiscordImageHandle handle_result){
|
||||||
if (result == DiscordResult_Ok)
|
if (result == DiscordResult_Ok)
|
||||||
{
|
{
|
||||||
AvatarCbData *data = (AvatarCbData*)callback_data;
|
AvatarCbData *data = (AvatarCbData*)callback_data;
|
||||||
|
if (data->bmp->isDisposed()) return;
|
||||||
int sz = data->bmp->width()*data->bmp->height()*4;
|
int sz = data->bmp->width()*data->bmp->height()*4;
|
||||||
uint8_t *buf = new uint8_t[sz];
|
uint8_t *buf = new uint8_t[sz];
|
||||||
data->pri->app.images->get_data(data->pri->app.images, handle_result, buf, sz);
|
data->pri->app.images->get_data(data->pri->app.images, handle_result, buf, sz);
|
||||||
data->bmp->replaceRaw(buf, data->bmp->width(), data->bmp->height());
|
data->bmp->replaceRaw(buf, data->bmp->width(), data->bmp->height());
|
||||||
delete[] buf;
|
delete[] buf;
|
||||||
|
delete data;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return cbData.bmp;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap *DiscordState::userAvatar()
|
Bitmap *DiscordState::userAvatar(int size)
|
||||||
{
|
{
|
||||||
return (p->userPresent) ? getAvatar(p->currentUser.id, 256) : 0;
|
return (p->userPresent) ? getAvatar(p->currentUser.id, size) : 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ public:
|
||||||
DiscordUserId userId();
|
DiscordUserId userId();
|
||||||
|
|
||||||
Bitmap *getAvatar(DiscordUserId userId, int size);
|
Bitmap *getAvatar(DiscordUserId userId, int size);
|
||||||
Bitmap *userAvatar();
|
Bitmap *userAvatar(int size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DiscordStatePrivate *p;
|
DiscordStatePrivate *p;
|
||||||
|
|
|
@ -670,6 +670,10 @@ void Graphics::update()
|
||||||
p->checkShutDownReset();
|
p->checkShutDownReset();
|
||||||
p->checkSyncLock();
|
p->checkSyncLock();
|
||||||
|
|
||||||
|
#ifdef HAVE_DISCORDSDK
|
||||||
|
shState->discord().update();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (p->frozen)
|
if (p->frozen)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -691,10 +695,6 @@ void Graphics::update()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_DISCORDSDK
|
|
||||||
if (p->frameCount % 10 == 0) shState->discord().update();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
p->checkResize();
|
p->checkResize();
|
||||||
p->redrawScreen();
|
p->redrawScreen();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue