cobble_core/minecraft/models/
rule.rs1use crate::utils::{Architecture, Platform};
2use serde::{Deserialize, Serialize};
3
4#[derive(Clone, Debug, Deserialize, Serialize)]
6pub struct Rule {
7 pub action: RuleAction,
9 pub os: Option<RuleOs>,
11 pub features: Option<RuleFeatures>,
13}
14
15impl Rule {
16 pub fn allows(&self) -> bool {
18 if let Some(os) = &self.os {
19 if let Some(platform) = &os.platform {
20 if platform != &Platform::current() {
21 return !self.action.to_bool();
22 }
23 }
24 }
25
26 if let Some(features) = &self.features {
27 if features.is_demo_user.is_some() || features.has_custom_resolution.is_some() {
28 return false;
29 }
30 }
31
32 self.action.to_bool()
33 }
34}
35
36#[derive(Clone, Debug, Deserialize, Serialize)]
38pub enum RuleAction {
39 #[serde(alias = "allow")]
41 Allow,
42 #[serde(alias = "disallow")]
44 Disallow,
45}
46
47impl RuleAction {
48 pub fn to_bool(&self) -> bool {
50 match self {
51 RuleAction::Allow => true,
52 RuleAction::Disallow => false,
53 }
54 }
55}
56
57#[derive(Clone, Debug, Deserialize, Serialize)]
59pub struct RuleOs {
60 #[serde(alias = "name")]
62 pub platform: Option<Platform>,
63 pub version: Option<String>,
65 pub arch: Option<Architecture>,
67}
68
69#[derive(Clone, Debug, Deserialize, Serialize)]
71pub struct RuleFeatures {
72 pub is_demo_user: Option<bool>,
74 pub has_custom_resolution: Option<bool>,
76}