From 86044397b8fac9298295cc22b40413d8f37025e3 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 11 Jun 2020 15:04:32 +0200 Subject: Added history with csv file parsing and writing --- Cargo.lock | 143 +++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 4 +- history.csv | 185 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/history.rs | 77 +++++++++++++++++++++++ src/main.rs | 32 +++++++--- src/scramble.rs | 133 ++++++++++++++++++++++++++++++++++++++++ src/shuffle.rs | 102 ------------------------------- src/text.rs | 51 +++++++++++----- 8 files changed, 600 insertions(+), 127 deletions(-) create mode 100644 history.csv create mode 100644 src/history.rs create mode 100644 src/scramble.rs delete mode 100644 src/shuffle.rs diff --git a/Cargo.lock b/Cargo.lock index 1cbd525..a4ca6e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,17 +1,74 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "autocfg" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" + [[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "bstr" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31accafdb70df7871592c058eca3985b71104e15ac32f64706022c58867da931" +dependencies = [ + "lazy_static", + "memchr", + "regex-automata", + "serde", +] + +[[package]] +name = "byteorder" +version = "1.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" + [[package]] name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +[[package]] +name = "chrono" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2" +dependencies = [ + "num-integer", + "num-traits", + "time", +] + +[[package]] +name = "csv" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00affe7f6ab566df61b4be3ce8cf16bc2576bca0963ceb0955e45d514bf9a279" +dependencies = [ + "bstr", + "csv-core", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "csv-core" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" +dependencies = [ + "memchr", +] + [[package]] name = "getrandom" version = "0.1.14" @@ -23,6 +80,12 @@ dependencies = [ "wasi", ] +[[package]] +name = "itoa" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e" + [[package]] name = "lazy_static" version = "1.4.0" @@ -35,6 +98,31 @@ version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" +[[package]] +name = "memchr" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" + +[[package]] +name = "num-integer" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" +dependencies = [ + "autocfg", +] + [[package]] name = "ppv-lite86" version = "0.2.8" @@ -82,14 +170,31 @@ dependencies = [ "rand_core", ] +[[package]] +name = "regex-automata" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" +dependencies = [ + "byteorder", +] + [[package]] name = "rutikmer" version = "0.1.0" dependencies = [ + "chrono", + "csv", "rand", "sdl2", ] +[[package]] +name = "ryu" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + [[package]] name = "sdl2" version = "0.34.1" @@ -112,8 +217,46 @@ dependencies = [ "libc", ] +[[package]] +name = "serde" +version = "1.0.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9124df5b40cbd380080b2cc6ab894c040a3070d995f5c9dc77e18c34a8ae37d" + +[[package]] +name = "time" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "winapi" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index beaf7e9..70bc74a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,9 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -rand = "*" +rand = "0.7" +csv = "1.1" +chrono = "0.4" [dependencies.sdl2] version = "0.34.0" diff --git a/history.csv b/history.csv new file mode 100644 index 0000000..31a42e9 --- /dev/null +++ b/history.csv @@ -0,0 +1,185 @@ +"time","scramble","date" +01:28.150,B2 F2 U2 R F2 D2 U2 R U2 L R B L R2 B' F2 D L2 F,2020-01-26 19:45:00 UTC +01:17.984,L D B R D' F2 L' D' R' B' D' R' L' U2 F2 L2 F2 R',2020-01-26 19:48:00 UTC +01:42.880,F' D2 B' U2 L2 D2 L2 B U2 F' D' B U B' F' R D2 B' F,2020-01-26 19:51:00 UTC +01:26.715,B2 R2 U2 B2 F L2 B R' B2 D R2 U F' R' U B R2 D2,2020-01-26 19:54:00 UTC +01:22.957,U F B2 U' F D2 R2 F U L U D2 B' L2 F L2 U2 B L2 B2,2020-01-26 19:57:00 UTC +01:34.325,F' B2 R2 D R B L D' R' F' B2 U2 R2 L F2 B2 U2 R' U2 D2 R,2020-01-27 13:20:00 UTC +01:13.972,D R2 U' B2 U L2 D2 R2 B2 U' L B2 F' D2 R B' F' U2 R2,2020-01-27 13:22:00 UTC +01:01.356,R2 U2 F' L' B' R U2 D R' F2 U F2 D2 B2 R2 F' D2 F D2,2020-01-27 13:24:00 UTC +01:12.776,L2 D B2 L2 D L2 R2 F2 U' L' F' D' B2 F' L2 R' U2 F L2 R2,2020-01-27 13:27:00 UTC +01:31.701,U2 L2 D2 B2 F2 R' D2 B2 R U F2 L B F L2 D' B' L' R2 F2,2020-01-27 13:30:00 UTC +01:17.747,U2 R' B2 R U2 R B2 U2 L' F2 L' F' U' R2 B D' L F' L' F',2020-01-27 13:35:00 UTC +01:28.785,F2 U' B2 D' U2 R' D2 U L' U B2 L' F' U B' R',2020-01-27 13:38:00 UTC +01:29.039,L2 B2 L2 D F2 U F D' B' F' R F U B F2 L F2 R2,2020-01-27 13:40:00 UTC +01:15.588,U' F B' U' B2 L2 U2 B' U' R D2 F L2 F B' D2 B R2 F,2020-01-27 19:26:00 UTC +01:10.315,B' U2 R L U2 B U' B2 R L' U R2 B2 D2 F D2 R2 F' D2 B2,2020-01-27 19:28:00 UTC +01:08.152,B2 D2 F2 D L2 D R2 U B2 U2 B D' R' F2 L' R' F2 D L' U,2020-01-27 19:31:00 UTC +01:18.437,B2 L' F2 L R U2 L U2 B2 R U B2 L2 R' U R' F' L' R',2020-01-27 19:33:00 UTC +01:15.958,F R' B D2 R D' R2 D2 L F' R2 D2 B2 U2 F2 R D2 R B2 L,2020-01-27 19:36:00 UTC +01:55.957,R' D2 L2 U2 L' B2 R B2 D2 B2 R D' L R F' L' D2 B U F U',2020-01-27 19:39:00 UTC +01:17.396,D R2 L F' L' U2 F2 U' B U B2 R2 B2 U2 R' L' B2 L D2,2020-01-27 19:41:00 UTC +01:14.593,D2 B D2 U2 B' U2 B2 L' B2 L2 D2 U2 L U2 L B' F2 D',2020-01-27 19:47:00 UTC +01:40.291,R' B2 L' B2 L B2 D2 R' B2 R U L U2 B' D' F U2 B F,2020-01-27 19:49:00 UTC +01:24.929,D F2 D R B2 D2 B' L D' F B2 U' D' R2 B2 D' B2 U' F2 U',2020-01-27 19:52:00 UTC +01:46.806,D F2 B' R' F L2 B2 R D2 B2 R' B' U2 L2 F2 R2 L2,2020-01-27 19:55:00 UTC +00:49.620,D B R2 U' R F U D2 L' U2 F' D' B2 U L2 B2 D2 R2 B2,2020-01-28 17:09:00 UTC +01:36.401,U D' F' B' U2 B' L F U' B' D2 B2 D2 L2 D2 R2 B' R2 L2,2020-01-28 17:12:00 UTC +01:52.379,U2 R' U' D' B2 U' F D F2 D' L' F U2 D2 B U2 F D2,2020-01-28 19:35:00 UTC +01:34.013,R' B2 R' U2 L B2 L' D2 F' D B L2 D2 L2 U' F2 L2 D B,2020-06-06 08:20:00 UTC +01:30.943,F2 R' F2 L R2 B2 L B R U B2 L2 F2 R B2 U' L2 B',2020-06-06 08:22:00 UTC +01:46.924,D2 L B2 F2 R F2 D2 L' B2 L' U R' B' U2 L B' D' R D2 U',2020-06-06 08:26:00 UTC +01:54.817,L2 B' D2 R2 B2 F L2 B R' D2 B2 D2 L2 D L2 R2 B2 L B',2020-06-06 08:28:00 UTC +01:19.208,D2 L2 R2 D L2 U L2 B2 D2 R' B2 D2 F2 R U' R2 U B F' U,2020-06-06 08:31:00 UTC +01:24.686,D' L2 U B2 D2 U B2 D2 L2 F' D B' U B2 U2 L B' U' F2 R,2020-06-06 09:48:00 UTC +01:30.343,B' L F' L2 U R' U D L' B2 D' B' R2 B' D2 B' U2 F L2,2020-06-06 09:50:00 UTC +01:23.028,F R2 B2 L2 B R2 U2 B R' D' B2 L' B' F' R B' U' R2 U,2020-06-06 09:53:00 UTC +01:40.421,F2 R2 F2 R F2 R' D2 B2 F D B' U' L' F2 L R2 D' L B',2020-06-06 10:09:00 UTC +01:20.059,D B2 F2 L2 U' F2 D' F R2 D R2 D2 F R' D U B' F' U2,2020-06-06 10:11:00 UTC +01:23.321,R2 F2 U B2 R2 U' F2 L2 U L B D F R' F' D U2 F2 L2,2020-06-06 10:13:00 UTC +01:16.911,R2 U' F L D2 R2 D R' U2 F' D B' L2 U2 R2 B2 L2 F R2,2020-06-06 10:19:00 UTC +01:41.131,F2 U2 L' B2 U2 L' R' B2 U2 L F L U2 B F2 U R D L' U2,2020-06-06 10:22:00 UTC +01:18.559,L2 B2 D F2 D B2 R2 D' L B D R2 B R' B R2 D2 L R',2020-06-06 10:26:00 UTC +01:32.152,L2 U' R' B' L F' L B' U' L' U' R F2 R' U2 L2 F2 U2 D2,2020-06-06 10:29:00 UTC +01:12.490,R D B U' R F' B2 R' U2 L F R2 D2 F D2 L2 B2 L2 B U2,2020-06-06 10:42:00 UTC +01:17.310,R2 B2 L2 R' F2 L F2 D' R2 U F' D2 R U B' U' L F,2020-06-06 10:45:00 UTC +01:09.190,R2 U R2 D U L2 F2 U' L' D' B' F' U L R' D' F2 U2 L,2020-06-06 10:50:00 UTC +01:32.847,L2 F' D2 L2 U2 L2 B D2 L B' L2 B2 U B' U' B' D2 L' F',2020-06-06 10:54:00 UTC +01:45.350,U2 L F2 R2 U2 B2 R' U2 B2 U2 R B F' R F U' B U F2 D F',2020-06-06 10:57:00 UTC +01:14.666,B' D2 F' L U F D F2 U' F2 R2 F2 D2 R U2 F2 D2 F2 L2 U2,2020-06-06 11:04:00 UTC +01:18.926,L U2 B2 L2 U2 L R' D B L' B2 R' F' D F' R' B' F',2020-06-06 11:06:00 UTC +01:09.400,B' U' F2 R U' B' D L2 U F L D2 F' R2 D2 F' R2 F2,2020-06-06 11:09:00 UTC +01:32.217,R2 F2 R' D2 L' R2 B2 R F2 D' L' U2 B F2 D U2 R U' L2 F',2020-06-06 11:12:00 UTC +01:11.135,U2 R2 D2 B F2 D2 F2 R2 U2 L' U L' R2 U F' D2 U R F2 U,2020-06-06 11:22:00 UTC +01:13.378,D R' F' L' U2 R D R2 B' U' F2 R2 F' L2 F R2 U2 R2 F' L2 B',2020-06-06 14:52:00 UTC +01:20.230,F' R F2 B2 L U' F B L F' U2 R' D2 R2 L D2 R' F2 D2 L,2020-06-06 15:01:00 UTC +00:52.911,L2 B' L2 D2 U2 B2 D2 R2 B' L' F' R' U' R' D F' L2 F D2,2020-06-06 15:03:00 UTC +01:14.312,R2 U F2 R2 F2 D' L2 D B2 F2 L F U2 B' D2 L' B' U' R2 F2,2020-06-06 15:05:00 UTC +01:28.680,R2 L2 B2 U2 R B U' F' U' L' F' U2 B' R2 B' R2 U2 F',2020-06-06 15:07:00 UTC +01:16.099,U2 L2 D L2 R2 U' F2 D U2 L2 R' F2 U F' U2 F D R' D,2020-06-06 15:09:00 UTC +01:05.052,D2 R' U' L D' L2 B R F' U D2 B2 L' D2 R U2 R2 U2 R2 L',2020-06-06 15:18:00 UTC +00:55.287,F' L2 B' U2 B' R2 D2 R2 D R F L2 R2 F' U' L2 U' L' F2,2020-06-06 15:20:00 UTC +01:00.243,B2 F' L2 F' R2 F' D2 R2 U L' R U L' D' F' U R2 D2 B',2020-06-06 15:26:00 UTC +01:36.968,L2 B U2 R U D L U' B2 R' F B2 D L2 B2 U' L2 D2,2020-06-06 15:29:00 UTC +01:11.255,D2 L F2 L F2 R U2 L B2 D L' D' B L2 D' U2 L2 D2 L,2020-06-06 15:31:00 UTC +00:56.809,B2 R' U2 D' F D' B2 D B2 U F2 D2 L2 B R2 F' U2 B,2020-06-06 15:33:00 UTC +00:58.990,F2 D' U B2 D' F2 R2 U2 R F' L' D F U2 B R B' F L2,2020-06-06 15:40:00 UTC +01:11.496,R2 L D' B' R2 L U2 R' F D2 L D2 R F2 D2 L' D2 R2 U2,2020-06-06 15:43:00 UTC +01:06.716,D' R2 D B' U' B2 L' F' U' L U2 B' U2 F2 U2 L2 F2 R2 F,2020-06-06 15:49:00 UTC +01:37.412,D U2 F2 D R2 D2 L2 U' R2 B' R2 D F U2 F L2 R' D L,2020-06-06 15:54:00 UTC +01:05.318,F2 D2 R2 B L2 B2 U2 F' U2 F L F D U2 L D L R' U2 F',2020-06-06 15:56:00 UTC +01:11.337,F' B2 R2 D R B L D' R' F' B2 U2 R2 L F2 B2 U2 R' U2 D2 R,2020-06-06 18:02:00 UTC +01:07.539,D R F D2 B' L2 D' R2 U' D2 L2 D2 F B2 L2 B' U2 L2 F' D2,2020-06-06 18:04:00 UTC +01:29.990,R2 B R2 F D2 L2 F2 R2 F' R' B' R B' R' F2 D' F U2 F2,2020-06-06 18:06:00 UTC +01:14.217,U2 R' B2 F2 U2 B2 R D2 L D B F D B U B' L' B2 L' R,2020-06-06 18:08:00 UTC +01:08.298,U' R2 B2 U2 F2 U2 F2 U R' D L2 B2 U' B2 L' R2 U B F,2020-06-06 18:10:00 UTC +01:10.385,B' F D2 U2 L2 F U2 F' U2 L D L D' F' U2 F2 U B L' B',2020-06-06 18:12:00 UTC +01:17.034,U' F2 U B2 F2 D F2 D' U2 R' B R2 D U F2 L F2 L2 F L2,2020-06-06 18:15:00 UTC +01:10.721,D2 B2 R2 U2 F2 L F2 L2 F2 R' B2 D' R D F' R2 D R B U2,2020-06-06 18:18:00 UTC +01:16.897,U2 R F2 L F2 U2 F2 R D' B' L' F' U F2 D' B2 L' U',2020-06-06 18:20:00 UTC +01:24.549,D2 B U' L' B' R B2 U B' U R2 D2 R2 U B2 D R2 D' R2 U2,2020-06-06 18:22:00 UTC +01:19.579,R2 F2 U' R2 B2 U' F' D' B R' U' F2 U B2 R' U B U2,2020-06-06 18:24:00 UTC +01:14.921,B2 D2 R2 F U2 F' R2 F U2 B' L' D2 U' B2 U' B' R2 F2 U,2020-06-06 18:26:00 UTC +01:08.835,U L2 D R U2 F L' U2 R2 B D' F2 R2 F2 R2 U2 B' L2 F',2020-06-06 18:28:00 UTC +01:27.298,B' F2 R2 B' R2 U2 R2 D2 L' F' U B D F2 D' U R U2 F2,2020-06-06 18:31:00 UTC +01:06.617,D2 B U2 L2 D2 F L2 F' R2 B2 U' R2 B' U F L' U R2 B' U2,2020-06-06 18:33:00 UTC +01:16.597,D2 R2 D L2 R2 D2 R2 F2 D U2 L' B' U2 F2 L B2 U2 R' B2 U,2020-06-06 18:35:00 UTC +01:19.533,U2 B' F2 R2 F D2 F2 D2 L2 U' L B' D' U' B L F2 U2 B' R,2020-06-06 18:40:00 UTC +01:15.978,U2 F U2 L2 B2 D2 F U2 L' B' R2 D U' L B' R' D2 U2 F',2020-06-06 19:01:00 UTC +01:05.044,B2 R' D2 F U F2 D2 F B2 U R' U2 F2 L D2 L' U2,2020-06-06 19:06:00 UTC +01:23.006,D2 R2 D' F2 D2 L2 U' L2 B U2 F' D2 B L2 D' R2 D' R U',2020-06-06 19:11:00 UTC +01:16.633,F' U2 B2 F R2 U2 F' R2 U2 L' B2 R' U B' L2 D2 L,2020-06-06 20:17:00 UTC +01:08.173,D2 R2 U' F2 R2 U' L2 U R2 D R F' L F U' F R B2 R' U,2020-06-06 20:19:00 UTC +01:05.897,R' L2 U' R F' B2 D L2 D R F B2 R2 U L2 U R2 F2 U,2020-06-06 20:21:00 UTC +01:13.100,D2 R2 D' B2 R2 U' R2 D L2 R' U2 B2 R' F U' F' D F2 U2,2020-06-06 20:24:00 UTC +00:52.938,R' B2 L' D' B' D' R U2 B L' B R2 L2 F2 R2 D2 F' U2 F2,2020-06-06 20:26:00 UTC +00:57.683,F2 R2 F2 R U2 R2 B2 D2 R' F' L U2 B U2 R F2 U' B R D',2020-06-06 20:28:00 UTC +00:58.341,R2 B' U' F2 U2 R B' D B' U' F U D B2 L2 U L2 D2,2020-06-06 20:31:00 UTC +01:27.513,L2 B' L2 R2 B2 L2 B' D L2 D' F2 L' R' D' B2 F2 L F',2020-06-06 20:34:00 UTC +01:23.341,U L2 D' B2 F2 D' L2 F' D B2 D2 R2 U' B L R B' F,2020-06-06 20:37:00 UTC +01:17.929,B2 F2 L' B2 L' U2 L' D2 R B F2 U' B D2 L D2 F2 L' B,2020-06-06 20:39:00 UTC +01:08.415,R2 B2 U2 B' R2 B D2 F R2 F D' R B2 U2 B' F' L B2 L B,2020-06-06 23:11:00 UTC +01:30.395,B2 R2 D B2 D R2 U' F2 U' F2 L R' U' F' L' B' D F L2 D',2020-06-06 23:14:00 UTC +01:11.949,R' B2 D2 F2 R B2 R B2 D2 B2 R U' R F D' U' L2 D2 U' F',2020-06-06 23:16:00 UTC +01:06.178,B F' U2 R2 U2 F' L2 F' U2 F2 R' B' L2 D F2 L U B2 U2 F,2020-06-06 23:18:00 UTC +01:17.502,U' R' F U' F2 R' D F' U' F2 U' L2 B2 R2 D2 R2 B L2,2020-06-06 23:21:00 UTC +01:04.379,F2 U' F2 U R2 U2 F2 L2 U L' U2 L' F L2 F' D' F2 U R',2020-06-08 15:01:00 UTC +01:27.072,F2 L2 U' L2 D L2 B2 F U2 F' D' B2 D' B' R' B' L B2,2020-06-08 15:03:00 UTC +01:24.714,B2 L2 B2 R2 U' L2 D' R2 U B' L' F' D2 B U L2 D' B L R2,2020-06-08 15:05:00 UTC +01:14.662,R' U2 L' B2 L R2 B2 R U B R D2 U R' B2 R2 U' L R,2020-06-08 15:14:00 UTC +01:06.806,R L' B R' B2 D2 B' L' U F2 L D' F2 U' B2 R2 B2 L2 D2,2020-06-08 15:16:00 UTC +01:11.024,B2 D2 B U F L F B2 R2 D' F2 L2 F' D2 F R2 F2 L2 B2,2020-06-08 15:23:00 UTC +01:06.451,U2 F2 D R2 D' L2 U2 B2 R F' L2 D' U' L' B' R' F2 D L R2,2020-06-08 15:25:00 UTC +01:10.899,F B R' U2 D2 B' D L2 B' R' D' R2 F2 U R2 F2 U' F2 D,2020-06-08 15:27:00 UTC +01:20.198,F2 U2 L' U2 R B2 D2 R' D2 R2 B U L' D U' B2 F' L F2 U',2020-06-08 17:51:00 UTC +01:16.965,D2 F' B U' B2 R F D B2 U2 F' U' B2 U' D F2 L2 U F2,2020-06-08 17:53:00 UTC +01:00.136,R' F2 L2 R' D2 L' D2 R' B2 F' U' F U' L F2 R D2 U R',2020-06-08 17:55:00 UTC +01:11.063,B2 L' F2 U' B R2 F U D' L F' B2 U F2 D' B2 D R2 U D,2020-06-08 17:57:00 UTC +01:10.443,B2 F2 L2 U' L2 D L2 B2 R2 U' R' B F D2 L2 D L' D U L' R2,2020-06-08 17:59:00 UTC +01:09.944,D' B' U' L' F2 L D' R' U2 F' B R' L2 U2 R F2 D2 F2 L' U2,2020-06-08 18:01:00 UTC +01:12.392,F L U' L' D L B U D2 F' R F' L2 F L2 B2 D2 F' R2,2020-06-08 18:05:00 UTC +01:12.683,B2 R' U' R' B2 R L' B D F' L U2 L2 U R2 F2 B2 D',2020-06-08 18:07:00 UTC +01:03.398,F L U2 F L F U' D' R L B R L2 U2 B2 L' U2 D2 F2,2020-06-08 18:08:00 UTC +01:10.289,F2 R F2 L' B2 R2 B2 L' U2 L' D L' B2 F' U' L2 D2 L B' D2,2020-06-08 18:11:00 UTC +01:12.829,D' F2 D' L2 B2 R2 F2 L' U2 R2 D' F' D' B L D' L R' U,2020-06-08 18:13:00 UTC +01:24.027,R' D R' U R' L' B2 D L F' R' D2 F' R2 F' D2 B' R2 D2,2020-06-08 18:15:00 UTC +00:48.946,R2 D' L2 U R2 U' B2 R2 D2 R D B L' F' R2 U' R' B' D' B',2020-06-08 18:16:00 UTC +00:55.830,L2 B' R2 B2 R2 D2 F' R2 D2 R' B2 U2 R2 F D L' U R F2,2020-06-08 18:21:00 UTC +01:07.010,R2 L2 B' L D2 B' L' F2 L B2 D2 F2 U F2 R2 F2 D B2 U' L2,2020-06-08 18:26:00 UTC +01:10.850,L U' B U F2 L U R' D F U2 B L2 F2 B D2 B R2 B,2020-06-08 18:28:00 UTC +01:08.909,L2 B2 R2 B L2 D2 F2 U2 B D' R' D2 L R' U L' B' U L',2020-06-08 18:30:00 UTC +00:57.577,B R' F L F U L F2 D' R' L2 B U2 F' U2 L2 F' L2,2020-06-08 18:31:00 UTC +01:01.914,F2 D2 L2 D2 B D2 L2 B F U2 F U L2 F D2 R D' U2 B2 U L',2020-06-08 18:34:00 UTC +01:08.443,B2 L2 F' D2 U2 B2 F' R2 U2 L D R F R' U' F R2 D2 B F2,2020-06-08 18:36:00 UTC +00:46.684,F U D2 R' U D R2 U L' B' R F B2 D2 L2 F' U2 D2 B2,2020-06-08 18:40:00 UTC +00:58.111,L B D' L2 D' B2 R2 F B' D' L' F2 B2 L' B2 D2 B2 D2 R2,2020-06-08 18:44:00 UTC +01:07.649,B2 F2 R2 F2 U2 B2 D' U' B' D2 L' D U' B' L2 U' F R U,2020-06-08 18:56:00 UTC +01:10.236,F2 U2 R D2 L' B2 D2 L D2 R2 F' U' R F' D2 R D' F2 R U,2020-06-08 20:04:00 UTC +00:40.121,L U L' B' D2 F' R U B U' R' L2 B2 R2 U2 F' B' L2 F,2020-06-08 20:05:00 UTC +01:11.069,U R2 U' L2 F2 L2 D L2 F2 U' L F' D' F R' F2 D B D2 F2,2020-06-08 20:08:00 UTC +01:16.818,D2 B2 D' B' L' F' U' F' D' R' F' L2 U2 D B2 L2 D2 F2 L2,2020-06-08 20:10:00 UTC +01:12.734,D' B2 U L' U' L' D F' U2 F U L2 U L2 F2 U' B2 D',2020-06-08 20:12:00 UTC +01:16.127,R2 B D2 F D2 B R2 U2 F D2 R2 D B2 D2 U' L' F' D2 R' U2 L',2020-06-08 20:14:00 UTC +00:51.849,U' F2 D' R' B2 R2 U B D' R2 D' R U2 D2 B2 R B2 D2 R F2,2020-06-08 20:16:00 UTC +00:59.531,F' L F U' D' B' R' F L' B' R2 F2 B2 U' F2 U2 R2 U2 L2,2020-06-08 20:18:00 UTC +00:43.472,B R U2 L D L2 D' L2 F R2 B2 U' D2 R2 D F2 L2 F2 L2,2020-06-08 20:19:00 UTC +00:58.809,F2 R2 U2 R2 F2 U' B2 R2 F2 L2 R B2 L' B' D' L' F2 R D2 L',2020-06-08 20:21:00 UTC +01:00.136,R2 U' R L D2 L2 B U2 F B2 D R F2 U2 L B2 R' U2 L',2020-06-08 20:23:00 UTC +01:00.952,F2 U2 B2 D2 R2 U2 R2 F2 U R B2 F R' B U2 R' U' B2 U2 L2,2020-06-08 20:25:00 UTC +00:54.914,R' D' R' U2 F' L B2 D' B' D2 B L B2 L F2 U2 L2 U2 L2,2020-06-08 20:27:00 UTC +01:05.158,R2 D2 U2 B' L2 F' R2 U' B2 L D B' U2 L' D' B',2020-06-08 20:29:00 UTC +01:02.667,R' U' D2 B R L' U2 R' F' R U R L' U2 D2 R' U2 F2 B2 U2,2020-06-08 20:31:00 UTC +00:58.438,F2 R' U2 F2 D2 B' U2 R' U' F2 U2 R2 F2 L2 F D2 B U2 L2,2020-06-08 20:33:00 UTC +01:08.240,B U' L' B L F' U' D2 L F R' D2 F R2 F2 R2 L2 F' R2,2020-06-08 20:35:00 UTC +01:13.318,B2 L D2 B2 L2 F2 L' B2 D2 L' U2 F' L F D B R B2 R2 B',2020-06-08 20:36:00 UTC +01:09.721,L2 D B2 L2 D L2 D U B2 F' L2 U' B' U' F L R' D B2 R2,2020-06-08 20:38:00 UTC +01:03.300,B2 L2 U R2 U2 R2 D2 F2 L F R' D2 R' D2 R' D L B U',2020-06-08 20:40:00 UTC +01:01.176,D2 F' L2 R2 F U2 F' L2 R' U F' U B D' B' D2 F U' L2,2020-06-08 20:42:00 UTC +01:09.189,R2 D' F2 U2 R2 U' F2 D2 F2 L D R2 U' L R B F L' B D,2020-06-08 20:43:00 UTC +01:08.249,D F D2 R2 U L' D2 F' B2 L' B2 D2 F L2 F2 D2 F R2 L2,2020-06-08 20:45:00 UTC +00:54.420,L2 F2 R' B2 F2 R' B2 L U R F' D' L B' F' L R F,2020-06-08 20:47:00 UTC +01:09.228,B' R' B' D' L F R F2 L2 F L' D2 R2 D B2 D R2 B2 U2,2020-06-08 22:00:00 UTC +01:09.820,R B' D R2 D' R U2 B' U B2 L' D2 L F2 R U2 D2 R2 L,2020-06-08 22:02:00 UTC +01:06.175,D' R2 U' L2 D U' B F L F' D' R2 B' D F R' D F2,2020-06-08 22:04:00 UTC +01:01.439,R2 F2 L2 D2 U' L2 D2 L D2 B' U2 R' U2 B' F D' L2 B' F2,2020-06-08 22:06:00 UTC +01:06.063,D2 B2 U' L2 F2 L2 D R2 B' U L' B D R F' D L2 U' F2 R,2020-06-08 22:08:00 UTC +00:49.902,F' D' B2 R U B D' B2 D R2 F2 L2 B R2 L2 F U2 B' R2 B,2020-06-08 22:09:00 UTC +01:06.925,F2 R L2 U' B U R D' F2 U' B' L2 F2 D B2 U2 R2 L2 U',2020-06-08 22:11:00 UTC +01:06.046,R F2 R2 D2 B2 R D2 F2 U2 F L F' D U2 B F D L' B' U',2020-06-08 22:13:00 UTC +01:07.975,L2 F L2 B L2 B' U2 L2 U' F2 D' F L2 F L2 D2 L' B L,2020-06-08 22:16:00 UTC +00:53.062,U2 L' D2 L R F2 D2 F2 R' D' B' D' U' B D2 L' D L2 B,2020-06-08 22:18:00 UTC +01:02.829,B2 L' F' U L' F U2 B2 L' U2 B D F2 L2 U2 R2 L2 F2 D2,2020-06-08 22:19:00 UTC +00:55.224,R' D L2 D' B' D2 R U L U2 B' R2 L2 U2 B2 D F2 U' L2 B2,2020-06-09 08:50:00 UTC +00:50.563,L U F L F2 L2 D R D B L2 U2 F2 L' U2 R F2 R' D2 B2,2020-06-09 08:51:00 UTC +00:59.932,F2 R' F2 R2 D2 L' U2 B D' B2 F' U' B2 D' F2 U B2 L,2020-06-09 08:53:00 UTC +00:55.561,R' D L' B' U B R' B' L B U2 L2 F2 U2 R2 D' L2 U R2 L2 D',2020-06-09 08:55:00 UTC +00:59.417,R2 B' R2 B2 L D F2 U2 F R' L2 B2 U2 F2 D' B2 U R2 F2,2020-06-09 08:56:00 UTC +00:58.197,U2 F2 B' R' D L D B' U2 F' D' L2 F2 L2 F2 U2 B2 U2 L' U2,2020-06-09 08:58:00 UTC +00:52.910,D2 L2 F2 L2 F2 D U2 F2 D B2 F U2 F' R D2 B' F U R' F',2020-06-09 09:03:00 UTC +01:09.769,R D2 F' D' F2 L B' R' U2 F D' F2 D2 R2 F2 R2 D' R2 L2 F2,2020-06-09 15:03:00 UTC +01:00.355,L2 F2 D' F2 U' B2 D U B2 L2 R U2 F' U' B' F' R' B' L',2020-06-09 15:05:00 UTC +00:52.638,D R2 L' U2 B R D' R F U2 F L2 U2 B2 U' B2 U2 B2,2020-06-09 15:07:00 UTC +01:20.682,F L2 U2 L2 R2 B2 L2 B' U2 L R U R' D2 F D R2 F' R' B,2020-06-09 15:09:00 UTC +00:56.581,L U' B' U D R' L F R2 B D' R2 U' R2 B2 U' D2 R2 D2 B2,2020-06-09 15:11:00 UTC +01:10.222,D' B2 U2 L' F2 B' U B' R2 B' U' R2 F' U2 R2 B2 D2 R2 F2,2020-06-09 15:13:00 UTC +01:15.929,F2 L2 D' F2 R2 B2 L2 D R2 D2 B U L' U2 R F' R2 D' L2 F,2020-06-09 15:16:00 UTC diff --git a/src/history.rs b/src/history.rs new file mode 100644 index 0000000..6b02b85 --- /dev/null +++ b/src/history.rs @@ -0,0 +1,77 @@ +use std::time::Duration; +use std::str; +use std::num; +use std::fmt; + +use csv; +use chrono; +use chrono::prelude::*; + +use super::scramble::Scramble; + + +pub struct SolveTime(Duration); + +impl str::FromStr for SolveTime { + type Err = num::ParseIntError; + // fmt: mm:ss.lll (l = millisecond) + fn from_str(s: &str) -> Result { + let minute: u64 = s[..2].parse()?; + let second: u64 = s[3..5].parse()?; + let millis: u64 = s[6..].parse()?; + Ok(SolveTime(Duration::from_secs(minute * 60_u64 + second) + Duration::from_millis(millis))) + } +} + +impl fmt::Display for SolveTime { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{:0>2}:{:0>2}.{:0>3}", + self.0.as_secs() / 60, + self.0.as_secs() % 60, + self.0.as_millis() % 1000) + } +} + +struct Entry { + time: SolveTime, + scramble: Scramble, + date: chrono::DateTime, +} + +pub struct History(Vec); + +const VEC_START_SIZE: usize = 200; + +impl History { + pub fn from_csv(file_path: &str) -> History { + let mut history = History(Vec::with_capacity(VEC_START_SIZE)); + let mut reader = csv::Reader::from_path(file_path).unwrap(); + for result in reader.records() { + if let Ok(record) = result { + history.0.push(Entry{ + time: record[0].parse::().unwrap(), + scramble: record[1].parse::().unwrap(), + date: record[2].parse::>().unwrap() + }) + } + } + history + } + + pub fn save_csv(&self, file_path: &str) { + let mut writter = csv::Writer::from_path(file_path).unwrap(); + writter.write_record(&["time", "scramble", "date"]).unwrap(); + for entry in &self.0 { + writter.write_record(&[ + entry.time.to_string(), + entry.scramble.to_string(), + entry.date.to_string() + ]).unwrap(); + } + writter.flush().unwrap(); + } + + pub fn summary(&self, n: usize) -> Vec { + self.0.iter().skip(self.0.len() - n).map(|Entry{time, ..}| time.to_string()).collect() + } +} diff --git a/src/main.rs b/src/main.rs index 26b5468..e106cb2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,12 +5,21 @@ use sdl2::pixels::Color; use sdl2::rect::Rect; pub mod time; -pub mod shuffle; +pub mod scramble; pub mod text; +pub mod history; + +use scramble::Scramble; +use history::History; const WIDTH: u32 = 640; const HEIGHT: u32 = 480; const TITLE: &str = "rutikmer"; +const FONT_SIZE: u32 = 40; + +const GREEN: Color = Color::RGB(0x1B, 0x5E, 0x20); +const ORANGE: Color = Color::RGB(0xEF, 0x6C, 0x00); +const BLACK: Color = Color::RGB(0x00, 0x00, 0x00); fn main() { let sdl = sdl2::init().unwrap(); @@ -21,7 +30,8 @@ fn main() { .resizable() .build() .unwrap(); - let font = ttf.load_font("font/FiraMono-Regular.ttf", 40).unwrap(); + let font = ttf.load_font("font/FiraMono-Regular.ttf", FONT_SIZE as u16).unwrap(); + let hist = History::from_csv("history.csv"); let mut canvas = window.into_canvas().build().unwrap(); let mut event_pump = sdl.event_pump().unwrap(); @@ -29,9 +39,9 @@ fn main() { let mut timer = time::Timer::new(); let timer_rect = Rect::new(10, 10, 100, 40); - let mut text_factory = text::Factory::new(&font, &tex_creator, Color::RGB(0, 0, 0)); + let mut text_factory = text::Factory::new(&font, &tex_creator, BLACK, FONT_SIZE); - let mut shuffle_str = shuffle::Move::string_sequence(10); + let mut scramble_str = Scramble::new_rand(10).to_string(); 'running: loop { for e in event_pump.poll_iter() { @@ -43,7 +53,7 @@ fn main() { time::State::Active => timer.stop(), time::State::Inactive => { timer.idle(); - shuffle_str = shuffle::Move::string_sequence(10); + scramble_str = Scramble::new_rand(10).to_string(); }, } } @@ -59,9 +69,9 @@ fn main() { } } let bg_color = match timer.state { - time::State::Idle => Color::RGB(100, 100, 0), - time::State::Active => Color::RGB(0, 100, 0), - time::State::Inactive => Color::RGB(0, 0, 0), + time::State::Idle => ORANGE, + time::State::Active => GREEN, + time::State::Inactive => BLACK, }; canvas.set_draw_color(bg_color); text_factory.set_bg(bg_color); @@ -72,7 +82,11 @@ fn main() { } if timer.state == time::State::Inactive { - canvas.copy(&text_factory.from_string(&shuffle_str), None, Rect::new(10, 100, 500, 40)).unwrap(); + canvas.copy(&text_factory.from_string(&scramble_str), None, Rect::new(10, 100, 500, 40)).unwrap(); + let sum = hist.summary(3); + for (i, s) in sum.iter().enumerate() { + canvas.copy(&text_factory.from_string(&s), None, Rect::new(10, 200 + 40 * (i as i32), 200, 30)).unwrap(); + } } canvas.present(); diff --git a/src/scramble.rs b/src/scramble.rs new file mode 100644 index 0000000..abee6a6 --- /dev/null +++ b/src/scramble.rs @@ -0,0 +1,133 @@ +use std::fmt; +use std::str; + +use rand::{ + distributions::{Distribution, Standard}, + Rng +}; + +pub struct Scramble(Vec); + +impl Scramble { + pub fn new_rand(n: usize) -> Scramble { + let mut sequence: Vec = Vec::with_capacity(n); + + while sequence.len() != n { + let direction = rand::random::(); + let modifier = rand::random::(); + + if let Some(l) = sequence.last() { + if l.direction == direction { + continue; + } + } + sequence.push(Move { direction, modifier }); + } + Scramble(sequence) + } +} + +impl fmt::Display for Scramble { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.0.iter().map(|m| m.to_string()).collect::>().join(" ")) + } +} + +impl str::FromStr for Scramble { + type Err = &'static str; + fn from_str(s: &str) -> Result { + let strs = s.split(" "); + let mut scramble = Scramble(Vec::new()); + for s in strs { + scramble.0.push(s.parse()?); + } + Ok(scramble) + } +} + +impl str::FromStr for Move { + type Err = &'static str; + fn from_str(s: &str) -> Result { + use Direction::*; + use Modifier::*; + + let mut cs = s.chars(); + let direction = match cs.next() { + Some('F') => Front, + Some('B') => Back, + Some('D') => Down, + Some('U') => Up, + Some('R') => Right, + Some('L') => Left, + Some(_) => return Err("Move direction isn't valid"), + None => return Err("Move format is empty"), + }; + let modifier = match cs.next() { + Some('\'') => Prime, + Some('2') => Twice, + Some(_) => return Err("Move modifier isn't valid"), + None => No, + }; + if let Some(_) = cs.next() { + return Err("Unexpected character in move"); + } + Ok(Move{ direction, modifier }) + } +} + +#[derive(PartialEq)] +enum Direction { Front, Back, Down, Up, Right, Left, } + +enum Modifier { No, Twice, Prime, } + +struct Move { + direction: Direction, + modifier: Modifier, +} + +// https://stackoverflow.com/questions/48490049 +impl Distribution for Standard { + fn sample(&self, rng: &mut R) -> Direction { + use Direction::*; + match rng.gen_range(0, 6) { + 0 => Front, + 1 => Back, + 2 => Down, + 3 => Up, + 4 => Right, + _ => Left, + } + } +} + +impl Distribution for Standard { + fn sample(&self, rng: &mut R) -> Modifier { + use Modifier::*; + match rng.gen_range(0, 3) { + 0 => No, + 1 => Twice, + _ => Prime, + } + } +} + +impl fmt::Display for Move { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + use Direction::*; + use Modifier::*; + let letter = match self.direction { + Front => "F", + Back => "B", + Down => "D", + Up => "U", + Right => "R", + Left => "L", + }; + let modifier = match self.modifier { + No => "", + Twice => "2", + Prime => "'", + }; + write!(f, "{}{}", letter, modifier) + } +} diff --git a/src/shuffle.rs b/src/shuffle.rs deleted file mode 100644 index 7f8f88f..0000000 --- a/src/shuffle.rs +++ /dev/null @@ -1,102 +0,0 @@ -use rand::{ - distributions::{Distribution, Standard}, - Rng -}; - -#[derive(PartialEq)] -enum MoveDirection { - Front, - Back, - Down, - Up, - Right, - Left, -} - -enum MoveModifier { - None, - Twice, - Prime, -} - -pub struct Move { - direction: MoveDirection, - modifier: MoveModifier, -} - - -// https://stackoverflow.com/questions/48490049 -impl Distribution for Standard { - fn sample(&self, rng: &mut R) -> MoveDirection { - use MoveDirection::*; - - match rng.gen_range(0, 6) { - 0 => Front, - 1 => Back, - 2 => Down, - 3 => Up, - 4 => Right, - _ => Left, - } - } -} - -impl Distribution for Standard { - fn sample(&self, rng: &mut R) -> MoveModifier { - use MoveModifier::*; - - match rng.gen_range(0, 3) { - 0 => None, - 1 => Twice, - _ => Prime, - } - } -} - -impl Move { - pub fn sequence(n: usize) -> Vec { - let mut sequence: Vec = Vec::with_capacity(n); - - while sequence.len() != n { - let direction = rand::random::(); - let modifier = rand::random::(); - - if let Some(l) = sequence.last() { - if l.direction == direction { - continue; - } - } - sequence.push(Move { direction, modifier }); - } - sequence - } - - pub fn string_sequence(n: usize) -> String { - let seq = Move::sequence(n); - seq.iter().map(|m| m.to_string() + " ").collect::>().join(" ") - } -} - -use std::fmt; - -impl fmt::Display for Move { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - use MoveDirection::*; - use MoveModifier::*; - - let letter = match self.direction { - Front => "F", - Back => "B", - Down => "D", - Up => "U", - Right => "R", - Left => "L", - }; - let modifier = match self.modifier { - None => "", - Twice => "2", - Prime => "'", - }; - write!(f, "{}{}", letter, modifier) - } -} diff --git a/src/text.rs b/src/text.rs index a27ca49..e62db3d 100644 --- a/src/text.rs +++ b/src/text.rs @@ -1,6 +1,7 @@ use sdl2::ttf; -use sdl2::render::{Texture, TextureCreator}; +use sdl2::render::{Canvas, Texture, TextureCreator}; use sdl2::pixels::Color; +use sdl2::rect::Rect; const WHITE: Color = Color::RGB(255, 255, 255); @@ -8,18 +9,20 @@ pub struct Factory<'a, T> { font: &'a ttf::Font<'a, 'a>, creator: &'a TextureCreator, bg: Color, + font_size: u32, } impl<'a, T> Factory<'a, T> { pub fn new(font: &'a ttf::Font, - creator: &'a TextureCreator, - bg: Color + creator: &'a TextureCreator, + bg: Color, + font_size: u32 ) -> Factory<'a, T> { - Factory { font, creator, bg } + Factory { font, creator, bg, font_size } } - pub fn from_string(&self, s: &String) -> Texture + pub fn from_string(&self, s: &str) -> Texture { let surface = self.font.render(s).shaded(WHITE, self.bg).unwrap(); self.creator.create_texture_from_surface(&surface).unwrap() @@ -30,14 +33,32 @@ impl<'a, T> Factory<'a, T> { } } +struct Frame<'a> { + width: u32, + height: u32, + texture: Texture<'a>, +} + +impl<'a> Frame<'a> { + fn new(s: &'a str, factory: &'a Factory) -> Frame<'a> { + Frame{ + width: s.len() as u32 * factory.font_size, + height: factory.font_size, + texture: factory.from_string(s) + } + } -// pub trait TextTexture { -// fn to_texture(&self, factory: &Factory) -> Texture; -// } -// -// impl TextTexture for String { -// fn to_texture(&self, factory: &Factory) -> Texture { -// let surface = factory.font.render(self).shaded(WHITE, factory.bg).unwrap(); -// factory.creator.create_texture_from_surface(&surface).unwrap() -// } -// } + fn to_rect(&self, x: i32, y: i32) -> Rect { + Rect::new(x, y, self.width, self.height) + } +} + +trait Framable { + fn to_frame<'a>(&'a self) -> Frame<'a>; + + fn put_canvas(&self, canvas: &mut Canvas, x: i32, y: i32) { + let frame = self.to_frame(); + let rect = frame.to_rect(x, y); + canvas.copy(&frame.texture, None, rect); + } +} -- cgit