classicube_helpers\tab_list/
entry.rs1#![allow(clippy::used_underscore_binding)]
2
3use std::os::raw::c_int;
4
5use classicube_sys::{StringsBuffer_UNSAFE_Get, TabList};
6
7#[derive(Debug)]
8pub struct TabListEntry {
9 id: u8,
10 name_offset: &'static u16,
11 group_rank: &'static u8,
12}
13
14impl TabListEntry {
15 #[must_use]
23 pub unsafe fn from_id(id: u8) -> Option<Self> {
24 let name_offset = &TabList.NameOffsets[id as usize];
25 let group_rank = &TabList.GroupRanks[id as usize];
26
27 if *name_offset == 0 || *group_rank == 0 || TabList._buffer.count == 0 {
28 return None;
29 }
30
31 Some(Self {
32 id,
33 name_offset,
34 group_rank,
35 })
36 }
37
38 #[must_use]
39 pub fn get_id(&self) -> u8 {
40 self.id
41 }
42
43 pub fn get_real_name(&self) -> String {
45 unsafe {
46 StringsBuffer_UNSAFE_Get(&mut TabList._buffer, c_int::from(*self.name_offset - 3))
47 }
48 .to_string()
49 }
50
51 pub fn get_nick_name(&self) -> String {
53 unsafe {
54 StringsBuffer_UNSAFE_Get(&mut TabList._buffer, c_int::from(*self.name_offset - 2))
55 }
56 .to_string()
57 }
58
59 pub fn get_group(&self) -> String {
60 unsafe {
61 StringsBuffer_UNSAFE_Get(&mut TabList._buffer, c_int::from(*self.name_offset - 1))
62 }
63 .to_string()
64 }
65
66 #[must_use]
67 pub fn get_rank(&self) -> u8 {
68 *self.group_rank
69 }
70}