mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2025-03-05 00:40:19 +01:00
a bunch of improvements to playtwitch
This commit is contained in:
parent
4c4139709a
commit
4ecae122c5
4 changed files with 196 additions and 117 deletions
|
@ -3,6 +3,13 @@ const c = @import("ffi.zig").c;
|
|||
const config = @import("config.zig");
|
||||
const log = std.log.scoped(.state);
|
||||
|
||||
pub const Entry = union(enum) {
|
||||
channel: ChannelEntry,
|
||||
|
||||
/// a seperator in the channel list, the optional string is a heading.
|
||||
separator: ?[]const u8,
|
||||
};
|
||||
|
||||
pub const ChannelEntry = struct {
|
||||
name: []const u8,
|
||||
comment: ?[]const u8,
|
||||
|
@ -23,7 +30,7 @@ chatty: bool,
|
|||
chatty_alive: bool,
|
||||
|
||||
/// an array of channels, composed of slices into `channels_file_data`
|
||||
channels: ?[]ChannelEntry,
|
||||
channels: ?[]Entry,
|
||||
|
||||
/// the data of the channels configuration file
|
||||
channels_file_data: ?[]u8,
|
||||
|
|
|
@ -26,16 +26,16 @@ pub fn configLoaderThread(state: *State) !void {
|
|||
defer file.close();
|
||||
|
||||
const channels_data = try file.readToEndAlloc(std.heap.c_allocator, std.math.maxInt(usize));
|
||||
var channels = std.ArrayList(State.ChannelEntry).init(std.heap.c_allocator);
|
||||
var channels = std.ArrayList(State.Entry).init(std.heap.c_allocator);
|
||||
|
||||
var channels_iter = std.mem.split(u8, channels_data, "\n");
|
||||
var channels_iter = std.mem.tokenize(u8, channels_data, "\n");
|
||||
while (channels_iter.next()) |line| {
|
||||
var line_iter = std.mem.split(u8, line, ":");
|
||||
var line_iter = std.mem.tokenize(u8, line, ":");
|
||||
|
||||
const channel = line_iter.next() orelse continue;
|
||||
const channel_trimmed = std.mem.trim(u8, channel, " \n\r");
|
||||
|
||||
if (channel_trimmed.len == 0 or channel_trimmed[0] == '#')
|
||||
if (channel_trimmed.len <= 0 or channel_trimmed[0] == '#')
|
||||
continue;
|
||||
|
||||
const comment_trimmed = blk: {
|
||||
|
@ -49,16 +49,24 @@ pub fn configLoaderThread(state: *State) !void {
|
|||
break :blk comment_trimmed;
|
||||
};
|
||||
|
||||
try channels.append(.{
|
||||
// dashes act as separator
|
||||
if (std.mem.allEqual(u8, channel_trimmed, '-')) {
|
||||
// separators can have comments to act as headings
|
||||
try channels.append(.{ .separator = comment_trimmed });
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
try channels.append(.{ .channel = .{
|
||||
.name = channel_trimmed,
|
||||
.comment = comment_trimmed,
|
||||
});
|
||||
} });
|
||||
}
|
||||
|
||||
const end_time = std.time.milliTimestamp();
|
||||
|
||||
log.info(
|
||||
"Loaded {d} channels in {d}ms",
|
||||
"Loaded {d} channel items in {d}ms",
|
||||
.{ channels.items.len, end_time - start_time },
|
||||
);
|
||||
|
||||
|
|
|
@ -16,13 +16,25 @@ pub fn winContent(state: *State) !void {
|
|||
|
||||
var start: StartType = .none;
|
||||
|
||||
// Chatty checkbox
|
||||
_ = c.igCheckbox("Start Chatty", &state.chatty);
|
||||
if (c.igBeginTable(
|
||||
"##text_inputs",
|
||||
2,
|
||||
0,
|
||||
.{ .x = 0.0, .y = 0.0 },
|
||||
0.0,
|
||||
)) {
|
||||
defer c.igEndTable();
|
||||
|
||||
c.igTableSetupColumn("##label", c.ImGuiTableColumnFlags_WidthFixed, 85.0, 0);
|
||||
c.igTableSetupColumn("##input", 0, 0.0, 0);
|
||||
|
||||
_ = c.igTableNextRow(0, 0.0);
|
||||
|
||||
// Quality input
|
||||
igu.sliceText("Quality ");
|
||||
c.igSameLine(0.0, 0.0);
|
||||
_ = c.igTableSetColumnIndex(0);
|
||||
igu.sliceText("Quality");
|
||||
|
||||
_ = c.igTableSetColumnIndex(1);
|
||||
if (c.igInputText(
|
||||
"##quality_input",
|
||||
&state.quality_buf,
|
||||
|
@ -80,8 +92,10 @@ pub fn winContent(state: *State) !void {
|
|||
}
|
||||
}
|
||||
|
||||
igu.sliceText("Play Channel ");
|
||||
c.igSameLine(0.0, 0.0);
|
||||
_ = c.igTableNextRow(0, 0.0);
|
||||
_ = c.igTableSetColumnIndex(0);
|
||||
igu.sliceText("Play Channel");
|
||||
_ = c.igTableSetColumnIndex(1);
|
||||
if (c.igInputText(
|
||||
"##play_channel_input",
|
||||
&state.channel_name_buf,
|
||||
|
@ -96,6 +110,7 @@ pub fn winContent(state: *State) !void {
|
|||
if (c.igButton("Play!", .{ .x = 0.0, .y = 0.0 })) {
|
||||
start = .channel_bar;
|
||||
}
|
||||
}
|
||||
|
||||
if (state.channels != null) {
|
||||
c.igBeginDisabled(state.live_status_loading);
|
||||
|
@ -104,8 +119,13 @@ pub fn winContent(state: *State) !void {
|
|||
(try std.Thread.spawn(.{}, @import("live.zig").reloadLiveThread, .{state}))
|
||||
.detach();
|
||||
}
|
||||
|
||||
c.igSameLine(0, 5.0);
|
||||
}
|
||||
|
||||
// Chatty checkbox
|
||||
_ = c.igCheckbox("Start Chatty", &state.chatty);
|
||||
|
||||
if (state.channels != null and c.igBeginChild_Str(
|
||||
"Quick Pick",
|
||||
.{ .x = 0.0, .y = 0.0 },
|
||||
|
@ -133,7 +153,15 @@ pub fn winContent(state: *State) !void {
|
|||
_ = c.igTableSetColumnIndex(2);
|
||||
c.igTableHeader("Live?");
|
||||
|
||||
for (state.channels.?) |ch, i| {
|
||||
for (state.channels.?) |entry, i| {
|
||||
c.igPushID_Int(@intCast(c_int, i));
|
||||
defer c.igPopID();
|
||||
|
||||
_ = c.igTableNextRow(0, 0.0);
|
||||
_ = c.igTableSetColumnIndex(0);
|
||||
|
||||
switch (entry) {
|
||||
.channel => |ch| {
|
||||
var ch_buf: [256]u8 = undefined;
|
||||
const formatted = try std.fmt.bufPrintZ(
|
||||
&ch_buf,
|
||||
|
@ -141,12 +169,6 @@ pub fn winContent(state: *State) !void {
|
|||
.{ch.name},
|
||||
);
|
||||
|
||||
c.igPushID_Int(@intCast(c_int, i));
|
||||
defer c.igPopID();
|
||||
|
||||
_ = c.igTableNextRow(0, 0.0);
|
||||
_ = c.igTableSetColumnIndex(0);
|
||||
|
||||
if (c.igSelectable_Bool(
|
||||
formatted.ptr,
|
||||
false,
|
||||
|
@ -179,6 +201,43 @@ pub fn winContent(state: *State) !void {
|
|||
c.igGetStyle().*.Colors[c.ImGuiCol_Text] = live_color;
|
||||
igu.sliceText(live_label);
|
||||
c.igGetStyle().*.Colors[c.ImGuiCol_Text] = prev_col;
|
||||
},
|
||||
.separator => |heading| {
|
||||
if (heading) |h| {
|
||||
const spacer_size = c.ImVec2{ .x = 0.0, .y = 2.0 };
|
||||
|
||||
c.igDummy(spacer_size);
|
||||
const prev_col = c.igGetStyle().*.Colors[c.ImGuiCol_Text];
|
||||
c.igGetStyle().*.Colors[c.ImGuiCol_Text] = c.ImVec4{
|
||||
.x = 0.7,
|
||||
.y = 0.2,
|
||||
.z = 0.9,
|
||||
.w = 1.0,
|
||||
};
|
||||
igu.sliceText(h);
|
||||
c.igGetStyle().*.Colors[c.ImGuiCol_Text] = prev_col;
|
||||
|
||||
// TODO: is this the best way to do the alignment?
|
||||
c.igSeparator();
|
||||
|
||||
_ = c.igTableSetColumnIndex(1);
|
||||
c.igDummy(spacer_size);
|
||||
c.igDummy(c.ImVec2{ .x = 0.0, .y = c.igGetTextLineHeight() });
|
||||
c.igSeparator();
|
||||
|
||||
_ = c.igTableSetColumnIndex(2);
|
||||
c.igDummy(spacer_size);
|
||||
c.igDummy(c.ImVec2{ .x = 0.0, .y = c.igGetTextLineHeight() });
|
||||
c.igSeparator();
|
||||
} else {
|
||||
c.igSeparator();
|
||||
_ = c.igTableSetColumnIndex(1);
|
||||
c.igSeparator();
|
||||
_ = c.igTableSetColumnIndex(2);
|
||||
c.igSeparator();
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -227,7 +286,7 @@ pub fn winContent(state: *State) !void {
|
|||
},
|
||||
.channels_idx => |idx| {
|
||||
c.glfwHideWindow(state.win);
|
||||
try launch.launchChildren(state, state.channels.?[idx].name);
|
||||
try launch.launchChildren(state, state.channels.?[idx].channel.name);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,10 @@ pub fn reloadLiveThread(s: *State) !void {
|
|||
defer s.mutex.unlock();
|
||||
|
||||
for (s.channels.?) |*chan| {
|
||||
chan.live = .loading;
|
||||
switch (chan.*) {
|
||||
.channel => |*ch| ch.live = .loading,
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,7 +48,9 @@ pub fn fetchChannelsLive(s: *State) !void {
|
|||
// we shouldn't need to aquire the mutex here, this data isnt being read and we're
|
||||
// only doing atomic writes.
|
||||
var fmt_buf: [512]u8 = undefined;
|
||||
for (s.channels.?) |*chan| {
|
||||
for (s.channels.?) |*entry| {
|
||||
const chan = if (entry.* == .channel) &entry.channel else continue;
|
||||
|
||||
page_buf.clearRetainingCapacity();
|
||||
|
||||
log.info("requesting live state for channel {s}", .{chan.name});
|
||||
|
|
Loading…
Add table
Reference in a new issue