From 4aacc249b7a90d58e7a2bd38b2b469c7d6cf693c Mon Sep 17 00:00:00 2001 From: Fedor Logachev Date: Thu, 13 May 2021 01:41:30 -0500 Subject: [PATCH 01/18] Update macroquad version --- Cargo.lock | 790 +++++++++++++++++++++++++++++++++++++++---- Cargo.toml | 3 +- src/assets.rs | 75 ++-- src/error.rs | 3 + src/main.rs | 4 +- src/utils.rs | 2 +- zgui/Cargo.toml | 2 +- zgui/src/lib.rs | 3 +- zscene/Cargo.toml | 2 +- zscene/src/sprite.rs | 1 + 10 files changed, 774 insertions(+), 111 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc7578d6..7b375a96 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,19 +8,41 @@ checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" [[package]] name = "ahash" -version = "0.3.8" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217" +checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e" [[package]] name = "aho-corasick" -version = "0.7.15" +version = "0.7.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" dependencies = [ "memchr", ] +[[package]] +name = "alsa" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75c4da790adcb2ce5e758c064b4f3ec17a30349f9961d3e5e6c9688b052a9e18" +dependencies = [ + "alsa-sys", + "bitflags", + "libc", + "nix", +] + +[[package]] +name = "alsa-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db8fee663d06c4e303404ef5f40488a53e062f89ba8bfed81f42325aafad1527" +dependencies = [ + "libc", + "pkg-config", +] + [[package]] name = "ansi_term" version = "0.11.0" @@ -53,6 +75,25 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +[[package]] +name = "bindgen" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2da379dbebc0b76ef63ca68d8fc6e71c0f13e59432e0987e508c1820e6ab5239" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "peeking_take_while", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", +] + [[package]] name = "bitflags" version = "1.2.1" @@ -73,15 +114,39 @@ checksum = "bed57e2090563b83ba8f83366628ce535a7584c9afa4c9fc0612a03925c6df58" [[package]] name = "byteorder" -version = "1.4.2" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "bytes" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b" +checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" [[package]] name = "cc" version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" +dependencies = [ + "jobserver", +] + +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + +[[package]] +name = "cexpr" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27" +dependencies = [ + "nom", +] [[package]] name = "cfg-if" @@ -89,12 +154,89 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clang-sys" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "853eda514c284c2287f4bf20ae614f8781f40a81d32ecda6e91449304dfe077c" +dependencies = [ + "glob", + "libc", + "libloading", +] + [[package]] name = "color_quant" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" +[[package]] +name = "combine" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc4369b5e4c0cddf64ad8981c0111e7df4f7078f4d6ba98fb31f2e17c4c57b7e" +dependencies = [ + "bytes", + "memchr", +] + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "core-foundation-sys" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ca8a5221364ef15ce201e8ed2f609fc312682a8f4e0e3d4aa5879764e0fa3b" + +[[package]] +name = "coreaudio-rs" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11894b20ebfe1ff903cbdc52259693389eea03b94918a2def2c30c3bf227ad88" +dependencies = [ + "bitflags", + "coreaudio-sys", +] + +[[package]] +name = "coreaudio-sys" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b7e3347be6a09b46aba228d6608386739fb70beff4f61e07422da87b0bb31fa" +dependencies = [ + "bindgen", +] + +[[package]] +name = "cpal" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8351ddf2aaa3c583fa388029f8b3d26f3c7035a20911fdd5f2e2ed7ab57dad25" +dependencies = [ + "alsa", + "core-foundation-sys", + "coreaudio-rs", + "jni", + "js-sys", + "lazy_static", + "libc", + "mach", + "ndk", + "ndk-glue", + "nix", + "oboe", + "parking_lot", + "stdweb", + "thiserror", + "web-sys", + "winapi", +] + [[package]] name = "crc32fast" version = "1.2.1" @@ -106,10 +248,45 @@ dependencies = [ [[package]] name = "ctor" -version = "0.1.19" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e98e2ad1a782e33928b96fc3948e7c355e5af34ba4de7670fe8bac2a3b2006d" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "darling" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8f45d9ad417bcef4817d614a501ab55cdd96a6fdb24f49aab89a54acfd66b19" +checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" +dependencies = [ + "darling_core", "quote", "syn", ] @@ -124,12 +301,24 @@ dependencies = [ "byteorder", ] +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "derive_more" -version = "0.99.11" +version = "0.99.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cb0e6161ad61ed084a36ba71fbba9e3ac5aee3606fb607fe08da6acbcf3d8c" +checksum = "f82b1b72f1263f214c0f823371768776c4f5841b942c9883aa8e5ec584fd0ba6" dependencies = [ + "convert_case", "proc-macro2", "quote", "syn", @@ -154,11 +343,17 @@ dependencies = [ "termcolor", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "fontdue" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3203e88e086474e56b0785255804a0c23542f76253584d3f43152cd2bb95d0b7" +checksum = "c7872084ec11cf1ff61c005223ff439110bb2d88e7f2dd348ac1f79907d57b0f" dependencies = [ "hashbrown", "ttf-parser", @@ -166,21 +361,23 @@ dependencies = [ [[package]] name = "glam" -version = "0.10.2" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "579160312273c954cc51bd440f059dde741029ac8daf8c84fece76cb77f62c15" -dependencies = [ - "version_check", -] +checksum = "333928d5eb103c5d4050533cec0384302db6be8ef7d3cebd30ec6a35350353da" + +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "hashbrown" -version = "0.8.2" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b62f79061a0bc2e046024cb7ba44b08419ed238ecbd9adbd787434b9e8c25" +checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" dependencies = [ "ahash", - "autocfg", ] [[package]] @@ -201,17 +398,29 @@ dependencies = [ "libc", ] +[[package]] +name = "hound" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a164bb2ceaeff4f42542bdb847c41517c78a60f5649671b2a07312b6e117549" + [[package]] name = "humantime" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "image" -version = "0.23.13" +version = "0.23.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "293f07a1875fa7e9c5897b51aa68b2d8ed8271b87e1a44cb64b9c3d98aabbc0d" +checksum = "24ffcb7e7244a9bf19d35bf2883b9c080c4ced3c07a9895572178cdb8f13f6a1" dependencies = [ "bytemuck", "byteorder", @@ -222,11 +431,100 @@ dependencies = [ "png", ] +[[package]] +name = "instant" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "jni" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24967112a1e4301ca5342ea339763613a37592b8a6ce6cf2e4494537c7a42faf" +dependencies = [ + "cesu8", + "combine", + "jni-sys", + "log", + "thiserror", + "walkdir", +] + +[[package]] +name = "jni-sys" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" + +[[package]] +name = "jobserver" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "972f5ae5d1cb9c6ae417789196c803205313edde988685da5e3aae0827b9e7fd" +dependencies = [ + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83bdfbace3a0e81a4253f73b49e960b053e396a11012cbd49b9b74d6a2b67062" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[package]] +name = "lewton" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "777b48df9aaab155475a83a7df3070395ea1ac6902f5cd062b8f2b028075c030" +dependencies = [ + "byteorder", + "ogg", + "tinyvec", +] + [[package]] name = "libc" -version = "0.2.86" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c" +checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" + +[[package]] +name = "libloading" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f84d96438c15fcd6c3f244c8fce01d1e2b9c6b5623e9c711dc9286d8fc92d6a" +dependencies = [ + "cfg-if", + "winapi", +] + +[[package]] +name = "lock_api" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0382880606dff6d15c9476c416d18690b72742aa7b605bb6dd6ec9030fbf07eb" +dependencies = [ + "scopeguard", +] [[package]] name = "log" @@ -238,10 +536,17 @@ dependencies = [ ] [[package]] -name = "macroquad" -version = "0.3.0-alpha.15" +name = "mach" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a85f60e0bcf3c97a09b580d8655b80b4be26e7f648ece3a8a6df4baf3567f896" +checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" +dependencies = [ + "libc", +] + +[[package]] +name = "macroquad" +version = "0.3.3" dependencies = [ "bumpalo", "fontdue", @@ -250,25 +555,24 @@ dependencies = [ "macroquad_macro", "miniquad", "quad-rand", + "rodio", ] [[package]] name = "macroquad_macro" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88dc77cec2b364f6e0cba5701b20482ef5c7c87f5587ee9e9296240936eaaf8a" +version = "0.1.5" [[package]] name = "memchr" -version = "2.3.4" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" +checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" [[package]] name = "miniquad" -version = "0.3.0-alpha.26" +version = "0.3.0-alpha.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f93dc8b526b2d565063e819449f0e2e7d6acfbf638c9a14c017d5f6c57e3caf" +checksum = "544f4f479ba6084845f4908abbeb40abb5fe01b171928dca2901852231f3f838" dependencies = [ "sapp-android", "sapp-darwin", @@ -288,6 +592,73 @@ dependencies = [ "adler32", ] +[[package]] +name = "ndk" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8794322172319b972f528bf90c6b467be0079f1fa82780ffb431088e741a73ab" +dependencies = [ + "jni-sys", + "ndk-sys", + "num_enum", + "thiserror", +] + +[[package]] +name = "ndk-glue" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5caf0c24d51ac1c905c27d4eda4fa0635bbe0de596b8f79235e0b17a4d29385" +dependencies = [ + "lazy_static", + "libc", + "log", + "ndk", + "ndk-macro", + "ndk-sys", +] + +[[package]] +name = "ndk-macro" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05d1c6307dc424d0f65b9b06e94f88248e6305726b14729fd67a5e47b2dc481d" +dependencies = [ + "darling", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "ndk-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c44922cb3dbb1c70b5e5f443d63b64363a898564d739ba5198e3a9138442868d" + +[[package]] +name = "nix" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa9b4819da1bc61c0ea48b63b7bc8604064dd43013e7cc325df098d49cd7c18a" +dependencies = [ + "bitflags", + "cc", + "cfg-if", + "libc", +] + +[[package]] +name = "nom" +version = "5.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" +dependencies = [ + "memchr", + "version_check", +] + [[package]] name = "num" version = "0.3.1" @@ -310,6 +681,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-derive" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "num-integer" version = "0.1.44" @@ -351,11 +733,65 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_enum" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "226b45a5c2ac4dd696ed30fa6b94b057ad909c7b7fc2e0d0808192bced894066" +dependencies = [ + "derivative", + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c0fd9eba1d5db0994a239e09c1be402d35622277e35468ba891aa5e3188ce7e" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "oboe" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cfb2390bddb9546c0f7448fd1d2abdd39e6075206f960991eb28c7fa7f126c4" +dependencies = [ + "jni", + "ndk", + "ndk-glue", + "num-derive", + "num-traits", + "oboe-sys", +] + +[[package]] +name = "oboe-sys" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe069264d082fc820dfa172f79be3f2e088ecfece9b1c47b0c9fd838d2bef103" +dependencies = [ + "cc", +] + +[[package]] +name = "ogg" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6951b4e8bf21c8193da321bcce9c9dd2e13c858fe078bf9054a288b419ae5d6e" +dependencies = [ + "byteorder", +] + [[package]] name = "once_cell" -version = "1.6.0" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ad167a2f54e832b82dbe003a046280dceffe5227b5f79e08e363a29638cfddd" +checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" [[package]] name = "output_vt100" @@ -366,6 +802,43 @@ dependencies = [ "winapi", ] +[[package]] +name = "parking_lot" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + +[[package]] +name = "pkg-config" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" + [[package]] name = "png" version = "0.16.8" @@ -390,11 +863,20 @@ dependencies = [ "output_vt100", ] +[[package]] +name = "proc-macro-crate" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" +dependencies = [ + "toml", +] + [[package]] name = "proc-macro2" -version = "1.0.24" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" dependencies = [ "unicode-xid", ] @@ -432,23 +914,42 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +[[package]] +name = "redox_syscall" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "742739e41cd49414de871ea5e549afb7e2a3ac77b589bcbebe8c82fab37147fc" +dependencies = [ + "bitflags", +] + [[package]] name = "regex" -version = "1.4.3" +version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" dependencies = [ "aho-corasick", "memchr", "regex-syntax", - "thread_local", ] [[package]] name = "regex-syntax" -version = "0.6.22" +version = "0.6.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" + +[[package]] +name = "rodio" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" +checksum = "b65c2eda643191f6d1bb12ea323a9db8d9ba95374e9be3780b5a9fb5cfb8520f" +dependencies = [ + "cpal", + "hound", + "lewton", +] [[package]] name = "ron" @@ -461,6 +962,21 @@ dependencies = [ "serde", ] +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "sapp-android" version = "0.1.5" @@ -472,9 +988,9 @@ dependencies = [ [[package]] name = "sapp-darwin" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf0d38a22937236c2ad6b90a12656a1f307efb144b6d7516104d2169f1dc3b18" +checksum = "0310e2445f307468aa13f1cde94d6fba6b8fd329afbb642dedbe3faf1a145f31" dependencies = [ "cc", ] @@ -499,53 +1015,83 @@ dependencies = [ [[package]] name = "sapp-linux" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "014328e7e348d068b6d655bd080ee0ca373321e59954eec8a865a87877b1d848" +checksum = "22b66fa7effb2823d80997912186494d4a19aa74d3ac1ff5aa1cfb648537be92" dependencies = [ "libc", ] [[package]] name = "sapp-wasm" -version = "0.1.20" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b0cfb71996396a4e04131b260f6e53a4783c4a818076b32dd76729ab59fa28" +checksum = "46dc18c2e8b9b9d1a50a8d83944d1e7c309581c99186b52d0530420d108ce37c" [[package]] name = "sapp-windows" -version = "0.2.14" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74bf2c366504901527cdd5093d067f12f81250791a8187ddac90b2120832becb" +checksum = "d8fa2d1f641f76f8397cc91c1b7327c6538d4f7897c185d9aac8431cef940e56" dependencies = [ "winapi", ] +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + [[package]] name = "serde" -version = "1.0.123" +version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae" +checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.123" +version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31" +checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d" dependencies = [ "proc-macro2", "quote", "syn", ] +[[package]] +name = "shlex" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" + +[[package]] +name = "smallvec" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" + +[[package]] +name = "stdweb" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef5430c8e36b713e13b48a9f709cc21e046723fe44ce34587b73a830203b533e" + +[[package]] +name = "strsim" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" + [[package]] name = "syn" -version = "1.0.60" +version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" +checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" dependencies = [ "proc-macro2", "quote", @@ -562,19 +1108,54 @@ dependencies = [ ] [[package]] -name = "thread_local" -version = "1.1.3" +name = "thiserror" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" +checksum = "e0f4a65597094d4483ddaed134f409b2cb7c1beccf25201a9f73c719254fa98e" dependencies = [ - "once_cell", + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinyvec" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + +[[package]] +name = "toml" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +dependencies = [ + "serde", ] [[package]] name = "ttf-parser" -version = "0.8.3" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7622061403fd00f0820df288e5a580e87d3ce15a1c4313c59fd1ffb77129903f" +checksum = "85e00391c1f3d171490a3f8bd79999b0002ae38d3da0d6a3a306c754b053d71b" [[package]] name = "unicode-segmentation" @@ -584,15 +1165,90 @@ checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" [[package]] name = "unicode-xid" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] name = "version_check" -version = "0.9.2" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" + +[[package]] +name = "walkdir" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +dependencies = [ + "same-file", + "winapi", + "winapi-util", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" +checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f" + +[[package]] +name = "web-sys" +version = "0.3.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e828417b379f3df7111d3a2a9e5753706cae29c41f7c4029ee9fd77f3e09e582" +dependencies = [ + "js-sys", + "wasm-bindgen", +] [[package]] name = "winapi" diff --git a/Cargo.toml b/Cargo.toml index 3334d668..909bac68 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,9 +24,10 @@ zscene = { path = "zscene" } zcomponents = { path = "zcomponents" } rand = { version = "0.8", default-features = false, features = ["alloc"] } quad-rand = { version = "0.2", features = ["rand"] } -mq = { package = "macroquad", version = "0.3.0-alpha.15" } +mq = { package = "macroquad", version = "0.3" } heck = "0.3" once_cell = "1.6" [dev-dependencies] pretty_assertions = "0.6" + diff --git a/src/assets.rs b/src/assets.rs index 28560707..ebf380c5 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -29,10 +29,11 @@ use crate::{ static INSTANCE: OnceCell = OnceCell::new(); -pub async fn load() { +pub async fn load() -> ZResult { assert!(INSTANCE.get().is_none()); - let assets = Assets::load().await.expect("Can't load assets"); + let assets = Assets::load().await?; INSTANCE.set(assets).expect("Can't set assets instance"); + Ok(()) } pub fn get() -> &'static Assets { @@ -53,12 +54,12 @@ async fn deserialize_from_file(path: &str) -> ZResult { async fn load_map( table: &[(Key, &str)], expand_path: fn(&str) -> String, -) -> HashMap { +) -> ZResult> { let mut map = HashMap::new(); for &(key, path) in table { - map.insert(key, load_texture(&expand_path(path)).await); + map.insert(key, load_texture(&expand_path(path)).await?); } - map + Ok(map) } #[derive(Debug, Clone, Deserialize)] @@ -98,15 +99,15 @@ impl Assets { for (obj_type, SpriteInfo { paths, .. }) in sprites_info.iter() { let mut frames = HashMap::new(); for (frame_name, path) in paths { - frames.insert(frame_name.to_string(), load_texture(path).await); + frames.insert(frame_name.to_string(), load_texture(path).await?); } sprite_frames.insert(obj_type.clone(), frames); } sprite_frames }; Ok(Self { - textures: Textures::load().await, - font: text::load_ttf_font("assets/OpenSans-Regular.ttf").await, + textures: Textures::load().await?, + font: text::load_ttf_font("assets/OpenSans-Regular.ttf").await?, sprites_info, sprite_frames, prototypes: Prototypes::from_str(&read_file("assets/objects.ron").await?), @@ -126,13 +127,13 @@ pub struct Textures { } impl Textures { - async fn load() -> Self { - Self { - map: MapObjectTextures::load().await, - weapon_flashes: load_weapon_flashes().await, - icons: IconTextures::load().await, - dot: load_texture("assets/img/dot.png").await, - } + async fn load() -> ZResult { + Ok(Self { + map: MapObjectTextures::load().await?, + weapon_flashes: load_weapon_flashes().await?, + icons: IconTextures::load().await?, + dot: load_texture("assets/img/dot.png").await?, + }) } } @@ -149,17 +150,17 @@ pub struct MapObjectTextures { } impl MapObjectTextures { - async fn load() -> Self { - Self { - selection: load_texture("assets/img/selection.png").await, - white_hex: load_texture("assets/img/white_hex.png").await, - tile: load_texture("assets/img/tile.png").await, - tile_rocks: load_texture("assets/img/tile_rocks.png").await, - grass: load_texture("assets/img/grass.png").await, - blood: load_texture("assets/img/blood.png").await, - explosion_ground_mark: load_texture("assets/img/explosion_ground_mark.png").await, - shadow: load_texture("assets/img/shadow.png").await, - } + async fn load() -> ZResult { + Ok(Self { + selection: load_texture("assets/img/selection.png").await?, + white_hex: load_texture("assets/img/white_hex.png").await?, + tile: load_texture("assets/img/tile.png").await?, + tile_rocks: load_texture("assets/img/tile_rocks.png").await?, + grass: load_texture("assets/img/grass.png").await?, + blood: load_texture("assets/img/blood.png").await?, + explosion_ground_mark: load_texture("assets/img/explosion_ground_mark.png").await?, + shadow: load_texture("assets/img/shadow.png").await?, + }) } } @@ -173,18 +174,18 @@ pub struct IconTextures { } impl IconTextures { - async fn load() -> Self { - Self { - info: load_texture("assets/img/icon_info.png").await, - end_turn: load_texture("assets/img/icon_end_turn.png").await, - main_menu: load_texture("assets/img/icon_menu.png").await, - abilities: load_ability_icons().await, - lasting_effects: load_lasting_effects().await, - } + async fn load() -> ZResult { + Ok(Self { + info: load_texture("assets/img/icon_info.png").await?, + end_turn: load_texture("assets/img/icon_end_turn.png").await?, + main_menu: load_texture("assets/img/icon_menu.png").await?, + abilities: load_ability_icons().await?, + lasting_effects: load_lasting_effects().await?, + }) } } -async fn load_weapon_flashes() -> HashMap { +async fn load_weapon_flashes() -> ZResult> { let map = &[ (WeaponType::Slash, "slash"), (WeaponType::Smash, "smash"), @@ -194,7 +195,7 @@ async fn load_weapon_flashes() -> HashMap { load_map(map, |s| format!("assets/img/{}.png", s)).await } -async fn load_ability_icons() -> HashMap { +async fn load_ability_icons() -> ZResult> { let map = &[ (Ability::Knockback, "knockback"), (Ability::Club, "club"), @@ -215,7 +216,7 @@ async fn load_ability_icons() -> HashMap { load_map(map, |s| format!("assets/img/icon_ability_{}.png", s)).await } -async fn load_lasting_effects() -> HashMap { +async fn load_lasting_effects() -> ZResult> { let map = &[ (effect::Lasting::Stun, "stun"), (effect::Lasting::Poison, "poison"), diff --git a/src/error.rs b/src/error.rs index 8ca41b3d..3cb57bf6 100644 --- a/src/error.rs +++ b/src/error.rs @@ -10,6 +10,7 @@ pub enum ZError { }, IOError(io::Error), MqFileError(mq::file::FileError), + MqFontError(mq::text::FontError), } impl ZError { @@ -29,6 +30,7 @@ impl fmt::Display for ZError { } ZError::IOError(ref e) => write!(f, "IO Error: {}", e), ZError::MqFileError(ref e) => write!(f, "Macroquad File error: {}", e), + ZError::MqFontError(ref e) => write!(f, "Macroquad Font error: {}", e), } } } @@ -41,6 +43,7 @@ impl error::Error for ZError { ZError::RonDeserializeError { error, .. } => Some(error), ZError::IOError(ref e) => Some(e), ZError::MqFileError(ref e) => Some(e), + ZError::MqFontError(ref e) => Some(e), } } } diff --git a/src/main.rs b/src/main.rs index 0508c172..f9e5c894 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,7 +48,7 @@ impl MainState { #[mq::main("Zemeroth")] #[macroquad(crate_rename = "mq")] -async fn main() { +async fn main() -> ZResult<()> { // std::env isn't supported on WASM. #[cfg(not(target_arch = "wasm32"))] if std::env::var("RUST_BACKTRACE").is_err() { @@ -56,7 +56,7 @@ async fn main() { } env_logger::init(); quad_rand::srand(mq::miniquad::date::now() as _); - assets::load().await; + assets::load().await?; let mut state = MainState::new().expect("Can't create the main state"); loop { state.tick().expect("Tick failed"); diff --git a/src/utils.rs b/src/utils.rs index 5f23f25c..66fbfc0d 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -89,7 +89,7 @@ pub fn make_and_set_camera(aspect_ratio: f32) -> Camera2D { w: aspect_ratio * 2.0, h: 2.0, }); - set_camera(camera); + set_camera(&camera); camera } diff --git a/zgui/Cargo.toml b/zgui/Cargo.toml index d3f240e1..ea7e3431 100644 --- a/zgui/Cargo.toml +++ b/zgui/Cargo.toml @@ -9,4 +9,4 @@ keywords = ["gamedev", "gui"] [dependencies] log = "0.4" -mq = { package = "macroquad", version = "0.3.0-alpha" } +mq = { package = "macroquad", version = "0.3" } diff --git a/zgui/src/lib.rs b/zgui/src/lib.rs index b95803a3..d086145c 100644 --- a/zgui/src/lib.rs +++ b/zgui/src/lib.rs @@ -161,6 +161,7 @@ impl Sprite { font, font_scale: self.scale.x, color: self.color, + ..Default::default() }, ); } @@ -321,7 +322,7 @@ impl Gui { pub fn draw(&self) { let ui_coordinates = Rect::new(-self.aspect_ratio, -1.0, self.aspect_ratio * 2.0, 2.0); - set_camera(Camera2D::from_display_rect(ui_coordinates)); + set_camera(&Camera2D::from_display_rect(ui_coordinates)); for AnchoredWidget { widget, .. } in &self.anchored_widgets { widget.borrow().draw(); } diff --git a/zscene/Cargo.toml b/zscene/Cargo.toml index a5243f24..9b1b15bb 100644 --- a/zscene/Cargo.toml +++ b/zscene/Cargo.toml @@ -8,4 +8,4 @@ description = "Scene and Actions for gwg" keywords = ["gamedev", "2D"] [dependencies] -mq = { package = "macroquad", version = "0.3.0-alpha" } +mq = { package = "macroquad", version = "0.3" } diff --git a/zscene/src/sprite.rs b/zscene/src/sprite.rs index dd8dda93..f0763718 100644 --- a/zscene/src/sprite.rs +++ b/zscene/src/sprite.rs @@ -224,6 +224,7 @@ impl Sprite { font: *font, font_scale: data.scale.x, color: data.color, + ..Default::default() }, ); } From 6dbf8e8d72ee92eba74a0466d217b6492dd09e5b Mon Sep 17 00:00:00 2001 From: Fedor Logachev Date: Thu, 13 May 2021 02:04:10 -0500 Subject: [PATCH 02/18] Clean up rust 1.52 warnings --- src/core/battle.rs | 4 ++-- src/core/battle/ability.rs | 2 +- src/core/battle/component.rs | 2 +- src/core/battle/scenario.rs | 2 +- src/core/campaign.rs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/battle.rs b/src/core/battle.rs index efe0321a..568a4764 100644 --- a/src/core/battle.rs +++ b/src/core/battle.rs @@ -36,8 +36,8 @@ impl Phase { } } -#[serde(transparent)] #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, derive_more::From)] +#[serde(transparent)] pub struct Rounds(pub i32); impl Rounds { @@ -56,8 +56,8 @@ impl fmt::Display for Rounds { } } -#[serde(transparent)] #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] +#[serde(transparent)] pub struct Turns(pub i32); impl Turns { diff --git a/src/core/battle/ability.rs b/src/core/battle/ability.rs index 1e14fcfe..8517d3d3 100644 --- a/src/core/battle/ability.rs +++ b/src/core/battle/ability.rs @@ -45,8 +45,8 @@ impl Status { } } -#[serde(from = "Ability")] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(from = "Ability")] pub struct RechargeableAbility { pub ability: Ability, pub status: Status, diff --git a/src/core/battle/component.rs b/src/core/battle/component.rs index 1565283e..7ee6fdb7 100644 --- a/src/core/battle/component.rs +++ b/src/core/battle/component.rs @@ -34,8 +34,8 @@ pub struct Armor { pub armor: battle::Strength, } -#[serde(transparent)] #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)] +#[serde(transparent)] pub struct ObjType(pub String); impl From<&str> for ObjType { diff --git a/src/core/battle/scenario.rs b/src/core/battle/scenario.rs index 6acbe06c..6891891f 100644 --- a/src/core/battle/scenario.rs +++ b/src/core/battle/scenario.rs @@ -34,8 +34,8 @@ pub struct Object { } // TODO: Split into `Scenario` (exact info) and `ScenarioTemplate`? -#[serde(default)] #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(default)] pub struct Scenario { pub map_radius: map::Distance, pub players_count: i32, diff --git a/src/core/campaign.rs b/src/core/campaign.rs index bb83cb36..39660e0f 100644 --- a/src/core/campaign.rs +++ b/src/core/campaign.rs @@ -20,8 +20,8 @@ pub enum Mode { Failed, } -#[serde(transparent)] #[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, derive_more::From)] +#[serde(transparent)] pub struct Renown(pub i32); // TODO: impl `Add` and `Sub` traits for `Renown`. From dce67bbcb1ed829668313d184b6cc348ea1763f7 Mon Sep 17 00:00:00 2001 From: Fedor Logachev Date: Fri, 14 May 2021 15:04:14 -0500 Subject: [PATCH 03/18] zgui: Use adaptive font scale This will lead into lots of atlas rebuilding on window resize, but will make fonts look really good --- src/utils.rs | 2 +- zgui/src/lib.rs | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index 66fbfc0d..a88198b1 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -14,7 +14,7 @@ pub fn time_s(s: f32) -> Duration { // TODO: Move to some config (https://github.com/ozkriff/zemeroth/issues/424) pub const fn font_size() -> u16 { - 128 + 20 } pub struct LineHeights { diff --git a/zgui/src/lib.rs b/zgui/src/lib.rs index d086145c..0c223024 100644 --- a/zgui/src/lib.rs +++ b/zgui/src/lib.rs @@ -14,7 +14,7 @@ use mq::{ color::Color, math::{Rect, Vec2}, shapes, - text::{draw_text_ex, measure_text, Font, TextParams}, + text::{camera_font_scale, draw_text_ex, measure_text, Font, TextParams}, texture::{draw_texture_ex, DrawTextureParams, Texture2D}, window, }; @@ -152,6 +152,12 @@ impl Sprite { font, font_size, } => { + // desired font size in camera space + let font_world_size = font_size as f32 * self.scale.x; + + // let macroquad figure appropriate TextParams for currently active camera + let (font_size, font_scale, font_scale_aspect) = camera_font_scale(font_world_size); + draw_text_ex( label, self.pos.x, @@ -159,7 +165,8 @@ impl Sprite { TextParams { font_size, font, - font_scale: self.scale.x, + font_scale, + font_scale_aspect, color: self.color, ..Default::default() }, From 1fd364ecdeacb47a7aea18b71ef7ebd6c20c23bb Mon Sep 17 00:00:00 2001 From: Fedor Logachev Date: Fri, 14 May 2021 15:05:40 -0500 Subject: [PATCH 04/18] Use same assets path on PC, Web and Android --- Cargo.toml | 3 +++ assets/sprites.ron | 66 +++++++++++++++++++++++----------------------- src/assets.rs | 46 ++++++++++++++++---------------- 3 files changed, 60 insertions(+), 55 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 909bac68..96f719b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,9 @@ opt-level = 3 [workspace] members = ["zcomponents", "zgui", "zscene"] +[package.metadata.android] +assets = "assets/" + [dependencies] ron = "0.6" log = "0.4" diff --git a/assets/sprites.ron b/assets/sprites.ron index e60e39c2..df4588ab 100644 --- a/assets/sprites.ron +++ b/assets/sprites.ron @@ -1,7 +1,7 @@ { "swordsman": ( paths: { - "": "assets/img/swordsman.png", + "": "img/swordsman.png", }, offset_x: 0.15, offset_y: 0.1, @@ -9,8 +9,8 @@ ), "elite_swordsman": ( paths: { - "": "assets/img/elite_swordsman.png", - "rage": "assets/img/elite_swordsman_rage.png", + "": "img/elite_swordsman.png", + "rage": "img/elite_swordsman_rage.png", }, offset_x: 0.15, offset_y: 0.1, @@ -18,7 +18,7 @@ ), "heavy_swordsman": ( paths: { - "": "assets/img/heavy_swordsman.png", + "": "img/heavy_swordsman.png", }, offset_x: 0.15, offset_y: 0.1, @@ -26,7 +26,7 @@ ), "spearman": ( paths: { - "": "assets/img/spearman.png", + "": "img/spearman.png", }, offset_x: 0.2, offset_y: 0.05, @@ -34,7 +34,7 @@ ), "elite_spearman": ( paths: { - "": "assets/img/elite_spearman.png", + "": "img/elite_spearman.png", }, offset_x: 0.2, offset_y: 0.05, @@ -42,7 +42,7 @@ ), "heavy_spearman": ( paths: { - "": "assets/img/heavy_spearman.png", + "": "img/heavy_spearman.png", }, offset_x: 0.2, offset_y: 0.05, @@ -50,7 +50,7 @@ ), "hammerman": ( paths: { - "": "assets/img/hammerman.png", + "": "img/hammerman.png", }, offset_x: 0.05, offset_y: 0.1, @@ -58,7 +58,7 @@ ), "heavy_hammerman": ( paths: { - "": "assets/img/heavy_hammerman.png", + "": "img/heavy_hammerman.png", }, offset_x: 0.05, offset_y: 0.1, @@ -66,9 +66,9 @@ ), "alchemist": ( paths: { - "": "assets/img/alchemist.png", - "throw": "assets/img/alchemist_throw.png", - "heal": "assets/img/alchemist_heal.png", + "": "img/alchemist.png", + "throw": "img/alchemist_throw.png", + "heal": "img/alchemist_heal.png", }, offset_x: 0.05, offset_y: 0.1, @@ -76,9 +76,9 @@ ), "healer": ( paths: { - "": "assets/img/healer.png", - "throw": "assets/img/healer_throw.png", - "heal": "assets/img/healer_heal.png", + "": "img/healer.png", + "throw": "img/healer_throw.png", + "heal": "img/healer_heal.png", }, offset_x: 0.05, offset_y: 0.1, @@ -86,8 +86,8 @@ ), "firer": ( paths: { - "": "assets/img/firer.png", - "throw": "assets/img/firer_throw.png", + "": "img/firer.png", + "throw": "img/firer_throw.png", }, offset_x: 0.05, offset_y: 0.1, @@ -95,7 +95,7 @@ ), "imp": ( paths: { - "": "assets/img/imp.png", + "": "img/imp.png", }, offset_x: 0.0, offset_y: 0.15, @@ -103,7 +103,7 @@ ), "toxic_imp": ( paths: { - "": "assets/img/toxic_imp.png", + "": "img/toxic_imp.png", }, offset_x: 0.0, offset_y: 0.15, @@ -111,8 +111,8 @@ ), "imp_bomber": ( paths: { - "": "assets/img/imp_bomber.png", - "throw": "assets/img/imp_bomber_throw.png", + "": "img/imp_bomber.png", + "throw": "img/imp_bomber_throw.png", }, offset_x: 0.0, offset_y: 0.15, @@ -120,9 +120,9 @@ ), "imp_summoner": ( paths: { - "": "assets/img/imp_summoner.png", - "summon": "assets/img/imp_summoner_cast.png", - "bloodlust": "assets/img/imp_summoner_cast.png", + "": "img/imp_summoner.png", + "summon": "img/imp_summoner_cast.png", + "bloodlust": "img/imp_summoner_cast.png", }, offset_x: 0.0, offset_y: 0.15, @@ -130,7 +130,7 @@ ), "boulder": ( paths: { - "": "assets/img/boulder.png", + "": "img/boulder.png", }, offset_x: 0.0, offset_y: 0.4, @@ -138,7 +138,7 @@ ), "bomb_damage": ( paths: { - "": "assets/img/bomb.png", + "": "img/bomb.png", }, offset_x: 0.0, offset_y: 0.2, @@ -146,7 +146,7 @@ ), "bomb_push": ( paths: { - "": "assets/img/bomb.png", + "": "img/bomb.png", }, offset_x: 0.0, offset_y: 0.2, @@ -154,7 +154,7 @@ ), "bomb_fire": ( paths: { - "": "assets/img/bomb_fire.png", + "": "img/bomb_fire.png", }, offset_x: 0.0, offset_y: 0.2, @@ -162,7 +162,7 @@ ), "bomb_poison": ( paths: { - "": "assets/img/bomb_poison.png", + "": "img/bomb_poison.png", }, offset_x: 0.0, offset_y: 0.2, @@ -170,7 +170,7 @@ ), "bomb_demonic": ( paths: { - "": "assets/img/bomb_demonic.png", + "": "img/bomb_demonic.png", }, offset_x: 0.0, offset_y: 0.2, @@ -178,7 +178,7 @@ ), "fire": ( paths: { - "": "assets/img/fire.png", + "": "img/fire.png", }, offset_x: 0.0, offset_y: 0.2, @@ -187,7 +187,7 @@ ), "poison_cloud": ( paths: { - "": "assets/img/poison_cloud.png", + "": "img/poison_cloud.png", }, offset_x: 0.0, offset_y: 0.2, @@ -196,7 +196,7 @@ ), "spike_trap": ( paths: { - "": "assets/img/spike_trap.png", + "": "img/spike_trap.png", }, offset_x: 0.0, offset_y: 0.5, diff --git a/src/assets.rs b/src/assets.rs index ebf380c5..045c7b3d 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -6,7 +6,7 @@ use std::{collections::HashMap, hash::Hash}; use mq::{ - file::load_file, + file::{self, load_file}, text::{self, Font}, texture::{load_texture, Texture2D}, }; @@ -93,7 +93,9 @@ pub struct Assets { impl Assets { pub async fn load() -> ZResult { - let sprites_info: SpritesInfo = deserialize_from_file("assets/sprites.ron").await?; + file::set_pc_assets_folder("assets"); + + let sprites_info: SpritesInfo = deserialize_from_file("sprites.ron").await?; let sprite_frames = { let mut sprite_frames = HashMap::new(); for (obj_type, SpriteInfo { paths, .. }) in sprites_info.iter() { @@ -107,13 +109,13 @@ impl Assets { }; Ok(Self { textures: Textures::load().await?, - font: text::load_ttf_font("assets/OpenSans-Regular.ttf").await?, + font: text::load_ttf_font("OpenSans-Regular.ttf").await?, sprites_info, sprite_frames, - prototypes: Prototypes::from_str(&read_file("assets/objects.ron").await?), - demo_scenario: deserialize_from_file("assets/scenario_01.ron").await?, - campaign_plan: deserialize_from_file("assets/campaign_01.ron").await?, - agent_campaign_info: deserialize_from_file("assets/agent_campaign_info.ron").await?, + prototypes: Prototypes::from_str(&read_file("objects.ron").await?), + demo_scenario: deserialize_from_file("scenario_01.ron").await?, + campaign_plan: deserialize_from_file("campaign_01.ron").await?, + agent_campaign_info: deserialize_from_file("agent_campaign_info.ron").await?, }) } } @@ -132,7 +134,7 @@ impl Textures { map: MapObjectTextures::load().await?, weapon_flashes: load_weapon_flashes().await?, icons: IconTextures::load().await?, - dot: load_texture("assets/img/dot.png").await?, + dot: load_texture("img/dot.png").await?, }) } } @@ -152,14 +154,14 @@ pub struct MapObjectTextures { impl MapObjectTextures { async fn load() -> ZResult { Ok(Self { - selection: load_texture("assets/img/selection.png").await?, - white_hex: load_texture("assets/img/white_hex.png").await?, - tile: load_texture("assets/img/tile.png").await?, - tile_rocks: load_texture("assets/img/tile_rocks.png").await?, - grass: load_texture("assets/img/grass.png").await?, - blood: load_texture("assets/img/blood.png").await?, - explosion_ground_mark: load_texture("assets/img/explosion_ground_mark.png").await?, - shadow: load_texture("assets/img/shadow.png").await?, + selection: load_texture("img/selection.png").await?, + white_hex: load_texture("img/white_hex.png").await?, + tile: load_texture("img/tile.png").await?, + tile_rocks: load_texture("img/tile_rocks.png").await?, + grass: load_texture("img/grass.png").await?, + blood: load_texture("img/blood.png").await?, + explosion_ground_mark: load_texture("img/explosion_ground_mark.png").await?, + shadow: load_texture("img/shadow.png").await?, }) } } @@ -176,9 +178,9 @@ pub struct IconTextures { impl IconTextures { async fn load() -> ZResult { Ok(Self { - info: load_texture("assets/img/icon_info.png").await?, - end_turn: load_texture("assets/img/icon_end_turn.png").await?, - main_menu: load_texture("assets/img/icon_menu.png").await?, + info: load_texture("img/icon_info.png").await?, + end_turn: load_texture("img/icon_end_turn.png").await?, + main_menu: load_texture("img/icon_menu.png").await?, abilities: load_ability_icons().await?, lasting_effects: load_lasting_effects().await?, }) @@ -192,7 +194,7 @@ async fn load_weapon_flashes() -> ZResult> { (WeaponType::Pierce, "pierce"), (WeaponType::Claw, "claw"), ]; - load_map(map, |s| format!("assets/img/{}.png", s)).await + load_map(map, |s| format!("img/{}.png", s)).await } async fn load_ability_icons() -> ZResult> { @@ -213,7 +215,7 @@ async fn load_ability_icons() -> ZResult> { (Ability::GreatHeal, "great_heal"), (Ability::Bloodlust, "bloodlust"), ]; - load_map(map, |s| format!("assets/img/icon_ability_{}.png", s)).await + load_map(map, |s| format!("img/icon_ability_{}.png", s)).await } async fn load_lasting_effects() -> ZResult> { @@ -222,5 +224,5 @@ async fn load_lasting_effects() -> ZResult> (effect::Lasting::Poison, "poison"), (effect::Lasting::Bloodlust, "bloodlust"), ]; - load_map(map, |s| format!("assets/img/effect_{}.png", s)).await + load_map(map, |s| format!("img/effect_{}.png", s)).await } From 5a92c6fd5d37ae12b0f48cd48fcb9bbbfb6a9c83 Mon Sep 17 00:00:00 2001 From: Fedor Logachev Date: Fri, 14 May 2021 21:32:33 -0500 Subject: [PATCH 05/18] Allow highdpi rendering --- src/main.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index f9e5c894..e659422c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,7 +46,15 @@ impl MainState { } } -#[mq::main("Zemeroth")] +fn window_conf() -> window::Conf { + window::Conf { + window_title: "Zemeroth".to_owned(), + high_dpi: true, + ..Default::default() + } +} + +#[mq::main(window_conf)] #[macroquad(crate_rename = "mq")] async fn main() -> ZResult<()> { // std::env isn't supported on WASM. From d1afadbdc4865d063c96a69abbd136fa9627f37b Mon Sep 17 00:00:00 2001 From: Fedor Logachev Date: Fri, 14 May 2021 22:34:55 -0500 Subject: [PATCH 06/18] Fix clippy warnings Very questionable stuff in this commit, but makes CI happy (hopefully) --- src/core/battle/execute.rs | 4 ++-- src/screen/battle.rs | 3 +-- src/screen/battle/view.rs | 6 +++--- src/screen/battle/visualize.rs | 12 ++++-------- zgui/src/lib.rs | 4 +--- 5 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/core/battle/execute.rs b/src/core/battle/execute.rs index 8f579e23..8c4f5cca 100644 --- a/src/core/battle/execute.rs +++ b/src/core/battle/execute.rs @@ -85,7 +85,7 @@ fn execute_move_to(state: &mut State, cb: Cb, command: &command::MoveTo) { fn do_move(state: &mut State, cb: Cb, id: Id, cost: Option, path: Path) { let cost = cost.unwrap_or(Moves(0)); - let active_event = event::MoveTo { id, path, cost }.into(); + let active_event = event::MoveTo { path, cost, id }.into(); let event = Event { active_event, actor_ids: vec![id], @@ -322,7 +322,7 @@ fn try_execute_passive_abilities_on_begin_turn(state: &mut State, cb: Cb) { continue; } let pos = state.parts().pos.get(id).0; - let active_event = event::UsePassiveAbility { pos, id, ability }.into(); + let active_event = event::UsePassiveAbility { id, pos, ability }.into(); let mut target_effects = Vec::new(); let strength = Strength(1); target_effects.push(effect::Heal { strength }.into()); diff --git a/src/screen/battle.rs b/src/screen/battle.rs index c38c8c95..31ebec6f 100644 --- a/src/screen/battle.rs +++ b/src/screen/battle.rs @@ -404,8 +404,7 @@ impl Battle { utils::remove_widget(&mut self.gui, &mut self.panel_end_turn)?; self.deselect()?; let command = command::EndTurn.into(); - let mut actions = Vec::new(); - actions.push(self.do_command_inner(&command, CommandOrigin::Internal)); + let mut actions = vec![self.do_command_inner(&command, CommandOrigin::Internal)]; actions.push(self.do_ai()); self.add_actions(actions); Ok(()) diff --git a/src/screen/battle/view.rs b/src/screen/battle/view.rs index d0e0bf19..06b91b56 100644 --- a/src/screen/battle/view.rs +++ b/src/screen/battle/view.rs @@ -282,8 +282,8 @@ impl BattleView { s.turns_left.decrease(); let mut color = s.sprite.color(); color.a = (s.initial_alpha / s.turns_total.0 as f32) * s.turns_left.0 as f32; - let mut sub_actions = Vec::new(); - sub_actions.push(action::ChangeColorTo::new(&s.sprite, color, time_s(2.0)).boxed()); + let mut sub_actions = + vec![action::ChangeColorTo::new(&s.sprite, color, time_s(2.0)).boxed()]; if s.turns_left.is_zero() { sub_actions.push(action::Hide::new(&s.layer, &s.sprite).boxed()); } @@ -390,7 +390,7 @@ impl BattleView { let positions = state.map().iter(); for pos in positions { let id = selected_id; - let command = command::UseAbility { id, ability, pos }.into(); + let command = command::UseAbility { id, pos, ability }.into(); if battle::check(state, &command).is_ok() { self.highlight_tile(pos, TILE_COLOR_ABILITY)?; } diff --git a/src/screen/battle/visualize.rs b/src/screen/battle/visualize.rs index cf810f1a..32aebdf9 100644 --- a/src/screen/battle/visualize.rs +++ b/src/screen/battle/visualize.rs @@ -311,8 +311,7 @@ fn show_weapon_flash( sprite.set_centered(true); sprite.set_pos(point); sprite.set_color(invisible); - let mut actions = Vec::new(); - actions.push(action::Show::new(&view.layers().flares, &sprite).boxed()); + let mut actions = vec![action::Show::new(&view.layers().flares, &sprite).boxed()]; if let Some(facing) = facing_opt { actions.push(action::SetFacing::new(&sprite, facing.to_scene_facing()).boxed()); } @@ -525,8 +524,7 @@ pub fn visualize( } fn visualize_pre(state: &State, view: &mut BattleView, event: &Event) -> ZResult> { - let mut actions = Vec::new(); - actions.push(visualize_event(state, view, &event.active_event)?); + let mut actions = vec![visualize_event(state, view, &event.active_event)?]; for &(id, ref effects) in &event.instant_effects { for effect in effects { actions.push(visualize_instant_effect(state, view, id, &effect)?); @@ -719,8 +717,7 @@ fn visualize_event_use_ability_jump( let z = hex_pos_to_z(event.pos); let action_move_shadow = action::MoveBy::new(&sprite_shadow, diff, time).boxed(); let action_dust = show_dust_at_pos(view, event.pos)?; - let mut actions = Vec::new(); - actions.push(action_set_z(&view.layers().objects, &sprite_object, 200.0)); + let mut actions = vec![action_set_z(&view.layers().objects, &sprite_object, 200.0)]; if sprite_object.has_frame("jump") { actions.push(action::SetFrame::new(&sprite_object, "jump").boxed()); } @@ -1171,8 +1168,7 @@ fn visualize_effect_dodge( let pos = state.parts().pos.get(target_id).0; let time_to = time_s(0.05); let time_from = time_s(0.3); - let mut actions = Vec::new(); - actions.push(message(view, pos, "dodged")?); + let mut actions = vec![message(view, pos, "dodged")?]; let point_a = view.hex_to_point(pos); let point_b = view.hex_to_point(effect.attacker_pos); let diff = (point_a - point_b).normalize() * view.tile_size() * 0.5; diff --git a/zgui/src/lib.rs b/zgui/src/lib.rs index 0c223024..946e01d4 100644 --- a/zgui/src/lib.rs +++ b/zgui/src/lib.rs @@ -168,7 +168,6 @@ impl Sprite { font_scale, font_scale_aspect, color: self.color, - ..Default::default() }, ); } @@ -448,8 +447,8 @@ impl Label { sprite, bg, param, - height, rect, + height, }) } @@ -792,7 +791,6 @@ impl Widget for Button { if self.border.rect().contains(pos) { let message = self.message.clone(); self.sender.send(message).unwrap(); - return; } } From 7bc4b588fa4b47ddc84b5419532ca679ff70d84d Mon Sep 17 00:00:00 2001 From: Fedor Logachev Date: Fri, 14 May 2021 22:42:31 -0500 Subject: [PATCH 07/18] Fix examples Some unwraps, maybe introducing ZResult would be a better choice here --- Cargo.lock | 22 +++++++++++++--------- zgui/examples/common/mod.rs | 8 +++++--- zgui/examples/pixel_coordinates.rs | 2 +- zscene/examples/action.rs | 10 +++++++--- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7b375a96..135b6355 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -546,7 +546,9 @@ dependencies = [ [[package]] name = "macroquad" -version = "0.3.3" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d252c1d0c6ccbc9e44b0fdd8fe0b53d316f02811716104daf7b804a1f04a8360" dependencies = [ "bumpalo", "fontdue", @@ -561,6 +563,8 @@ dependencies = [ [[package]] name = "macroquad_macro" version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ecb8935bc6a74b8374439c0bd8d2857ae1499fde9fbba76bb00722f7213b42d" [[package]] name = "memchr" @@ -570,9 +574,9 @@ checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" [[package]] name = "miniquad" -version = "0.3.0-alpha.30" +version = "0.3.0-alpha.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "544f4f479ba6084845f4908abbeb40abb5fe01b171928dca2901852231f3f838" +checksum = "7e26b0198031cdbd234dca807a06294bb2423bee1b5d914a780c649118da0b9d" dependencies = [ "sapp-android", "sapp-darwin", @@ -979,9 +983,9 @@ dependencies = [ [[package]] name = "sapp-android" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cfc3238f9450dba929931ea554552355ff65c4ab2ffd5d291ca5dfcb7cd3193" +checksum = "cb57c363bd1f1afeb1f16207bc425bc5672db23920c1adf1545000fc4d4f84f9" dependencies = [ "cc", ] @@ -1015,18 +1019,18 @@ dependencies = [ [[package]] name = "sapp-linux" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22b66fa7effb2823d80997912186494d4a19aa74d3ac1ff5aa1cfb648537be92" +checksum = "bbdb2f8011955c62544d9e626a58333e788810d00bd7411d52b81611b92af142" dependencies = [ "libc", ] [[package]] name = "sapp-wasm" -version = "0.1.24" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46dc18c2e8b9b9d1a50a8d83944d1e7c309581c99186b52d0530420d108ce37c" +checksum = "00e859e8645a3bcb85aecd40bab883438e4105f21b21bccbeac2348760f508bb" [[package]] name = "sapp-windows" diff --git a/zgui/examples/common/mod.rs b/zgui/examples/common/mod.rs index c970f479..5c2f272e 100644 --- a/zgui/examples/common/mod.rs +++ b/zgui/examples/common/mod.rs @@ -19,7 +19,7 @@ pub fn make_and_set_camera(aspect_ratio: f32) -> Camera2D { h: 2.0, }; let camera = Camera2D::from_display_rect(display_rect); - set_camera(camera); + set_camera(&camera); camera } @@ -34,8 +34,10 @@ pub struct Assets { impl Assets { pub async fn load() -> Self { - let font = load_ttf_font("zgui/assets/Karla-Regular.ttf").await; - let texture = texture::load_texture("zgui/assets/fire.png").await; + let font = load_ttf_font("zgui/assets/Karla-Regular.ttf") + .await + .unwrap(); + let texture = texture::load_texture("zgui/assets/fire.png").await.unwrap(); Self { font, texture } } } diff --git a/zgui/examples/pixel_coordinates.rs b/zgui/examples/pixel_coordinates.rs index 71c5f0fc..da6513fd 100644 --- a/zgui/examples/pixel_coordinates.rs +++ b/zgui/examples/pixel_coordinates.rs @@ -20,7 +20,7 @@ pub fn make_and_set_camera(_aspect_ratio: f32) -> Camera2D { h: mq::window::screen_height(), }; let camera = Camera2D::from_display_rect(display_rect); - set_camera(camera); + set_camera(&camera); camera } diff --git a/zscene/examples/action.rs b/zscene/examples/action.rs index b88fba0f..bcb1cbd6 100644 --- a/zscene/examples/action.rs +++ b/zscene/examples/action.rs @@ -29,8 +29,12 @@ struct Assets { impl Assets { async fn load() -> Self { - let font = text::load_ttf_font("zscene/assets/Karla-Regular.ttf").await; - let texture = texture::load_texture("zscene/assets/fire.png").await; + let font = text::load_ttf_font("zscene/assets/Karla-Regular.ttf") + .await + .unwrap(); + let texture = texture::load_texture("zscene/assets/fire.png") + .await + .unwrap(); Self { font, texture } } } @@ -92,7 +96,7 @@ impl State { fn update_aspect_ratio() { let aspect_ratio = window::screen_width() / window::screen_height(); let coordinates = Rect::new(-aspect_ratio, -1.0, aspect_ratio * 2.0, 2.0); - set_camera(Camera2D::from_display_rect(coordinates)); + set_camera(&Camera2D::from_display_rect(coordinates)); } #[mq::main("ZScene: Actions Demo")] From d1ac9f5120d68fc905f36cb77fbba6afe78fcc57 Mon Sep 17 00:00:00 2001 From: Fedor Logachev Date: Fri, 28 May 2021 20:41:23 -0500 Subject: [PATCH 08/18] Fix text rendering on floating labels and popups --- src/screen/battle/view.rs | 4 ++-- src/screen/battle/visualize.rs | 12 ++++++------ zscene/examples/action.rs | 3 +-- zscene/src/sprite.rs | 3 ++- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/screen/battle/view.rs b/src/screen/battle/view.rs index 06b91b56..6a971c59 100644 --- a/src/screen/battle/view.rs +++ b/src/screen/battle/view.rs @@ -16,7 +16,7 @@ use crate::{ }, geom::{self, hex_to_point}, screen::battle::visualize, - utils::{font_size, time_s}, + utils::time_s, ZResult, }; @@ -483,7 +483,7 @@ impl BattleView { let pos = hex_to_point(self.tile_size(), target_pos); let text = format!("{}%", chances.1 * 10); let font = assets::get().font; - let mut sprite = Sprite::from_text((text.as_str(), font, font_size()), 0.1); + let mut sprite = Sprite::from_text((text.as_str(), font), 0.1); sprite.set_pos(pos); sprite.set_centered(true); sprite.set_color([0.0, 0.0, 0.0, 1.0].into()); diff --git a/src/screen/battle/visualize.rs b/src/screen/battle/visualize.rs index 32aebdf9..cd3b9cb8 100644 --- a/src/screen/battle/visualize.rs +++ b/src/screen/battle/visualize.rs @@ -24,7 +24,7 @@ use crate::{ }, geom, screen::battle::view::BattleView, - utils::{font_size, time_s}, + utils::time_s, ZResult, }; @@ -72,9 +72,8 @@ fn textures() -> &'static assets::Textures { pub fn message(view: &mut BattleView, pos: PosHex, text: &str) -> ZResult> { let visible = [0.0, 0.0, 0.0, 1.0].into(); let invisible = Color::new(0.0, 0.0, 0.0, 0.0); - let font_size = font_size(); let font = assets::get().font; - let mut sprite = Sprite::from_text((text, font, font_size), 0.1); + let mut sprite = Sprite::from_text((text, font), 0.1); sprite.set_centered(true); let point = view.hex_to_point(pos); let point = point - Vec2::new(0.0, view.tile_size() * 1.5); @@ -121,7 +120,9 @@ fn announce(view: &mut BattleView, text: &str, time: Duration) -> ZResult ZResult ZResult> { let visible = [0.0, 0.0, 0.0, 1.0].into(); let invisible = [0.0, 0.0, 0.0, 0.0].into(); - let font_size = font_size(); let font = assets::get().font; - let mut sprite = Sprite::from_text((text, font, font_size), 0.1); + let mut sprite = Sprite::from_text((text, font), 0.1); sprite.set_centered(true); let point = pos + Vec2::new(0.0, view.tile_size() * 0.5); sprite.set_pos(point); diff --git a/zscene/examples/action.rs b/zscene/examples/action.rs index bcb1cbd6..297e74ff 100644 --- a/zscene/examples/action.rs +++ b/zscene/examples/action.rs @@ -70,8 +70,7 @@ impl State { fn action_demo_show_hide(&self) -> Box { let mut sprite = { - let font_size = 32; - let mut sprite = Sprite::from_text(("some text", self.assets.font, font_size), 0.1); + let mut sprite = Sprite::from_text(("some text", self.assets.font), 0.1); sprite.set_pos(Vec2::new(0.0, 0.0)); sprite.set_scale(2.0); // just testing set_size method let scale = sprite.scale(); diff --git a/zscene/src/sprite.rs b/zscene/src/sprite.rs index f0763718..6abc25e4 100644 --- a/zscene/src/sprite.rs +++ b/zscene/src/sprite.rs @@ -107,7 +107,8 @@ impl Sprite { Self::from_drawable(Drawable::Texture(texture), height) } - pub fn from_text((label, font, font_size): (&str, Font, u16), height: f32) -> Self { + pub fn from_text((label, font): (&str, Font), height: f32) -> Self { + let (font_size, _, _) = mq::text::camera_font_scale(height); Self::from_drawable( Drawable::Text { label: label.to_string(), From fd52b4c2f25dd77ceb08ce2086660ecbb7f35c6b Mon Sep 17 00:00:00 2001 From: Andrey Lesnikov Date: Tue, 1 Jun 2021 10:02:30 +0300 Subject: [PATCH 09/18] Style tweaks for consistency --- Cargo.toml | 1 - src/core/campaign.rs | 4 ++-- src/main.rs | 2 +- src/screen/battle.rs | 6 ++++-- src/screen/battle/view.rs | 4 ++-- src/screen/battle/visualize.rs | 2 -- zgui/src/lib.rs | 2 -- 7 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 96f719b6..f52655f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,4 +33,3 @@ once_cell = "1.6" [dev-dependencies] pretty_assertions = "0.6" - diff --git a/src/core/campaign.rs b/src/core/campaign.rs index 39660e0f..fdb15216 100644 --- a/src/core/campaign.rs +++ b/src/core/campaign.rs @@ -333,8 +333,8 @@ mod tests { vec![node] }; Plan { - nodes, initial_agents, + nodes, } } @@ -372,8 +372,8 @@ mod tests { }, ]; Plan { - nodes, initial_agents, + nodes, } } diff --git a/src/main.rs b/src/main.rs index e659422c..7c9ac5cb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,7 +56,7 @@ fn window_conf() -> window::Conf { #[mq::main(window_conf)] #[macroquad(crate_rename = "mq")] -async fn main() -> ZResult<()> { +async fn main() -> ZResult { // std::env isn't supported on WASM. #[cfg(not(target_arch = "wasm32"))] if std::env::var("RUST_BACKTRACE").is_err() { diff --git a/src/screen/battle.rs b/src/screen/battle.rs index 31ebec6f..5c2115c3 100644 --- a/src/screen/battle.rs +++ b/src/screen/battle.rs @@ -404,8 +404,10 @@ impl Battle { utils::remove_widget(&mut self.gui, &mut self.panel_end_turn)?; self.deselect()?; let command = command::EndTurn.into(); - let mut actions = vec![self.do_command_inner(&command, CommandOrigin::Internal)]; - actions.push(self.do_ai()); + let actions = vec![ + self.do_command_inner(&command, CommandOrigin::Internal), + self.do_ai(), + ]; self.add_actions(actions); Ok(()) } diff --git a/src/screen/battle/view.rs b/src/screen/battle/view.rs index 6a971c59..d2d3d395 100644 --- a/src/screen/battle/view.rs +++ b/src/screen/battle/view.rs @@ -282,8 +282,8 @@ impl BattleView { s.turns_left.decrease(); let mut color = s.sprite.color(); color.a = (s.initial_alpha / s.turns_total.0 as f32) * s.turns_left.0 as f32; - let mut sub_actions = - vec![action::ChangeColorTo::new(&s.sprite, color, time_s(2.0)).boxed()]; + let change_color = action::ChangeColorTo::new(&s.sprite, color, time_s(2.0)).boxed(); + let mut sub_actions = vec![change_color]; if s.turns_left.is_zero() { sub_actions.push(action::Hide::new(&s.layer, &s.sprite).boxed()); } diff --git a/src/screen/battle/visualize.rs b/src/screen/battle/visualize.rs index cd3b9cb8..7517abd4 100644 --- a/src/screen/battle/visualize.rs +++ b/src/screen/battle/visualize.rs @@ -120,9 +120,7 @@ fn announce(view: &mut BattleView, text: &str, time: Duration) -> ZResult { // desired font size in camera space let font_world_size = font_size as f32 * self.scale.x; - // let macroquad figure appropriate TextParams for currently active camera let (font_size, font_scale, font_scale_aspect) = camera_font_scale(font_world_size); - draw_text_ex( label, self.pos.x, From d259e14c09ceab0ff9ac998322b7846b40a7f3b1 Mon Sep 17 00:00:00 2001 From: Andrey Lesnikov Date: Thu, 3 Jun 2021 09:01:30 +0300 Subject: [PATCH 10/18] Fix zscene's example --- zscene/examples/action.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/zscene/examples/action.rs b/zscene/examples/action.rs index 297e74ff..40920f91 100644 --- a/zscene/examples/action.rs +++ b/zscene/examples/action.rs @@ -49,6 +49,7 @@ impl State { fn new(assets: Assets) -> Self { let layers = Layers::default(); let scene = Scene::new(layers.clone().sorted()); + update_aspect_ratio(); Self { assets, scene, From d5df0c04c1ba6a2612a2e4560fe3e389ac0d19f5 Mon Sep 17 00:00:00 2001 From: Andrey Lesnikov Date: Thu, 3 Jun 2021 09:05:30 +0300 Subject: [PATCH 11/18] main.rs: Put expect on assets::load result --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 7c9ac5cb..8363e549 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,7 +64,7 @@ async fn main() -> ZResult { } env_logger::init(); quad_rand::srand(mq::miniquad::date::now() as _); - assets::load().await?; + assets::load().await.expect("Can't load assets"); let mut state = MainState::new().expect("Can't create the main state"); loop { state.tick().expect("Tick failed"); From 193c99abb5c3529797187c0787d2f83fbd058e5a Mon Sep 17 00:00:00 2001 From: Andrey Lesnikov Date: Fri, 4 Jun 2021 22:14:08 +0300 Subject: [PATCH 12/18] CI: cargo clippy --all --tests --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 852ede69..80881ef4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: - run: cargo fmt --all -- --check - - run: cargo clippy -- -D warnings + - run: cargo clippy --all --tests -- -D warnings build: name: ${{ matrix.build }} From 4d126b4d4a2ff982ccb0ba59e5b0fd18e661b10b Mon Sep 17 00:00:00 2001 From: Andrey Lesnikov Date: Sat, 5 Jun 2021 08:40:32 +0300 Subject: [PATCH 13/18] Move set_pc_assets_folder to main.rs --- src/assets.rs | 2 -- src/main.rs | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/assets.rs b/src/assets.rs index 045c7b3d..46e439ac 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -93,8 +93,6 @@ pub struct Assets { impl Assets { pub async fn load() -> ZResult { - file::set_pc_assets_folder("assets"); - let sprites_info: SpritesInfo = deserialize_from_file("sprites.ron").await?; let sprite_frames = { let mut sprite_frames = HashMap::new(); diff --git a/src/main.rs b/src/main.rs index 8363e549..87c1db51 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,6 +64,7 @@ async fn main() -> ZResult { } env_logger::init(); quad_rand::srand(mq::miniquad::date::now() as _); + mq::file::set_pc_assets_folder("assets"); assets::load().await.expect("Can't load assets"); let mut state = MainState::new().expect("Can't create the main state"); loop { From e9809a88e318e440119d78f0f1d0ed59b55fa7c4 Mon Sep 17 00:00:00 2001 From: Andrey Lesnikov Date: Sat, 5 Jun 2021 08:40:52 +0300 Subject: [PATCH 14/18] assets.rs: Fix import --- src/assets.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assets.rs b/src/assets.rs index 46e439ac..352b9a18 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -6,7 +6,7 @@ use std::{collections::HashMap, hash::Hash}; use mq::{ - file::{self, load_file}, + file::load_file, text::{self, Font}, texture::{load_texture, Texture2D}, }; From 77a0da65f00f4412939ae7ba0d19698a88f04ee0 Mon Sep 17 00:00:00 2001 From: Andrey Lesnikov Date: Sun, 6 Jun 2021 19:49:13 +0300 Subject: [PATCH 15/18] zscene: Add Err enum to action.rs example Looks nicer this way than with individual unwraps --- zscene/examples/action.rs | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/zscene/examples/action.rs b/zscene/examples/action.rs index 40920f91..d028487b 100644 --- a/zscene/examples/action.rs +++ b/zscene/examples/action.rs @@ -10,6 +10,24 @@ use mq::{ }; use zscene::{self, action, Action, Boxed, Layer, Scene, Sprite}; +#[derive(Debug)] +pub enum Err { + File(mq::file::FileError), + Font(mq::text::FontError), +} + +impl From for Err { + fn from(err: mq::file::FileError) -> Self { + Err::File(err) + } +} + +impl From for Err { + fn from(err: mq::text::FontError) -> Self { + Err::Font(err) + } +} + #[derive(Debug, Clone, Default)] pub struct Layers { pub bg: Layer, @@ -28,14 +46,10 @@ struct Assets { } impl Assets { - async fn load() -> Self { - let font = text::load_ttf_font("zscene/assets/Karla-Regular.ttf") - .await - .unwrap(); - let texture = texture::load_texture("zscene/assets/fire.png") - .await - .unwrap(); - Self { font, texture } + async fn load() -> Result { + let font = text::load_ttf_font("zscene/assets/Karla-Regular.ttf").await?; + let texture = texture::load_texture("zscene/assets/fire.png").await?; + Ok(Self { font, texture }) } } @@ -102,7 +116,7 @@ fn update_aspect_ratio() { #[mq::main("ZScene: Actions Demo")] #[macroquad(crate_rename = "mq")] async fn main() { - let assets = Assets::load().await; + let assets = Assets::load().await.expect("Can't load assets"); let mut state = State::new(assets); { // Run two demo demo actions in parallel. From d603e6a33e99d2f8e7846597821392069a5f1e30 Mon Sep 17 00:00:00 2001 From: Andrey Lesnikov Date: Sun, 6 Jun 2021 19:50:04 +0300 Subject: [PATCH 16/18] zgui: Add Err enum to examples --- zgui/examples/absolute_coordinates.rs | 2 +- zgui/examples/common/mod.rs | 28 +++++++++++++++++++++------ zgui/examples/layers_layout.rs | 2 +- zgui/examples/nested.rs | 2 +- zgui/examples/pixel_coordinates.rs | 2 +- zgui/examples/remove.rs | 2 +- zgui/examples/text_button.rs | 2 +- 7 files changed, 28 insertions(+), 12 deletions(-) diff --git a/zgui/examples/absolute_coordinates.rs b/zgui/examples/absolute_coordinates.rs index 286066a6..9597b4d7 100644 --- a/zgui/examples/absolute_coordinates.rs +++ b/zgui/examples/absolute_coordinates.rs @@ -29,7 +29,7 @@ fn draw_scene() { #[mq::main("ZGui: Absolute Coordinates Demo")] #[macroquad(crate_rename = "mq")] async fn main() { - let assets = common::Assets::load().await; + let assets = common::Assets::load().await.expect("Can't load assets"); let mut gui = make_gui(assets.font).expect("Can't create the gui"); loop { // Update the camera and the GUI. diff --git a/zgui/examples/common/mod.rs b/zgui/examples/common/mod.rs index 5c2f272e..196d95af 100644 --- a/zgui/examples/common/mod.rs +++ b/zgui/examples/common/mod.rs @@ -7,6 +7,24 @@ use mq::{ texture::{self, Texture2D}, }; +#[derive(Debug)] +pub enum Err { + File(mq::file::FileError), + Font(mq::text::FontError), +} + +impl From for Err { + fn from(err: mq::file::FileError) -> Self { + Err::File(err) + } +} + +impl From for Err { + fn from(err: mq::text::FontError) -> Self { + Err::Font(err) + } +} + pub fn aspect_ratio() -> f32 { mq::window::screen_width() / mq::window::screen_height() } @@ -33,11 +51,9 @@ pub struct Assets { } impl Assets { - pub async fn load() -> Self { - let font = load_ttf_font("zgui/assets/Karla-Regular.ttf") - .await - .unwrap(); - let texture = texture::load_texture("zgui/assets/fire.png").await.unwrap(); - Self { font, texture } + pub async fn load() -> Result { + let font = load_ttf_font("zgui/assets/Karla-Regular.ttf").await?; + let texture = texture::load_texture("zgui/assets/fire.png").await?; + Ok(Self { font, texture }) } } diff --git a/zgui/examples/layers_layout.rs b/zgui/examples/layers_layout.rs index d4afddbf..fac68ea9 100644 --- a/zgui/examples/layers_layout.rs +++ b/zgui/examples/layers_layout.rs @@ -26,7 +26,7 @@ fn make_gui(assets: common::Assets) -> ui::Result> { #[mq::main("ZGui: Layers Layout Demo")] #[macroquad(crate_rename = "mq")] async fn main() { - let assets = common::Assets::load().await; + let assets = common::Assets::load().await.expect("Can't load assets"); let mut gui = make_gui(assets).expect("Can't create the gui"); loop { // Update the camera and the GUI. diff --git a/zgui/examples/nested.rs b/zgui/examples/nested.rs index 569f9432..b46c43a9 100644 --- a/zgui/examples/nested.rs +++ b/zgui/examples/nested.rs @@ -70,7 +70,7 @@ fn make_gui(assets: common::Assets) -> ui::Result> { #[mq::main("ZGui: Nested Layouts Demo")] #[macroquad(crate_rename = "mq")] async fn main() { - let assets = common::Assets::load().await; + let assets = common::Assets::load().await.expect("Can't load assets"); let mut gui = make_gui(assets).expect("Can't create the gui"); loop { // Update the camera and the GUI. diff --git a/zgui/examples/pixel_coordinates.rs b/zgui/examples/pixel_coordinates.rs index da6513fd..ede486df 100644 --- a/zgui/examples/pixel_coordinates.rs +++ b/zgui/examples/pixel_coordinates.rs @@ -45,7 +45,7 @@ fn draw_scene() { #[mq::main("ZGui: Pixel Coordinates Demo")] #[macroquad(crate_rename = "mq")] async fn main() { - let assets = common::Assets::load().await; + let assets = common::Assets::load().await.expect("Can't load assets"); let mut gui = make_gui(assets.font).expect("Can't create the gui"); loop { // Update the camera and the GUI. diff --git a/zgui/examples/remove.rs b/zgui/examples/remove.rs index 3e5821ea..ea2905be 100644 --- a/zgui/examples/remove.rs +++ b/zgui/examples/remove.rs @@ -68,7 +68,7 @@ impl State { #[mq::main("ZGui: Remove Widget Demo")] #[macroquad(crate_rename = "mq")] async fn main() { - let assets = common::Assets::load().await; + let assets = common::Assets::load().await.expect("Can't load assets"); let mut state = State::new(assets).expect("Can't create the game state"); loop { // Update the camera and the GUI. diff --git a/zgui/examples/text_button.rs b/zgui/examples/text_button.rs index b51fa815..62318c85 100644 --- a/zgui/examples/text_button.rs +++ b/zgui/examples/text_button.rs @@ -21,7 +21,7 @@ fn make_gui(font: mq::text::Font) -> ui::Result> { #[mq::main("ZGui: Text Button Demo")] #[macroquad(crate_rename = "mq")] async fn main() { - let assets = common::Assets::load().await; + let assets = common::Assets::load().await.expect("Can't load assets"); let mut gui = make_gui(assets.font).expect("Can't create the gui"); loop { // Update the camera and the GUI. From 584da23783f402554339252a44e2e077a8340fd5 Mon Sep 17 00:00:00 2001 From: Andrey Lesnikov Date: Sun, 6 Jun 2021 19:52:17 +0300 Subject: [PATCH 17/18] zgui: Remove Drawable::text's font_size arg And put a few TODOs --- src/screen/agent_info.rs | 6 +++--- src/screen/battle.rs | 13 +++++-------- src/screen/campaign.rs | 10 ++++------ src/screen/confirm.rs | 6 ++---- src/screen/general_info.rs | 3 +-- src/screen/main_menu.rs | 3 +-- src/utils.rs | 5 ----- zgui/examples/absolute_coordinates.rs | 3 +-- zgui/examples/layers_layout.rs | 3 +-- zgui/examples/nested.rs | 3 +-- zgui/examples/pixel_coordinates.rs | 3 +-- zgui/examples/remove.rs | 3 +-- zgui/examples/text_button.rs | 3 +-- zgui/src/lib.rs | 7 +++++-- zscene/src/sprite.rs | 1 + 15 files changed, 28 insertions(+), 44 deletions(-) diff --git a/src/screen/agent_info.rs b/src/screen/agent_info.rs index c4fff960..c10df978 100644 --- a/src/screen/agent_info.rs +++ b/src/screen/agent_info.rs @@ -84,7 +84,7 @@ fn info_panel( let mut layout = Box::new(ui::VLayout::new().stretchable(true)); layout.add(agent_image(typename)?); let mut add = |w| layout.add(w); - let text_ = |s: &str| ui::Drawable::text(s, font, utils::font_size()); + let text_ = |s: &str| ui::Drawable::text(s, font); let label_ = |text: &str| -> ZResult<_> { Ok(ui::Label::new(text_(text), h)?) }; let label = |text: &str| -> ZResult> { Ok(Box::new(label_(text)?)) }; let label_s = |text: &str| -> ZResult<_> { Ok(Box::new(label_(text)?.stretchable(true))) }; @@ -181,7 +181,7 @@ fn info_panel( fn button_back(gui: &mut ui::Gui, layout_width: f32) -> ZResult> { let font = assets::get().font; let h = utils::line_heights().normal; - let text = ui::Drawable::text("back", font, utils::font_size()); + let text = ui::Drawable::text("back", font); let msg = Message::Back; let mut button = ui::Button::new(text, h, gui.sender(), msg)?.stretchable(true); button.stretch(layout_width / 3.0); @@ -226,7 +226,7 @@ impl AgentInfo { let col = { let mut col = Box::new(ui::VLayout::new()); col.add(Box::new(ui::Spacer::new_vertical(panel_from_height * 0.5))); - let text = ui::Drawable::text("=>", font, utils::font_size()); + let text = ui::Drawable::text("=>", font); col.add(Box::new(ui::Label::new(text, h)?)); col }; diff --git a/src/screen/battle.rs b/src/screen/battle.rs index 5c2115c3..d945fc96 100644 --- a/src/screen/battle.rs +++ b/src/screen/battle.rs @@ -43,8 +43,6 @@ use crate::{ mod view; mod visualize; -const FONT_SIZE: u16 = utils::font_size(); - #[derive(Clone, Debug)] enum Message { Exit, @@ -65,11 +63,10 @@ fn line_with_info_button( ) -> ZResult> { let h = line_heights().normal; let font = assets::get().font; - let text = ui::Drawable::text(text, font, FONT_SIZE); let icon = textures().icons.info; let button = ui::Button::new(ui::Drawable::Texture(icon), h, gui.sender(), message)?; let mut line = Box::new(ui::HLayout::new().stretchable(true)); - line.add(Box::new(ui::Label::new(text, h)?)); + line.add(Box::new(ui::Label::new(ui::Drawable::text(text, font), h)?)); line.add(Box::new(ui::Spacer::new_horizontal(0.0).stretchable(true))); line.add(Box::new(button)); Ok(line) @@ -86,7 +83,7 @@ fn build_panel_agent_info(gui: &mut Gui, state: &State, id: Id) -> ZRes let h = line_heights().normal; let space_between_buttons = h / 8.0; let mut add = |w| layout.add(w); - let text_ = |s: &str| ui::Drawable::text(s, font, FONT_SIZE); + let text_ = |s: &str| ui::Drawable::text(s, font); let label_ = |text: &str| -> ZResult<_> { Ok(ui::Label::new(text_(text), h)?) }; let label = |text: &str| -> ZResult> { Ok(Box::new(label_(text)?)) }; let label_s = |text: &str| -> ZResult<_> { Ok(Box::new(label_(text)?.stretchable(true))) }; @@ -188,7 +185,7 @@ fn build_panel_agent_info(gui: &mut Gui, state: &State, id: Id) -> ZRes effect::Duration::Rounds(n) => format!("{} ({}t)", s, n), }; let message = Message::LastingEffectInfo(effect.effect); - let text = ui::Drawable::text(text, font, FONT_SIZE); + let text = ui::Drawable::text(text, font); let tex_info = ui::Drawable::Texture(textures().icons.info); let button_info = ui::Button::new(tex_info, h, gui.sender(), message)?; let icon_effect = visualize::get_effect_icon(&effect.effect); @@ -250,7 +247,7 @@ fn build_panel_agent_abilities( if let ability::Status::Cooldown(n) = ability.status { let mut layers = ui::LayersLayout::new(); layers.add(Box::new(button)); - let text = ui::Drawable::text(format!(" ({})", n).as_str(), font, FONT_SIZE); + let text = ui::Drawable::text(format!(" ({})", n).as_str(), font); let label = ui::Label::new(text, h / 2.0)?; layers.add(Box::new(label)); layout.add(Box::new(layers)); @@ -283,7 +280,7 @@ fn build_panel_ability_description( id: Id, ) -> ZResult { let font = assets::get().font; - let text = |s: &str| ui::Drawable::text(s, font, FONT_SIZE); + let text = |s: &str| ui::Drawable::text(s, font); let h = line_heights().normal; let mut layout = Box::new(ui::VLayout::new().stretchable(true)); let text_title = text(&format!("~~~ {} ~~~", ability.title())); diff --git a/src/screen/campaign.rs b/src/screen/campaign.rs index 9e0116af..fe4742eb 100644 --- a/src/screen/campaign.rs +++ b/src/screen/campaign.rs @@ -32,8 +32,6 @@ enum Message { Action(Action), } -const FONT_SIZE: u16 = utils::font_size(); - // The main line height of this screen. fn line_height() -> f32 { utils::line_heights().normal @@ -133,7 +131,7 @@ fn build_panel_actions(gui: &mut ui::Gui, state: &State) -> ZResult, state: &State) -> ZResult, state: &State) -> ZResult ZResult> { - let text = ui::Drawable::text(text, font, FONT_SIZE); + let text = ui::Drawable::text(text, font); Ok(Box::new(ui::Label::new(text, line_height())?)) } @@ -256,7 +254,7 @@ impl Campaign { fn add_label_central_message(&mut self, text: &str) -> ZResult { let font = assets::get().font; let h = utils::line_heights().large; - let text = ui::Drawable::text(text, font, FONT_SIZE); + let text = ui::Drawable::text(text, font); let label = ui::pack(ui::Label::new_with_bg(text, h)?); let anchor = ui::Anchor(ui::HAnchor::Middle, ui::VAnchor::Middle); self.gui.add(&label, anchor); diff --git a/src/screen/confirm.rs b/src/screen/confirm.rs index 8a11f90a..6413c9f8 100644 --- a/src/screen/confirm.rs +++ b/src/screen/confirm.rs @@ -33,10 +33,9 @@ impl Confirm { pub fn from_lines(lines: &[impl AsRef], sender: Sender) -> ZResult { let font = assets::get().font; let h = utils::line_heights().big; - let font_size = utils::font_size(); let mut layout = ui::VLayout::new(); for line in lines { - let text = ui::Drawable::text(line.as_ref(), font, font_size); + let text = ui::Drawable::text(line.as_ref(), font); let label = Box::new(ui::Label::new(text, h)?); layout.add(label); } @@ -51,11 +50,10 @@ impl Confirm { let font = assets::get().font; let mut gui = ui::Gui::new(); let h = utils::line_heights().big; - let font_size = utils::font_size(); let mut layout = Box::new(ui::VLayout::new()); let spacer = || Box::new(ui::Spacer::new_vertical(h * 0.5)); let button = |line, message| -> ZResult<_> { - let text = ui::Drawable::text(line, font, font_size); + let text = ui::Drawable::text(line, font); let b = ui::Button::new(text, h, gui.sender(), message)?.stretchable(true); Ok(b) }; diff --git a/src/screen/general_info.rs b/src/screen/general_info.rs index 0d8cfc26..abafcd26 100644 --- a/src/screen/general_info.rs +++ b/src/screen/general_info.rs @@ -24,9 +24,8 @@ impl GeneralInfo { let font = assets::get().font; let mut gui = ui::Gui::new(); let h = utils::line_heights().normal; - let font_size = utils::font_size(); let mut layout = Box::new(ui::VLayout::new().stretchable(true)); - let text_ = |s: &str| ui::Drawable::text(s, font, font_size); + let text_ = |s: &str| ui::Drawable::text(s, font); let label_ = |text: &str| -> ZResult<_> { Ok(ui::Label::new(text_(text), h)?) }; let label = |text: &str| -> ZResult<_> { Ok(Box::new(label_(text)?)) }; let label_s = |text: &str| -> ZResult<_> { Ok(Box::new(label_(text)?.stretchable(true))) }; diff --git a/src/screen/main_menu.rs b/src/screen/main_menu.rs index 3a6c1166..7def0b9d 100644 --- a/src/screen/main_menu.rs +++ b/src/screen/main_menu.rs @@ -25,10 +25,9 @@ fn make_gui() -> ZResult> { let font = assets::get().font; let mut gui = ui::Gui::new(); let h = utils::line_heights().large; - let font_size = utils::font_size(); let space = || Box::new(ui::Spacer::new_vertical(h / 8.0)); let button = &mut |text, message| -> ZResult<_> { - let text = ui::Drawable::text(text, font, font_size); + let text = ui::Drawable::text(text, font); let b = ui::Button::new(text, h, gui.sender(), message)?.stretchable(true); Ok(Box::new(b)) }; diff --git a/src/utils.rs b/src/utils.rs index a88198b1..69c7ca58 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -12,11 +12,6 @@ pub fn time_s(s: f32) -> Duration { Duration::from_millis(ms as u64) } -// TODO: Move to some config (https://github.com/ozkriff/zemeroth/issues/424) -pub const fn font_size() -> u16 { - 20 -} - pub struct LineHeights { pub small: f32, pub normal: f32, diff --git a/zgui/examples/absolute_coordinates.rs b/zgui/examples/absolute_coordinates.rs index 9597b4d7..535b29f2 100644 --- a/zgui/examples/absolute_coordinates.rs +++ b/zgui/examples/absolute_coordinates.rs @@ -9,10 +9,9 @@ enum Message { } fn make_gui(font: mq::text::Font) -> ui::Result> { - let font_size = 64; let mut gui = ui::Gui::new(); let anchor = ui::Anchor(ui::HAnchor::Right, ui::VAnchor::Bottom); - let text = ui::Drawable::text("Button", font, font_size); + let text = ui::Drawable::text("Button", font); let button = ui::Button::new(text, 0.2, gui.sender(), Message::Command)?; gui.add(&ui::pack(button), anchor); Ok(gui) diff --git a/zgui/examples/layers_layout.rs b/zgui/examples/layers_layout.rs index fac68ea9..55a431da 100644 --- a/zgui/examples/layers_layout.rs +++ b/zgui/examples/layers_layout.rs @@ -9,9 +9,8 @@ enum Message { } fn make_gui(assets: common::Assets) -> ui::Result> { - let font_size = 64; let mut gui = ui::Gui::new(); - let text = ui::Drawable::text(" text", assets.font, font_size); + let text = ui::Drawable::text(" text", assets.font); let texture = ui::Drawable::Texture(assets.texture); let button = ui::Button::new(texture, 0.2, gui.sender(), Message::Command)?; let label = ui::Label::new(text, 0.1)?; diff --git a/zgui/examples/nested.rs b/zgui/examples/nested.rs index b46c43a9..8f516d19 100644 --- a/zgui/examples/nested.rs +++ b/zgui/examples/nested.rs @@ -15,8 +15,7 @@ enum Message { } fn make_gui(assets: common::Assets) -> ui::Result> { - let font_size = 64; - let text = |s| ui::Drawable::text(s, assets.font, font_size); + let text = |s| ui::Drawable::text(s, assets.font); let texture = || ui::Drawable::Texture(assets.texture); let mut gui = ui::Gui::new(); { diff --git a/zgui/examples/pixel_coordinates.rs b/zgui/examples/pixel_coordinates.rs index ede486df..685c8d79 100644 --- a/zgui/examples/pixel_coordinates.rs +++ b/zgui/examples/pixel_coordinates.rs @@ -25,10 +25,9 @@ pub fn make_and_set_camera(_aspect_ratio: f32) -> Camera2D { } fn make_gui(font: mq::text::Font) -> ui::Result> { - let font_size = 64; let mut gui = ui::Gui::new(); let anchor = ui::Anchor(ui::HAnchor::Right, ui::VAnchor::Bottom); - let text = ui::Drawable::text("Button", font, font_size); + let text = ui::Drawable::text("Button", font); let button = ui::Button::new(text, 0.2, gui.sender(), Message::Command)?; gui.add(&ui::pack(button), anchor); Ok(gui) diff --git a/zgui/examples/remove.rs b/zgui/examples/remove.rs index ea2905be..9ed55bb1 100644 --- a/zgui/examples/remove.rs +++ b/zgui/examples/remove.rs @@ -9,10 +9,9 @@ enum Message { } fn make_gui(font: mq::text::Font) -> ui::Result> { - let font_size = 64; let mut gui = ui::Gui::new(); let anchor = ui::Anchor(ui::HAnchor::Right, ui::VAnchor::Bottom); - let text = ui::Drawable::text("Button", font, font_size); + let text = ui::Drawable::text("Button", font); let button = ui::Button::new(text, 0.2, gui.sender(), Message::AddOrRemove)?; gui.add(&ui::pack(button), anchor); Ok(gui) diff --git a/zgui/examples/text_button.rs b/zgui/examples/text_button.rs index 62318c85..1aa287af 100644 --- a/zgui/examples/text_button.rs +++ b/zgui/examples/text_button.rs @@ -9,10 +9,9 @@ enum Message { } fn make_gui(font: mq::text::Font) -> ui::Result> { - let font_size = 64; let mut gui = ui::Gui::new(); let anchor = ui::Anchor(ui::HAnchor::Right, ui::VAnchor::Bottom); - let text = ui::Drawable::text("Button", font, font_size); + let text = ui::Drawable::text("Button", font); let button = ui::Button::new(text, 0.2, gui.sender(), Message::Command)?; gui.add(&ui::pack(button), anchor); Ok(gui) diff --git a/zgui/src/lib.rs b/zgui/src/lib.rs index d9cfc8b5..0f2647b1 100644 --- a/zgui/src/lib.rs +++ b/zgui/src/lib.rs @@ -78,11 +78,14 @@ pub enum Drawable { } impl Drawable { - pub fn text(label: impl Into, font: Font, font_size: u16) -> Drawable { + pub fn text(label: impl Into, font: Font) -> Drawable { Drawable::Text { label: label.into(), font, - font_size, + // TODO: this field doesn't mean much with new macroquad since + // we're using camera_font_scale vefore rendering it anyway. + // But it's somewhat tricky to remove this so I'm putting this constant here for now. + font_size: 128, } } diff --git a/zscene/src/sprite.rs b/zscene/src/sprite.rs index 6abc25e4..c969e709 100644 --- a/zscene/src/sprite.rs +++ b/zscene/src/sprite.rs @@ -108,6 +108,7 @@ impl Sprite { } pub fn from_text((label, font): (&str, Font), height: f32) -> Self { + // TODO: it'd be cool to move this to the drawing method (same as in zgui) let (font_size, _, _) = mq::text::camera_font_scale(height); Self::from_drawable( Drawable::Text { From 6b529081324b95873d17901b9a530319d7acf993 Mon Sep 17 00:00:00 2001 From: Andrey Lesnikov Date: Sun, 6 Jun 2021 20:26:25 +0300 Subject: [PATCH 18/18] execute.rs: More clippy fixes --- src/core/battle/execute.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/core/battle/execute.rs b/src/core/battle/execute.rs index 8c4f5cca..456487a0 100644 --- a/src/core/battle/execute.rs +++ b/src/core/battle/execute.rs @@ -1260,14 +1260,12 @@ mod tests { ..Default::default() }; let effect_dodge = effect::Dodge { attacker_pos }; - let mut instant_effects2 = Vec::new(); - instant_effects2.push((Id(0), vec![Effect::Vanish, effect_dodge.clone().into()])); + let instant_effects2 = vec![(Id(0), vec![Effect::Vanish, effect_dodge.clone().into()])]; let context2 = ExecuteContext { instant_effects: instant_effects2, ..Default::default() }; - let mut instant_effects_expected = Vec::new(); - instant_effects_expected.push(( + let instant_effects_expected = vec![( Id(0), vec![ effect_kill, @@ -1275,7 +1273,7 @@ mod tests { Effect::Vanish, effect_dodge.into(), ], - )); + )]; let context_expected = ExecuteContext { instant_effects: instant_effects_expected, ..Default::default()