mindustry logic execution, map- and schematic- parsing and rendering
-rw-r--r--mindus/Cargo.toml6
-rw-r--r--mindus/build.rs46
-rw-r--r--mindus/src/color_mapped390
-rw-r--r--mindus/src/color_mapping.rs14
-rw-r--r--mindus/src/colorsbin0 -> 768 bytes
-rw-r--r--mindus/src/data/dynamic.rs8
-rw-r--r--mindus/src/data/map.rs11
-rw-r--r--mindus/src/data/renderer.rs98
-rw-r--r--mindus/src/data/schematic.rs2
-rw-r--r--mindus/src/exe/draw.rs9
-rw-r--r--mindus/src/lib.rs1
-rw-r--r--mindus/src/team.rs38
12 files changed, 525 insertions, 98 deletions
diff --git a/mindus/Cargo.toml b/mindus/Cargo.toml
index fce9ce5..f3ac070 100644
--- a/mindus/Cargo.toml
+++ b/mindus/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "mindus"
-version = "5.0.28"
+version = "5.0.29"
edition = "2021"
description = "A library for working with mindustry data formats (eg schematics and maps) (fork of plandustry)"
authors = [
@@ -30,6 +30,7 @@ fimg = { version = "0.4.33", features = [
"blur",
"save",
], default-features = false }
+atools = "0.1.6"
[features]
bin = ["fimg/save"]
@@ -52,3 +53,6 @@ path = "src/exe/mod.rs"
[dev-dependencies]
diff = "0.1"
+
+[package.metadata.docs.rs]
+rustdoc-args = ["--generate-link-to-definition"]
diff --git a/mindus/build.rs b/mindus/build.rs
index e43ec8e..fe160cb 100644
--- a/mindus/build.rs
+++ b/mindus/build.rs
@@ -1,6 +1,5 @@
#![feature(let_chains)]
use fimg::DynImage;
-use std::collections::HashMap;
use std::fs::File;
use std::io::Write as _;
use std::iter::Iterator;
@@ -36,8 +35,6 @@ fn main() {
let mut quar = File::create(o.join("quar.rs")).unwrap();
let mut eigh = File::create(o.join("eigh.rs")).unwrap();
- let mut to_colors = File::create(o.join("2.rs")).unwrap();
- let mut from_colors = File::create(o.join("4.rs")).unwrap();
let mut n = 22usize;
wr!(full => "pub mod full {{");
@@ -53,11 +50,6 @@ fn main() {
wr!(eigh => "pub static EMPTY4: Image<&[u8], 4> = Image::make::<4, 4>();");
wr!(eigh => "pub static EMPTY: Image<&[u8], 3> = Image::make::<4, 4>();");
- wr!(to_colors => "phf::phf_map! {{");
- wr!(from_colors => "phf::phf_map! {{");
-
- let mut mapped = HashMap::with_capacity(68);
-
for mut file in [&full, &quar, &eigh] {
wr!(file => "use crate::utils::Image;");
wr!(file => "pub static CLIFF: Image<&[u8], 4> = EMPTY4.copy();");
@@ -124,42 +116,6 @@ fn main() {
}
println!("do {path}");
- if rgb {
- let [r, g, b] = match &*path {
- "HOTROCK" => [221u8, 123, 82],
- "YELLOW_STONE" => [255, 210, 128],
- "REGOLITH" => [146, 90, 70],
- "CRATER_STONE" => [92, 87, 87],
- "CHAR" => [86, 79, 79],
- "METAL_FLOOR_DAMAGED" => [134, 138, 154],
- "FERRIC_CRATERS" => [69, 69, 69],
- "RHYOLITE_CRATER" => [100, 60, 53],
- "ROUGH_RHYOLITE" => [99, 60, 53],
- "DARK_PANEL_1" => [93, 81, 79],
- "DARK_PANEL_2" => [91, 81, 85],
- "DARK_PANEL_3" => [91, 79, 77],
- "DARK_PANEL_4" => [103, 90, 88],
- "DENSE_RED_STONE" => [206, 116, 95],
- "SPORE_MOSS" => [124, 76, 128],
- "METAL_FLOOR" => [126, 113, 111],
- "METAL_FLOOR_2" => [117, 106, 104],
- "MAGMAROCK" => [104, 74, 53],
- "ICE_SNOW" => [130, 125, 233],
- _ => unsafe { p.pixel::<3>(p.width() / 2, p.height() / 2) },
- };
- match mapped.entry((r, g, b)) {
- std::collections::hash_map::Entry::Occupied(with) => panic!(
- "slot {path} occupied by {}, shared color {r}, {g}, {b}",
- with.get()
- ),
- std::collections::hash_map::Entry::Vacant(e) => {
- e.insert(path.clone());
- }
- }
- wr!(from_colors => "0x{:x}_u32 => &crate::block::{path},", fimg::Pack::pack(&[r,g,b]));
- wr!(to_colors => r#""{f}" => ({r}, {g}, {b}),"#)
- }
-
macro_rules! writ {
($ext:ident / $scale:literal) => {
let mut buf = File::create(o.join(n.to_string() + "-" + stringify!($ext))).unwrap();
@@ -198,7 +154,7 @@ fn main() {
n += 1;
}
}
- for mut f in [full, eigh, quar, to_colors, from_colors] {
+ for mut f in [full, eigh, quar] {
f.write_all(b"}").unwrap();
}
}
diff --git a/mindus/src/color_mapped b/mindus/src/color_mapped
new file mode 100644
index 0000000..2e7b740
--- /dev/null
+++ b/mindus/src/color_mapped
@@ -0,0 +1,390 @@
+{ let mut l = [[0; 3]; u16::MAX as usize + 1];
+l[1] = [169,53,39];
+l[2] = [127,127,127];
+l[19] = [61,73,128];
+l[20] = [71,84,143];
+l[21] = [74,57,114];
+l[22] = [53,41,83];
+l[23] = [57,50,74];
+l[24] = [116,104,122];
+l[25] = [53,55,81];
+l[26] = [22,24,23];
+l[27] = [84,157,181];
+l[28] = [196,99,50];
+l[29] = [5,0,18];
+l[31] = [66,66,71];
+l[32] = [67,67,71];
+l[33] = [60,60,66];
+l[34] = [49,47,47];
+l[35] = [67,56,49];
+l[36] = [104,74,53];
+l[37] = [167,137,111];
+l[38] = [48,46,46];
+l[39] = [79,49,42];
+l[40] = [41,24,21];
+l[41] = [120,121,134];
+l[42] = [91,57,46];
+l[43] = [89,55,44];
+l[44] = [81,50,43];
+l[45] = [114,75,54];
+l[46] = [116,77,54];
+l[47] = [34,38,43];
+l[48] = [56,50,49];
+l[49] = [60,53,51];
+l[50] = [41,48,43];
+l[51] = [45,39,47];
+l[52] = [58,47,67];
+l[53] = [129,93,56];
+l[54] = [139,61,65];
+l[55] = [146,71,68];
+l[56] = [193,174,168];
+l[57] = [85,112,59];
+l[58] = [56,73,50];
+l[59] = [66,35,30];
+l[60] = [23,25,31];
+l[61] = [40,54,41];
+l[62] = [92,56,38];
+l[63] = [108,46,55];
+l[64] = [31,28,34];
+l[65] = [69,43,42];
+l[66] = [45,39,64];
+l[67] = [84,132,73];
+l[68] = [188,189,191];
+l[69] = [179,183,187];
+l[70] = [162,162,194];
+l[71] = [156,158,187];
+l[72] = [74,70,101];
+l[73] = [86,54,92];
+l[74] = [107,91,75];
+l[75] = [86,56,104];
+l[76] = [122,122,127];
+l[77] = [139,86,149];
+l[78] = [112,70,64];
+l[79] = [160,161,184];
+l[80] = [211,209,255];
+l[81] = [239,247,255];
+l[82] = [90,89,89];
+l[83] = [202,154,90];
+l[84] = [164,111,72];
+l[85] = [117,69,57];
+l[86] = [68,76,81];
+l[87] = [109,99,92];
+l[88] = [78,93,80];
+l[89] = [103,132,86];
+l[90] = [106,90,105];
+l[91] = [251,220,227];
+l[92] = [187,83,89];
+l[93] = [227,129,102];
+l[94] = [255,223,188];
+l[95] = [244,248,255];
+l[96] = [112,187,103];
+l[97] = [114,116,160];
+l[98] = [146,78,148];
+l[99] = [238,247,255];
+l[100] = [90,159,92];
+l[101] = [225,234,252];
+l[102] = [214,219,249];
+l[103] = [196,178,250];
+l[104] = [221,111,78];
+l[105] = [92,88,164];
+l[106] = [230,130,72];
+l[107] = [124,124,129];
+l[108] = [239,247,255];
+l[109] = [119,122,169];
+l[110] = [255,221,185];
+l[111] = [169,170,190];
+l[112] = [91,90,90];
+l[113] = [71,79,84];
+l[114] = [113,102,95];
+l[115] = [81,97,83];
+l[116] = [160,108,69];
+l[117] = [101,129,85];
+l[118] = [132,109,130];
+l[119] = [185,126,179];
+l[120] = [207,161,90];
+l[121] = [124,156,98];
+l[122] = [103,86,102];
+l[123] = [254,220,225];
+l[124] = [150,100,75];
+l[125] = [188,85,89];
+l[126] = [85,87,96];
+l[127] = [83,84,94];
+l[128] = [80,81,90];
+l[129] = [90,91,101];
+l[130] = [93,95,106];
+l[131] = [108,88,76];
+l[132] = [60,62,71];
+l[133] = [65,62,69];
+l[134] = [59,60,69];
+l[135] = [67,69,79];
+l[136] = [70,67,75];
+l[137] = [78,69,76];
+l[138] = [126,128,143];
+l[139] = [72,71,75];
+l[140] = [82,52,89];
+l[141] = [217,157,115];
+l[142] = [140,127,169];
+l[143] = [119,119,119];
+l[144] = [39,39,39];
+l[145] = [141,161,227];
+l[146] = [249,163,199];
+l[147] = [58,143,100];
+l[148] = [118,138,154];
+l[149] = [249,163,199];
+l[150] = [249,163,199];
+l[151] = [58,143,100];
+l[152] = [80,90,107];
+l[153] = [118,138,154];
+l[154] = [147,151,161];
+l[155] = [142,146,155];
+l[156] = [137,140,148];
+l[157] = [138,141,149];
+l[158] = [163,154,156];
+l[159] = [174,182,170];
+l[160] = [198,176,157];
+l[161] = [180,166,152];
+l[162] = [155,161,186];
+l[163] = [186,173,168];
+l[164] = [186,167,167];
+l[165] = [187,153,149];
+l[166] = [176,156,159];
+l[167] = [180,154,155];
+l[168] = [159,159,184];
+l[169] = [130,133,145];
+l[170] = [177,186,167];
+l[171] = [141,112,110];
+l[172] = [115,110,115];
+l[173] = [115,132,126];
+l[174] = [129,137,163];
+l[175] = [113,134,126];
+l[176] = [136,127,135];
+l[177] = [148,124,126];
+l[178] = [148,137,136];
+l[179] = [136,127,135];
+l[180] = [133,126,136];
+l[181] = [160,132,131];
+l[182] = [160,127,124];
+l[183] = [150,124,124];
+l[184] = [143,133,128];
+l[185] = [133,140,166];
+l[186] = [159,140,128];
+l[187] = [136,123,130];
+l[188] = [198,155,129];
+l[189] = [199,155,129];
+l[190] = [127,143,237];
+l[191] = [126,143,236];
+l[192] = [226,241,151];
+l[193] = [219,235,144];
+l[194] = [142,129,181];
+l[195] = [142,129,181];
+l[196] = [255,225,182];
+l[197] = [255,219,175];
+l[198] = [253,221,126];
+l[199] = [253,220,126];
+l[200] = [159,170,186];
+l[201] = [156,164,182];
+l[202] = [165,175,195];
+l[203] = [169,180,200];
+l[204] = [167,178,197];
+l[205] = [167,179,198];
+l[206] = [159,168,188];
+l[207] = [102,167,122];
+l[208] = [94,154,114];
+l[209] = [130,132,145];
+l[210] = [125,127,140];
+l[211] = [121,131,137];
+l[212] = [255,232,133];
+l[213] = [255,226,131];
+l[214] = [164,138,181];
+l[215] = [156,132,176];
+l[216] = [255,219,176];
+l[217] = [149,182,169];
+l[218] = [150,182,169];
+l[219] = [183,161,161];
+l[220] = [186,159,158];
+l[221] = [176,169,168];
+l[222] = [89,91,101];
+l[223] = [145,132,124];
+l[224] = [130,118,116];
+l[225] = [128,135,157];
+l[226] = [148,129,133];
+l[227] = [147,136,135];
+l[228] = [146,136,135];
+l[229] = [111,113,124];
+l[230] = [103,110,146];
+l[231] = [116,122,105];
+l[232] = [104,100,131];
+l[233] = [129,131,145];
+l[234] = [124,125,138];
+l[235] = [188,171,162];
+l[236] = [110,112,124];
+l[237] = [119,115,122];
+l[238] = [120,122,136];
+l[239] = [125,127,140];
+l[240] = [112,114,126];
+l[241] = [121,117,125];
+l[242] = [159,157,161];
+l[243] = [117,118,129];
+l[244] = [134,142,159];
+l[245] = [129,131,142];
+l[246] = [125,127,140];
+l[247] = [133,132,140];
+l[248] = [115,116,129];
+l[249] = [140,142,153];
+l[250] = [140,119,108];
+l[251] = [186,162,149];
+l[252] = [162,141,130];
+l[253] = [151,139,135];
+l[254] = [164,157,161];
+l[255] = [148,156,198];
+l[256] = [143,153,207];
+l[257] = [152,157,165];
+l[258] = [139,151,193];
+l[259] = [138,133,167];
+l[260] = [150,154,167];
+l[261] = [153,160,195];
+l[262] = [150,158,195];
+l[263] = [173,180,190];
+l[264] = [165,170,181];
+l[265] = [147,156,197];
+l[266] = [125,135,130];
+l[267] = [133,171,133];
+l[268] = [141,164,145];
+l[269] = [114,141,121];
+l[270] = [115,133,123];
+l[271] = [113,135,126];
+l[272] = [116,130,128];
+l[273] = [196,187,160];
+l[274] = [200,191,161];
+l[275] = [209,185,151];
+l[276] = [161,159,158];
+l[277] = [200,183,159];
+l[278] = [197,178,157];
+l[279] = [189,168,148];
+l[280] = [189,159,158];
+l[281] = [183,174,164];
+l[282] = [193,179,159];
+l[283] = [133,126,161];
+l[284] = [140,146,161];
+l[285] = [128,131,150];
+l[286] = [130,126,154];
+l[287] = [177,151,153];
+l[288] = [118,144,126];
+l[289] = [116,134,131];
+l[290] = [115,141,128];
+l[291] = [144,125,129];
+l[292] = [117,135,130];
+l[293] = [115,135,127];
+l[294] = [142,133,129];
+l[295] = [148,127,131];
+l[296] = [159,142,136];
+l[297] = [150,155,166];
+l[298] = [153,152,178];
+l[299] = [170,152,156];
+l[300] = [145,152,178];
+l[301] = [146,147,166];
+l[302] = [163,170,162];
+l[303] = [110,132,122];
+l[304] = [148,133,132];
+l[305] = [173,142,133];
+l[306] = [159,135,130];
+l[307] = [147,127,130];
+l[308] = [128,134,157];
+l[309] = [199,182,167];
+l[310] = [205,181,160];
+l[311] = [209,181,157];
+l[312] = [165,146,135];
+l[313] = [179,152,134];
+l[314] = [174,150,134];
+l[315] = [184,175,172];
+l[316] = [187,177,172];
+l[317] = [170,163,164];
+l[318] = [159,143,135];
+l[319] = [154,141,139];
+l[320] = [144,130,130];
+l[321] = [127,129,138];
+l[322] = [148,140,144];
+l[323] = [150,140,142];
+l[324] = [154,148,157];
+l[325] = [150,159,192];
+l[326] = [149,153,173];
+l[327] = [167,172,188];
+l[328] = [149,120,118];
+l[329] = [146,147,173];
+l[330] = [172,169,177];
+l[331] = [131,136,156];
+l[332] = [124,130,155];
+l[333] = [139,129,133];
+l[334] = [145,142,138];
+l[335] = [137,134,130];
+l[336] = [141,130,132];
+l[337] = [135,125,127];
+l[338] = [101,114,115];
+l[339] = [119,108,114];
+l[340] = [118,109,128];
+l[341] = [119,110,116];
+l[342] = [116,119,132];
+l[343] = [121,118,118];
+l[344] = [114,117,130];
+l[345] = [127,112,116];
+l[346] = [130,119,118];
+l[347] = [128,115,136];
+l[348] = [145,137,144];
+l[349] = [130,147,147];
+l[350] = [129,135,159];
+l[351] = [137,136,142];
+l[352] = [136,136,144];
+l[353] = [137,136,143];
+l[354] = [138,134,138];
+l[355] = [125,141,141];
+l[356] = [134,154,150];
+l[357] = [118,105,110];
+l[358] = [106,104,125];
+l[359] = [107,111,128];
+l[360] = [114,102,105];
+l[361] = [104,108,124];
+l[362] = [103,100,120];
+l[363] = [116,109,110];
+l[364] = [129,117,123];
+l[365] = [118,115,137];
+l[366] = [119,123,140];
+l[367] = [124,111,106];
+l[368] = [114,137,129];
+l[369] = [109,112,122];
+l[370] = [118,121,133];
+l[371] = [77,79,87];
+l[372] = [90,91,99];
+l[373] = [122,113,115];
+l[374] = [130,121,122];
+l[375] = [123,111,116];
+l[376] = [129,108,109];
+l[377] = [117,109,111];
+l[378] = [116,108,111];
+l[379] = [88,86,103];
+l[380] = [98,92,93];
+l[381] = [196,178,160];
+l[382] = [174,155,137];
+l[383] = [144,126,113];
+l[384] = [145,125,114];
+l[385] = [181,165,151];
+l[386] = [187,169,156];
+l[387] = [140,130,127];
+l[388] = [143,128,131];
+l[389] = [146,135,136];
+l[390] = [173,178,189];
+l[396] = [181,166,159];
+l[397] = [176,169,169];
+l[398] = [132,131,150];
+l[399] = [123,121,144];
+l[400] = [160,150,197];
+l[401] = [160,154,192];
+l[402] = [160,150,196];
+l[403] = [132,125,157];
+l[404] = [132,122,158];
+l[405] = [113,113,134];
+l[406] = [104,104,123];
+l[407] = [92,82,85];
+l[408] = [131,124,134];
+l[409] = [201,174,156];
+l[410] = [148,137,130];
+l[411] = [138,137,138]; l } \ No newline at end of file
diff --git a/mindus/src/color_mapping.rs b/mindus/src/color_mapping.rs
index da9a66d..c4a1a85 100644
--- a/mindus/src/color_mapping.rs
+++ b/mindus/src/color_mapping.rs
@@ -1,13 +1,3 @@
-use crate::block::Block;
-
/// Map a 0xRRGGBB color to a block.
-pub static COLOR2BLOCK: phf::Map<u32, &Block> = include!(concat!(env!("OUT_DIR"), "/4.rs"));
-pub static BLOCK2COLOR: phf::Map<&str, (u8, u8, u8)> = include!(concat!(env!("OUT_DIR"), "/2.rs"));
-
-pub fn block(col: [u8; 3]) -> Option<&'static Block> {
- COLOR2BLOCK.get(&fimg::Pack::pack(&col)).copied()
-}
-
-pub fn color(block: &Block) -> Option<(u8, u8, u8)> {
- BLOCK2COLOR.get(block.name()).copied()
-}
+// pub static COLOR2BLOCK: phf::Map<u32, &Block> = include!(concat!(env!("OUT_DIR"), "/4.rs"));
+pub static BLOCK2COLOR: [[u8; 3]; u16::MAX as usize + 1] = include!("color_mapped");
diff --git a/mindus/src/colors b/mindus/src/colors
new file mode 100644
index 0000000..68e89f3
--- /dev/null
+++ b/mindus/src/colors
Binary files differ
diff --git a/mindus/src/data/dynamic.rs b/mindus/src/data/dynamic.rs
index 05652ba..de8e511 100644
--- a/mindus/src/data/dynamic.rs
+++ b/mindus/src/data/dynamic.rs
@@ -353,7 +353,7 @@ pub enum WriteError {
#[cfg(test)]
mod test {
use super::*;
- use crate::team::{CRUX, DERELICT, SHARDED};
+ use crate::team::Team;
macro_rules! _zero {
($tt:tt) => {
@@ -491,8 +491,8 @@ mod test {
);
make_dyn_test!(
reparse_team,
- DynData::Team(SHARDED),
- DynData::Team(CRUX),
- DynData::Team(DERELICT)
+ DynData::Team(Team::SHARDED),
+ DynData::Team(Team::CRUX),
+ DynData::Team(Team::DERELICT)
);
}
diff --git a/mindus/src/data/map.rs b/mindus/src/data/map.rs
index b103431..f848f95 100644
--- a/mindus/src/data/map.rs
+++ b/mindus/src/data/map.rs
@@ -83,7 +83,7 @@ use crate::data::renderer::*;
use crate::data::DataRead;
use crate::fluid::Type as Fluid;
use crate::item::{storage::Storage, Type as Item};
-use crate::team::{self, Team};
+use crate::team::Team;
use crate::unit::Unit;
#[cfg(doc)]
use crate::{block::content, data::*, fluid, item, modifier, unit};
@@ -170,7 +170,7 @@ impl Tile {
items: Storage::new(),
liquids: Storage::new(),
rotation: Rotation::Up,
- team: crate::team::SHARDED,
+ team: Team::SHARDED,
data: 0,
});
}
@@ -302,7 +302,7 @@ impl Build {
liquids: Storage::default(),
state: None,
rotation: Rotation::Up,
- team: team::SHARDED,
+ team: Team::SHARDED,
data: 0,
}
}
@@ -536,7 +536,7 @@ pub struct MapReader {
#[derive(Debug)]
pub enum ThinBloc {
None(u8),
- Build(Rotation, &'static Block),
+ Build(Rotation, &'static Block, Team),
Many(&'static Block, u8),
}
@@ -696,11 +696,12 @@ impl MapReader {
let _ = self.buff.read_f32()?;
let rot = self.buff.read_i8()?;
let rot = Rotation::try_from((rot & 127) as u8).unwrap_or(Rotation::Up);
+ let team = Team::of(self.buff.read_u8()?);
let read = self.buff.read - rb4;
let n = len - read;
self.buff.skip(n)?;
- ThinMapData::Bloc(ThinBloc::Build(rot, block))
+ ThinMapData::Bloc(ThinBloc::Build(rot, block, team))
} else {
ThinMapData::Bloc(ThinBloc::None(0))
}
diff --git a/mindus/src/data/renderer.rs b/mindus/src/data/renderer.rs
index b0d7a38..2b2c5ba 100644
--- a/mindus/src/data/renderer.rs
+++ b/mindus/src/data/renderer.rs
@@ -6,6 +6,8 @@ pub(crate) use super::autotile::*;
use super::schematic::Schematic;
use super::GridPos;
use crate::block::content::Type;
+use crate::color_mapping::BLOCK2COLOR;
+use crate::team::Team;
pub(crate) use crate::utils::*;
use crate::Map;
use crate::{
@@ -455,7 +457,7 @@ pub fn draw_map_single(
Yielded(ThinMapData::Bloc(ThinBloc::None(n))) => {
i += n as usize;
}
- Yielded(ThinMapData::Bloc(ThinBloc::Build(r, bloc))) => {
+ Yielded(ThinMapData::Bloc(ThinBloc::Build(r, bloc, _))) => {
draw(i, r, bloc);
}
Yielded(ThinMapData::Bloc(ThinBloc::Many(bloc, n))) => {
@@ -476,3 +478,97 @@ pub fn draw_map_single(
Ok((img, (w, h)))
}
+
+/// Draws a map in a single pass. Uses the silly team color thing that mindustry has.
+pub fn draw_map_simple(
+ map: &mut crate::data::map::MapReader,
+) -> Result<(Image<Box<[u8]>, 3>, (u16, u16)), super::map::ReadError> {
+ use std::ops::CoroutineState::*;
+ let mut co = map.thin_map()?;
+ let (w, h) = match Pin::new(&mut co).resume(()) {
+ Yielded(ThinMapData::Init { width, height }) => (width, height),
+ Complete(Err(x)) => return Err(x),
+ _ => unreachable!(),
+ };
+ let mut img = uninit::Image::<u8, 3>::new(
+ (w as u32).try_into().unwrap(),
+ (h as u32).try_into().unwrap(),
+ );
+ // loop1 draws the floor
+ for y in 0..h {
+ for x in 0..w {
+ let (floor, ore) = match Pin::new(&mut co).resume(()) {
+ Yielded(ThinMapData::Tile { floor, ore }) => (floor, ore),
+ Complete(Err(x)) => return Err(x),
+ _ => unreachable!(),
+ };
+ let t = (ore != Type::Air).then_some(ore).unwrap_or(floor);
+ let y = h - y - 1;
+ let i1 = img.at(x as u32, y as u32) as usize;
+ unsafe {
+ img.slice(i1..i1 + 3)
+ .write_copy_of_slice(&BLOCK2COLOR[t as u16 as usize][..])
+ };
+ }
+ }
+ let mut img = unsafe { img.assume_init() }.boxed();
+ let mut i = 0;
+ while i < (w as usize * h as usize) {
+ let mut draw = |i, b: &'static crate::block::Block, team: Team| {
+ let x = i % w as usize;
+ let y = i / w as usize;
+ let y = h as usize - y - 1;
+ let s = b.get_size();
+ let x = x
+ - (match s {
+ 1 | 2 => 0,
+ 3 | 4 => 1,
+ 5 | 6 => 2,
+ 7 | 8 => 3,
+ 9 => 4,
+ // SAFETY: no block too big
+ _ => unsafe { std::hint::unreachable_unchecked() },
+ }) as usize;
+ let y = y
+ - (match s {
+ 1 => 0,
+ 2 | 3 => 1,
+ 4 | 5 => 2,
+ 6 | 7 => 3,
+ 8 | 9 => 4,
+ // SAFETY: no block too big
+ _ => unsafe { std::hint::unreachable_unchecked() },
+ }) as usize;
+ for x in x..(x as usize + s as usize).min(w as usize) {
+ for y in y..(y as usize + s as usize).min(h as usize) {
+ unsafe {
+ img.set_pixel(x as u32, y as u32, <[u8; 3]>::from(team.color()));
+ }
+ }
+ }
+ };
+ match Pin::new(&mut co).resume(()) {
+ Yielded(ThinMapData::Bloc(ThinBloc::None(n))) => {
+ i += n as usize;
+ }
+ Yielded(ThinMapData::Bloc(ThinBloc::Build(_, bloc, t))) => {
+ draw(i, bloc, t);
+ }
+ Yielded(ThinMapData::Bloc(ThinBloc::Many(bloc, n))) => {
+ for i in i..=i + n as usize {
+ draw(i, bloc, Team::DERELICT);
+ }
+ i += n as usize;
+ }
+ Complete(Err(x)) => return Err(x),
+ x => unreachable!("{x:?}"),
+ }
+ i += 1;
+ }
+ match Pin::new(&mut co).resume(()) {
+ Complete(Ok(())) => (),
+ f => unreachable!("{f:?}"),
+ };
+
+ Ok((img, (w, h)))
+}
diff --git a/mindus/src/data/schematic.rs b/mindus/src/data/schematic.rs
index 86c6542..0c315ec 100644
--- a/mindus/src/data/schematic.rs
+++ b/mindus/src/data/schematic.rs
@@ -169,7 +169,7 @@ impl Schematic {
/// Ratios of this schematic.
/// ```
- /// # #![feature(const_trait_impl, effects)]
+ /// # #![feature(const_trait_impl)]
/// # use mindus::Schematic;
/// # use mindus::block::ratios::ratios;
/// assert_eq!(Schematic::deserialize_base64("bXNjaAF4nEWMSw7CMAxEh9REVSqx5hKcCLFISxaR0o9Sg8rtSTpFePPkmWfDwTWQyY8B5z75VdE9wzrkuGicJwA2+T6kFeb+aNDtym2MW8i4LJ/sNWo4dje8ksa31zmXuyv+Y4BTgRD2iIi9M+xM7WrUgnoNhYpQESpCxfKLrUo9FsISLX6vKgwhhCVK+wX5/BtM").unwrap().ratios(),
diff --git a/mindus/src/exe/draw.rs b/mindus/src/exe/draw.rs
index 447bc44..7981b3c 100644
--- a/mindus/src/exe/draw.rs
+++ b/mindus/src/exe/draw.rs
@@ -1,5 +1,5 @@
use mindus::data::DataRead;
-use mindus::{Renderable, Schematic, Serializable};
+use mindus::{Schematic, Serializable};
use std::env::Args;
use crate::print_err;
@@ -8,7 +8,7 @@ pub fn main(args: Args) {
// process schematics from command line
for curr in args {
match if curr.ends_with(".msch") {
- let Ok(v) = std::fs::read(curr) else {
+ let Ok(v) = std::fs::read(&curr) else {
panic!("no file found");
};
Schematic::deserialize(&mut DataRead::new(&v))
@@ -23,11 +23,12 @@ pub fn main(args: Args) {
}
} {
Ok(s) => {
- let i = s.render();
+ println!("{curr} {}", s.tags.get("name").unwrap());
+ // let i = s.render();
if let Ok(v) = std::env::var("SAVE")
&& v == "1"
{
- i.save("x.png");
+ // i.save("x.png");
continue;
}
}
diff --git a/mindus/src/lib.rs b/mindus/src/lib.rs
index c172db1..45786f4 100644
--- a/mindus/src/lib.rs
+++ b/mindus/src/lib.rs
@@ -1,5 +1,6 @@
//! crate for dealing with mindustry
#![feature(
+ maybe_uninit_write_slice,
stmt_expr_attributes,
generic_const_exprs,
iter_from_coroutine,
diff --git a/mindus/src/team.rs b/mindus/src/team.rs
index 416a356..70fa3b7 100644
--- a/mindus/src/team.rs
+++ b/mindus/src/team.rs
@@ -1,5 +1,7 @@
use std::fmt;
+use atools::Chunked;
+
use crate::content::{Content, Type};
#[derive(Clone, Copy, Debug, Eq, Ord, PartialOrd, Default, PartialEq)]
@@ -107,30 +109,16 @@ impl Content for Team {
}
impl Team {
- pub const fn color(self) -> (u8, u8, u8) {
- macro_rules! h {
- ($x:literal) => {{
- let v = color_hex::color_from_hex!($x);
- (v[0], v[1], v[2])
- }};
- }
- match self {
- SHARDED => h!("ffd37f"),
- DERELICT => h!("4d4e58"),
- CRUX => h!("f25555"),
- MALIS => h!("a27ce5"),
- GREEN => h!("54d67d"),
- BLUE => h!("6c87fd"),
- NEOPLASTIC => h!("e05438"),
- _ => h!("a9a9a9"),
- }
+ pub const fn color(self) -> [u8; 3] {
+ static COLORS: [[u8; 3]; 256] = include_bytes!("colors").chunked::<3>();
+ COLORS[self.0 as usize]
}
-}
-pub const DERELICT: Team = Team(0);
-pub const SHARDED: Team = Team(1);
-pub const CRUX: Team = Team(2);
-pub const MALIS: Team = Team(3);
-pub const GREEN: Team = Team(4);
-pub const BLUE: Team = Team(5);
-pub const NEOPLASTIC: Team = Team(6);
+ pub const DERELICT: Team = Team(0);
+ pub const SHARDED: Team = Team(1);
+ pub const CRUX: Team = Team(2);
+ pub const MALIS: Team = Team(3);
+ pub const GREEN: Team = Team(4);
+ pub const BLUE: Team = Team(5);
+ pub const NEOPLASTIC: Team = Team(6);
+}