Skip to content

Commit

Permalink
Add button to view level on site
Browse files Browse the repository at this point in the history
  • Loading branch information
Beyley committed Aug 22, 2023
1 parent ad640fe commit f1c0569
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
.version = "0.0.0",
.dependencies = .{
.@"zig-discord" = .{
.url = "https://github.com/Beyley/zig-discord/archive/535bbf730616887e48d7f36c01a04a3bb1ecd81f.tar.gz",
.hash = "1220274bcea2b0b0e4429f56903c89f78caf6cf28082d8dc07778e84a0c3780b4db2",
.url = "https://github.com/Beyley/zig-discord/archive/c512cdc50e0b97cd6a4a4ca92dea92d6b0de8733.tar.gz",
.hash = "12205fdd48bee613a162c668eeef2054650ecb612ddb0660587525b1fcb639e5538c",
},
.zBoxer = .{
.url = "https://github.com/Beyley/zBoxer/archive/8ba46a2fe50d658f1406c9681b8b931df24edf37.tar.gz",
Expand Down
36 changes: 30 additions & 6 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pub fn runApp(allocator: std.mem.Allocator) !void {
name: Rpc.Packet.ArrayString(128),
publisher_username: Rpc.Packet.ArrayString(128),
icon_hash: Rpc.Packet.ArrayString(256),
site_url: Rpc.Packet.ArrayString(256),

/// Creates a new level info struct, pulling level info from the API
/// Returns null when the level is not found
Expand All @@ -121,6 +122,14 @@ pub fn runApp(allocator: std.mem.Allocator) !void {
.name = Rpc.Packet.ArrayString(128).create(level_info.value.data.title),
.publisher_username = Rpc.Packet.ArrayString(128).create(level_info.value.data.publisher.username),
.icon_hash = Rpc.Packet.ArrayString(256).create(level_info.value.data.iconHash),
.site_url = blk: {
var str: Rpc.Packet.ArrayString(256) = undefined;
var stream = std.io.fixedBufferStream(&str.buf);
try _uri.format("+", .{}, stream.writer());
try std.fmt.format(stream.writer(), "/level/{d}", .{id});
str.len = stream.pos;
break :blk str;
},
}
else
null;
Expand Down Expand Up @@ -158,12 +167,7 @@ pub fn runApp(allocator: std.mem.Allocator) !void {
}

var presence = Rpc.Packet.Presence{
.buttons = &.{
Rpc.Packet.Presence.Button{
.label = "Profile",
.url = profile_url.items,
},
},
.buttons = undefined,
.details = Rpc.Packet.ArrayString(128).create(switch (player_status.value.data.levelType) {
.story => "Playing a story level",
.online => "Playing a level",
Expand Down Expand Up @@ -270,6 +274,26 @@ pub fn runApp(allocator: std.mem.Allocator) !void {
else => {},
}

if (last_level_info) |level_info| {
presence.buttons = &.{
Rpc.Packet.Presence.Button{
.label = Rpc.Packet.ArrayString(128).create("Profile"),
.url = Rpc.Packet.ArrayString(256).create(profile_url.items),
},
Rpc.Packet.Presence.Button{
.label = Rpc.Packet.ArrayString(128).create("Level"),
.url = level_info.site_url,
},
};
} else {
presence.buttons = &.{
Rpc.Packet.Presence.Button{
.label = Rpc.Packet.ArrayString(128).create("Profile"),
.url = Rpc.Packet.ArrayString(256).create(profile_url.items),
},
};
}

//Apply the new presence
try rpc_client.setPresence(presence);

Expand Down

0 comments on commit f1c0569

Please sign in to comment.