fable_data/script/
mod.rs

1//! This is module for a scripting syntax shared in several formats.
2
3mod decode;
4mod encode;
5
6pub use decode::*;
7pub use encode::*;
8
9#[derive(Debug,PartialEq)]
10pub enum ScriptExpression {
11    ScriptValue(ScriptValue),
12    ScriptField(ScriptField),
13    ScriptCall(ScriptCall),
14    ScriptMarkup(ScriptMarkup),
15    ScriptComment(ScriptComment),
16    ScriptBinaryOp(ScriptBinaryOp),
17}
18
19/// The named part of calls and fields.
20#[derive(Debug,PartialEq)]
21pub enum ScriptReference {
22    Name(String),
23    ScriptAccessor(ScriptAccessor),
24}
25
26/// A complex reference containing another reference or expression.
27#[derive(Debug,PartialEq)]
28pub struct ScriptAccessor {
29    pub name: String,
30    pub path: Vec<ScriptAccessorPath>,
31}
32
33#[derive(Debug,PartialEq)]
34pub enum ScriptAccessorPath {
35    /// For the syntax `A.B`.
36    Name(String),
37    /// For the syntax `A[B]` and more complex expression.
38    Expression(ScriptExpression),
39}
40
41/// Reference and expression.
42///
43/// Random example:
44///
45/// ```txt
46/// DialogueLayers[DIALOGUE_LAYER_BACKGROUND].ResponseTimeSecsAttack		4.0;
47/// ```
48#[derive(Debug,PartialEq)]
49pub struct ScriptField {
50    pub reference: ScriptReference,
51    pub value: Box<ScriptExpression>,
52}
53
54/// A value.
55#[derive(Debug,PartialEq)]
56pub enum ScriptValue {
57    /// A plaintext string such as `MESH_OBJECT_POINTER`.
58    Name(String),
59    BoolLiteral(bool),
60    IntegerLiteral(i32),
61    /// A big integer for 64-bit ids.
62    BigIntegerLiteral(u64),
63    FloatLiteral(f32),
64    StringLiteral(String),
65}
66
67/// A call.
68///
69/// Random example:
70///
71/// ```txt
72/// PermittedAINarrators.Add("AF3_1_5");
73/// ```
74#[derive(Debug,PartialEq)]
75pub struct ScriptCall {
76    pub reference: ScriptReference,
77    pub arguments: Vec<ScriptExpression>
78}
79
80/// XML-like markup (but not real XML).
81///
82/// Random example:
83///
84/// ```txt
85/// <CHeroMarriageDef>
86///	    //marriage event
87///     WeddingTimeForScreenToFadeOut       4.0;
88///     WeddingTimeForScreenToFadeIn        3.0;
89///     ...
90/// <\CHeroMarriageDef>
91/// ```
92#[derive(Debug,PartialEq)]
93pub struct ScriptMarkup {
94    pub name: String,
95    pub body: Vec<ScriptExpression>
96}
97
98/// A line or block comment.
99#[derive(Debug,PartialEq)]
100pub enum ScriptComment {
101    Block(String),
102    Line(String),
103}
104
105/// A binary operation.
106#[derive(Debug,PartialEq)]
107pub struct ScriptBinaryOp {
108    pub kind: ScriptBinaryOpKind,
109    pub lhs: Box<ScriptExpression>,
110    pub rhs: Box<ScriptExpression>,
111}
112
113#[derive(Debug,PartialEq)]
114pub enum ScriptBinaryOpKind {
115    Add,
116    Subtract,
117    Multiply,
118    Divide,
119    BitOr,
120    // TODO more?
121}