diff --git a/README.md b/README.md index c7910c3..e3c4c18 100644 --- a/README.md +++ b/README.md @@ -51,8 +51,6 @@ blueprint rotation? "init_board": null, "inputs": [], "outputs": [0, 0, 0, 0, 0, 0, 0, 0], - "input_is_text": false, - "output_is_text": false } ``` ### solution diff --git a/levels/01_intro/04_copy_input.json b/levels/01_intro/04_copy_input.json index 62da9a1..cf4d266 100644 --- a/levels/01_intro/04_copy_input.json +++ b/levels/01_intro/04_copy_input.json @@ -4,8 +4,6 @@ "name": "Copy Cat", "description": "read input and output the same thing", "init_board": null, - "inputs": [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 103, 33], - "outputs": [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 103, 33], - "input_is_text": true, - "output_is_text": true + "inputs": "Hello, world!", + "outputs": "Hello, world!" } \ No newline at end of file diff --git a/levels/02_lists/null_separation.json b/levels/02_lists/null_separation.json index 143c0d4..ea5280e 100644 --- a/levels/02_lists/null_separation.json +++ b/levels/02_lists/null_separation.json @@ -4,8 +4,6 @@ "name": "Null Separation", "description": "output everything after the first zero in the input data", "init_board": null, - "inputs": [199, 34, 71, 209, 4, 0, 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 103, 33, 0], - "outputs": [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 103, 33], - "input_is_text": true, - "output_is_text": true + "inputs": "9834726\u0000Hello, worlg!", + "outputs": "Hello, worlg!" } \ No newline at end of file diff --git a/levels/02_lists/reverse_input.json b/levels/02_lists/reverse_input.json index ff1fa56..d479e47 100644 --- a/levels/02_lists/reverse_input.json +++ b/levels/02_lists/reverse_input.json @@ -4,8 +4,6 @@ "name": "Reverse", "description": "read input until zero and output the same thing in reverse", "init_board": null, - "inputs": [116, 110, 114, 111, 112, 109, 105, 32, 121, 114, 101, 118, 0], - "outputs": [118, 101, 114, 121, 32, 105, 109, 112, 111, 114, 110, 116], - "input_is_text": true, - "output_is_text": true + "inputs": "tnropmi yrev\u0000", + "outputs": "very impornt" } \ No newline at end of file diff --git a/levels/03_text/ascii_to_lower.json b/levels/03_text/ascii_to_lower.json index d011995..f1d095b 100644 --- a/levels/03_text/ascii_to_lower.json +++ b/levels/03_text/ascii_to_lower.json @@ -4,8 +4,6 @@ "name": "Lowercase", "description": "Convert text to lowercase", "init_board": null, - "inputs": [73, 32, 67, 114, 97, 86, 101, 68, 32, 116, 72, 69, 32, 115, 116, 114, 69, 110, 71, 84, 72, 32, 65, 78, 68, 32, 67, 101, 114, 84, 65, 105, 110, 84, 121, 32, 111, 70, 32, 83, 84, 101, 101, 76], - "outputs": [105, 32, 99, 114, 97, 118, 101, 100, 32, 116, 104, 101, 32, 115, 116, 114, 101, 110, 103, 116, 104, 32, 97, 110, 100, 32, 99, 101, 114, 116, 97, 105, 110, 116, 121, 32, 111, 102, 32, 115, 116, 101, 101, 108], - "input_is_text": true, - "output_is_text": true + "inputs": "I CraVeD tHE strEnGTH AND CerTAinTy oF STeeL", + "outputs": "i craved the strength and certainty of steel" } \ No newline at end of file diff --git a/levels/03_text/output_decimal.json b/levels/03_text/output_decimal.json index cdee987..2f6f794 100644 --- a/levels/03_text/output_decimal.json +++ b/levels/03_text/output_decimal.json @@ -5,7 +5,5 @@ "description": "Convert input numbers to text, separated by spaces (32)\n'0' = 48, '1' = 49, '2' = 50, and so on", "init_board": null, "inputs": [85, 114, 32, 103, 97, 121, 58, 51], - "outputs": [56, 53, 32, 49, 49, 52, 32, 51, 50, 32, 49, 48, 51, 32, 57, 55, 32, 49, 50, 49, 32, 53, 56, 32, 53, 49], - "input_is_text": false, - "output_is_text": true + "outputs": "85 114 32 103 97 121 58 51" } \ No newline at end of file diff --git a/levels/03_text/parse_decimal.json b/levels/03_text/parse_decimal.json index f63eb86..1ccb3d1 100644 --- a/levels/03_text/parse_decimal.json +++ b/levels/03_text/parse_decimal.json @@ -4,8 +4,6 @@ "name": "Numbers 2", "description": "Convert input numbers from text, separated by spaces (32)\n'0' = 48, '1' = 49, '2' = 50, and so on", "init_board": null, - "inputs": [56, 53, 32, 49, 49, 52, 32, 51, 50, 32, 49, 48, 51, 32, 57, 55, 32, 49, 50, 49, 32, 51, 50, 32, 53, 56, 32, 53, 49], - "outputs": [85, 114, 32, 103, 97, 121, 58, 51], - "input_is_text": true, - "output_is_text": false + "inputs": "85 114 32 103 97 121 58 51", + "outputs": [85, 114, 32, 103, 97, 121, 58, 51] } \ No newline at end of file diff --git a/levels/sandbox.json b/levels/sandbox.json index b32b787..d255bf0 100644 --- a/levels/sandbox.json +++ b/levels/sandbox.json @@ -5,7 +5,6 @@ "description": "make whatever you want here", "is_sandbox": true, "init_board": null, - "inputs": [], - "outputs": [], - "input_is_text": true + "inputs": "", + "outputs": [] } \ No newline at end of file diff --git a/src/level.rs b/src/level.rs index 6ef2582..b71551c 100644 --- a/src/level.rs +++ b/src/level.rs @@ -9,12 +9,24 @@ pub struct Level { #[serde(default)] is_sandbox: bool, init_board: Option, - inputs: Vec, - outputs: Vec, - #[serde(default)] - input_is_text: bool, - #[serde(default)] - output_is_text: bool, + inputs: IOData, + outputs: IOData, +} + +#[derive(Debug, Clone, Deserialize)] +#[serde(untagged)] +pub enum IOData { + Bytes(Vec), + Text(String), +} + +impl IOData { + pub fn as_bytes(&self) -> &[u8] { + match self { + IOData::Bytes(b) => b, + IOData::Text(t) => t.as_bytes(), + } + } } impl Level { @@ -43,18 +55,18 @@ impl Level { } pub fn inputs(&self) -> &[u8] { - &self.inputs + self.inputs.as_bytes() } pub fn outputs(&self) -> &[u8] { - &self.outputs + self.outputs.as_bytes() } pub fn input_is_text(&self) -> bool { - self.input_is_text + matches!(self.inputs, IOData::Text(_)) } pub fn output_is_text(&self) -> bool { - self.output_is_text + matches!(self.outputs, IOData::Text(_)) } }