thot_core/project/
script_association.rs1use crate::types::ResourceId;
2use std::cmp::{Eq, Ordering, PartialEq, PartialOrd};
3use std::hash::Hash;
4
5#[cfg(feature = "serde")]
6use serde::{Deserialize, Serialize};
7
8#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
17#[derive(Debug, PartialEq, Eq, Hash, Clone)]
18pub struct ScriptAssociation {
19 pub script: ResourceId,
20 pub autorun: bool,
21 pub priority: i32,
22}
23
24impl ScriptAssociation {
25 pub fn new(script: ResourceId) -> Self {
26 ScriptAssociation {
27 script,
28 autorun: true,
29 priority: 0,
30 }
31 }
32}
33
34impl Into<RunParameters> for ScriptAssociation {
35 fn into(self) -> RunParameters {
36 RunParameters {
37 autorun: self.autorun,
38 priority: self.priority,
39 }
40 }
41}
42
43#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
48#[derive(Debug, PartialEq, Eq, Hash, Clone)]
49pub struct RunParameters {
50 pub autorun: bool,
51 pub priority: i32,
52}
53
54impl RunParameters {
55 pub fn new() -> Self {
56 RunParameters {
57 autorun: true,
58 priority: 0,
59 }
60 }
61
62 pub fn to_association(self, script: ResourceId) -> ScriptAssociation {
64 let mut assoc = ScriptAssociation::new(script);
65 assoc.autorun = self.autorun;
66 assoc.priority = self.priority;
67
68 assoc
69 }
70}
71
72impl PartialOrd for RunParameters {
73 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
79 let me = self.priority;
80 let you = other.priority;
81 if me < you {
82 return Some(Ordering::Less);
83 } else if me > you {
84 return Some(Ordering::Greater);
85 } else if self.autorun == other.autorun {
86 return Some(Ordering::Equal);
88 }
89
90 None
93 }
94}
95
96#[cfg(test)]
97#[path = "./script_association_test.rs"]
98mod script_association_test;