Skip to content

Commit 3e2ebc4

Browse files
committed
make CI happy
1 parent f302f0b commit 3e2ebc4

File tree

10 files changed

+74
-67
lines changed

10 files changed

+74
-67
lines changed

.github/workflows/prek.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ jobs:
1010
uses: astral-sh/setup-uv@v7
1111
- name: Set up Python
1212
run: uv python install
13+
- name: Setup wasm32
14+
run: rustup target add wasm32-unknown-unknown
1315
- uses: j178/prek-action@v1

crates/gui/src/app.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -276,25 +276,25 @@ impl EditorApp {
276276
}
277277
})
278278
}
279-
if ui.button("Export").clicked() {
280-
if let Some(world_db) = self.world_db.as_ref() {
281-
let mut out_bytes = Vec::new();
282-
match world_db.write_to(&mut out_bytes) {
283-
Ok(()) => {
284-
let task = rfd::AsyncFileDialog::new()
285-
.set_file_name("data.mdb")
286-
.save_file();
287-
let ctx = ui.ctx().clone();
288-
wasm_bindgen_futures::spawn_local(async move {
289-
if let Some(file) = task.await {
290-
let _ = file.write(&out_bytes).await;
291-
ctx.request_repaint();
292-
}
293-
})
294-
}
295-
Err(e) => {
296-
self.save_err = Some(e);
297-
}
279+
if ui.button("Export").clicked()
280+
&& let Some(world_db) = self.world_db.as_ref()
281+
{
282+
let mut out_bytes = Vec::new();
283+
match world_db.write_to(&mut out_bytes) {
284+
Ok(()) => {
285+
let task = rfd::AsyncFileDialog::new()
286+
.set_file_name("data.mdb")
287+
.save_file();
288+
let ctx = ui.ctx().clone();
289+
wasm_bindgen_futures::spawn_local(async move {
290+
if let Some(file) = task.await {
291+
let _ = file.write(&out_bytes).await;
292+
ctx.request_repaint();
293+
}
294+
})
295+
}
296+
Err(e) => {
297+
self.save_err = Some(e);
298298
}
299299
}
300300
}

crates/gui/src/dw_impl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use the_blockheads_tools_lib::game::{
88
impl ToIconInstance for CornPlant {
99
fn to_icon_instance(&self) -> DwIconInstanceRaw {
1010
DwIconInstanceRaw {
11-
position: self.float_pos.map(|f| f.get()).into(),
11+
position: self.float_pos.map(|f| f.get()),
1212
item_type: ItemType::Corn as u32,
1313
}
1414
}
@@ -17,7 +17,7 @@ impl ToIconInstance for CornPlant {
1717
impl ToIconInstance for CarrotPlant {
1818
fn to_icon_instance(&self) -> DwIconInstanceRaw {
1919
DwIconInstanceRaw {
20-
position: self.float_pos.map(|f| f.get()).into(),
20+
position: self.float_pos.map(|f| f.get()),
2121
item_type: ItemType::Carrot as u32,
2222
}
2323
}
@@ -26,7 +26,7 @@ impl ToIconInstance for CarrotPlant {
2626
impl ToIconInstance for TomatoPlant {
2727
fn to_icon_instance(&self) -> DwIconInstanceRaw {
2828
DwIconInstanceRaw {
29-
position: self.float_pos.map(|f| f.get()).into(),
29+
position: self.float_pos.map(|f| f.get()),
3030
item_type: ItemType::Tomato as u32,
3131
}
3232
}

crates/py_bindings/src/lib.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ mod block {
245245
}
246246
}
247247

248-
impl Into<BlockType> for BlockTypePy {
249-
fn into(self) -> BlockType {
250-
BlockType::try_from(self as u8).expect("Enums are out of sync!")
248+
impl From<BlockTypePy> for BlockType {
249+
fn from(val: BlockTypePy) -> Self {
250+
BlockType::try_from(val as u8).expect("Enums are out of sync!")
251251
}
252252
}
253253

@@ -272,7 +272,7 @@ mod block {
272272
}
273273
None => Err(InvalidAccessorError::new_err(format!(
274274
"The block at {} doesn't exist.",
275-
self.block_coord.to_string()
275+
self.block_coord
276276
))),
277277
}
278278
}
@@ -308,7 +308,7 @@ mod chunk {
308308
)),
309309
None => Err(InvalidAccessorError::new_err(format!(
310310
"The chunk at {} doesn't exist.",
311-
self.coord.to_string()
311+
self.coord
312312
))),
313313
}
314314
}
@@ -346,7 +346,6 @@ mod chunk {
346346
world_db
347347
.chunks
348348
.keys()
349-
.into_iter()
350349
.map(|value| ChunkCoordPy { inner: value }),
351350
)
352351
}
@@ -834,9 +833,9 @@ pub mod item {
834833
}
835834
}
836835

837-
impl Into<ItemType> for ItemTypePy {
838-
fn into(self) -> ItemType {
839-
ItemType::try_from(self as u16).expect("Enums are out of sync!")
836+
impl From<ItemTypePy> for ItemType {
837+
fn from(val: ItemTypePy) -> Self {
838+
ItemType::try_from(val as u16).expect("Enums are out of sync!")
840839
}
841840
}
842841

@@ -859,9 +858,9 @@ pub mod item {
859858
}
860859
}
861860

862-
impl Into<ChestType> for ChestTypePy {
863-
fn into(self) -> ChestType {
864-
ChestType::try_from(self as u8).expect("Enums are out of sync!")
861+
impl From<ChestTypePy> for ChestType {
862+
fn from(val: ChestTypePy) -> Self {
863+
ChestType::from(val as u8)
865864
}
866865
}
867866

@@ -909,9 +908,9 @@ pub mod item {
909908
}
910909
}
911910

912-
impl Into<WorkbenchType> for WorkbenchTypePy {
913-
fn into(self) -> WorkbenchType {
914-
WorkbenchType::try_from(self as u8).expect("Enums are out of sync!")
911+
impl From<WorkbenchTypePy> for WorkbenchType {
912+
fn from(val: WorkbenchTypePy) -> Self {
913+
WorkbenchType::from(val as u8)
915914
}
916915
}
917916

@@ -936,9 +935,9 @@ pub mod item {
936935
}
937936
}
938937

939-
impl Into<PigmentColor> for PigmentColorPy {
940-
fn into(self) -> PigmentColor {
941-
PigmentColor::try_from(self as u8).expect("Enums are out of sync!")
938+
impl From<PigmentColorPy> for PigmentColor {
939+
fn from(val: PigmentColorPy) -> Self {
940+
PigmentColor::try_from(val as u8).expect("Enums are out of sync!")
942941
}
943942
}
944943

crates/py_bindings/tests/test_coords.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ def test_chunk_coord():
1010
assert coord.y == 10
1111

1212
with pytest.raises(AttributeError):
13-
coord.x = 5
13+
coord.x = 5 # ty: ignore[invalid-assignment]
1414
with pytest.raises(AttributeError):
15-
coord.y = 5
15+
coord.y = 5 # ty: ignore[invalid-assignment]
1616
with pytest.raises(ValueError):
1717
ChunkCoord(123, 45)
1818
with pytest.raises(OverflowError):
@@ -30,9 +30,9 @@ def test_chunk_block_coord():
3030
assert coord.y == 10
3131

3232
with pytest.raises(AttributeError):
33-
coord.x = 5
33+
coord.x = 5 # ty: ignore[invalid-assignment]
3434
with pytest.raises(AttributeError):
35-
coord.y = 5
35+
coord.y = 5 # ty: ignore[invalid-assignment]
3636
with pytest.raises(ValueError):
3737
ChunkBlockCoord(32, 5)
3838
with pytest.raises(ValueError):
@@ -48,9 +48,9 @@ def test_block_coord():
4848
assert coord.y == 678
4949

5050
with pytest.raises(AttributeError):
51-
coord.x = 5
51+
coord.x = 5 # ty: ignore[invalid-assignment]
5252
with pytest.raises(AttributeError):
53-
coord.y = 5
53+
coord.y = 5 # ty: ignore[invalid-assignment]
5454
with pytest.raises(ValueError):
5555
BlockCoord(123, 1024)
5656
with pytest.raises(OverflowError):

crates/py_bindings/tests/test_dynamic_world_v2.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,28 @@ def test_dynamic_world_v2_write():
2222
with pytest.raises(OverflowError):
2323
dynamic_world_v2.active_blockhead_index = -1 # u64 internally
2424
with pytest.raises(TypeError):
25-
dynamic_world_v2.active_blockhead_index = "123"
25+
dynamic_world_v2.active_blockhead_index = "123" # ty: ignore[invalid-assignment]
2626

2727
dynamic_world_v2.dynamic_object_id_count = 12345
2828
assert dynamic_world_v2.dynamic_object_id_count == 12345
2929
with pytest.raises(OverflowError):
3030
dynamic_world_v2.dynamic_object_id_count = -1 # u64 internally
3131
with pytest.raises(TypeError):
32-
dynamic_world_v2.dynamic_object_id_count = "123"
32+
dynamic_world_v2.dynamic_object_id_count = "123" # ty: ignore[invalid-assignment]
3333

3434
dynamic_world_v2.save_version = 0
3535
assert dynamic_world_v2.save_version == 0
3636
with pytest.raises(OverflowError):
3737
dynamic_world_v2.save_version = -1 # u8 internally
3838
with pytest.raises(TypeError):
39-
dynamic_world_v2.save_version = "123"
39+
dynamic_world_v2.save_version = "123" # ty: ignore[invalid-assignment]
4040

4141
dynamic_world_v2.saved_glow_indices = b""
4242
assert dynamic_world_v2.saved_glow_indices == b""
4343
with pytest.raises(TypeError):
44-
dynamic_world_v2.saved_glow_indices = "123"
44+
dynamic_world_v2.saved_glow_indices = "123" # ty: ignore[invalid-assignment]
4545

4646
dynamic_world_v2.workbench_has_been_crafted = True
4747
assert dynamic_world_v2.workbench_has_been_crafted == True
4848
with pytest.raises(TypeError):
49-
dynamic_world_v2.saved_glow_indices = "123"
49+
dynamic_world_v2.saved_glow_indices = "123" # ty: ignore[invalid-assignment]

crates/py_bindings/tests/test_item.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from the_blockheads_tools_py import (
2-
Item, ItemType, PigmentColor, StackedItem, BasketExtra, ChestExtra, ChestType
2+
Item, ItemType, PigmentColor, StackedItem, BasketExtra, ChestExtra, ChestType,
3+
WorkbenchExtra, WorkbenchType
34
)
45
import pytest
56

@@ -225,13 +226,12 @@ def test_chest_roundtrip():
225226
container = Item(ItemType.PortalChest, extra=chest)
226227

227228
# We can test that the properties we set are stable in python.
229+
assert type(container.extra) is ChestExtra
228230
assert container.extra.unique_id == 0xDEADBEEFCAFEBABE
229231
assert container.extra[7][0].item_type == ItemType.Diamond
230232
assert container.extra[7][0].damage == 5
231233

232234
def test_workbench_basic():
233-
from the_blockheads_tools_py import WorkbenchExtra, WorkbenchType
234-
235235
wb = WorkbenchExtra()
236236
assert wb.workbench_type == WorkbenchType.Workbench
237237
assert wb.level == 1
@@ -243,8 +243,6 @@ def test_workbench_basic():
243243
assert wb.owner_id == "crafter"
244244

245245
def test_workbench_properties():
246-
from the_blockheads_tools_py import WorkbenchExtra
247-
248246
wb = WorkbenchExtra()
249247

250248
# Test mutability
@@ -264,8 +262,6 @@ def test_workbench_properties():
264262
assert wb.unique_id == 999999
265263

266264
def test_workbench_integration():
267-
from the_blockheads_tools_py import WorkbenchExtra, WorkbenchType
268-
269265
wb = WorkbenchExtra(WorkbenchType.Easel)
270266
item = Item(ItemType.Easel, extra=wb)
271267

crates/py_bindings/tests/test_world_db_main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ def test_world_db_main():
88
# blockheads is now a list of BlockheadPy
99
assert isinstance(main.blockheads, list)
1010
with pytest.raises(AttributeError):
11-
main.blockheads = b"12345"
11+
main.blockheads = b"12345" # ty: ignore[invalid-assignment]
1212
with pytest.raises(AttributeError):
13-
main.dynamic_world_v2 = b"12345"
13+
main.dynamic_world_v2 = b"12345" # ty: ignore[invalid-assignment]
1414
if main.blockheads:
1515
assert isinstance(main.blockheads[0].name, str)
1616

@@ -29,4 +29,6 @@ def test_inventories():
2929
# Test setting (roundtrip)
3030
db.main.set_blockhead_inventory(first_id, inv)
3131
inv2 = db.main.get_blockhead_inventory(first_id)
32+
assert inv2 is not None
3233
assert len(inv2.slots) == 8
34+
assert inv2 is inv

crates/py_bindings/tests/test_world_v2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ def test_world_v2_write():
3333
world_db = WorldDb.open(WORLD_DB_PATH)
3434
world_v2 = world_db.main.world_v2
3535
with pytest.raises(TypeError):
36-
world_v2.host_port = 12345
36+
world_v2.host_port = 12345 # ty: ignore[invalid-assignment]
3737
world_v2.host_port = "51515"
3838
assert world_v2.host_port == "51515"
3939

4040
with pytest.raises(TypeError):
41-
world_v2.translation = "15151"
41+
world_v2.translation = "15151" # ty: ignore[invalid-assignment]
4242
world_v2.translation = (520, 520)
4343
assert world_v2.translation == (520.0, 520.0)
4444

4545
with pytest.raises(TypeError):
46-
world_v2.translation = "15151"
46+
world_v2.translation = "15151" # ty: ignore[invalid-assignment]
4747
world_v2.circum_navigate_booleans_data = b"12345"
4848
assert world_v2.circum_navigate_booleans_data == b"12345"

crates/py_bindings/the_blockheads_tools_py.pyi

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class PigmentColor(Enum):
1313
TyrianPurple = 7
1414
CopperBlue = 8
1515

16+
def __int__(self) -> int: ...
17+
1618

1719
class ItemType(Enum):
1820
Unknown = 0
@@ -443,6 +445,8 @@ class ItemType(Enum):
443445
FeederChest = 1104
444446
LuminousPlaster = 1105
445447

448+
def __int__(self) -> int: ...
449+
446450

447451
class ChestType(Enum):
448452
Standard = 0
@@ -453,6 +457,8 @@ class ChestType(Enum):
453457
DisplayCabinet = 5
454458
Feeder = 6
455459

460+
def __int__(self) -> int: ...
461+
456462

457463
class WorkbenchType(Enum):
458464
Undefined = 0
@@ -488,10 +494,12 @@ class WorkbenchType(Enum):
488494
EggExtractor = 30
489495
PizzaOven = 31
490496

497+
def __int__(self) -> int: ...
498+
491499

492500
class BasketExtra:
493501
items: list[StackedItem]
494-
def __init__(self, items: list[StackedItem] | None = None) -> None: ...
502+
def __init__(self, items: Optional[list[StackedItem]] = None) -> None: ...
495503
def __len__(self) -> int: ...
496504
def __getitem__(self, index: int) -> StackedItem: ...
497505
def __setitem__(self, index: int, value: StackedItem) -> None: ...
@@ -524,7 +532,7 @@ class Item:
524532
selected_sub_item_index: int
525533
padding: int
526534

527-
def __init__(self, item_type: ItemType, extra: BasketExtra | ChestExtra | WorkbenchExtra | None = None) -> None: ...
535+
def __init__(self, item_type: ItemType, extra: Optional[BasketExtra | ChestExtra | WorkbenchExtra] = None) -> None: ...
528536
@property
529537
def item_type(self) -> ItemType: ...
530538
@item_type.setter
@@ -576,7 +584,7 @@ class WorkbenchExtra:
576584
class StackedItem:
577585
items: list[Item]
578586

579-
def __init__(self, items: list[Item]) -> None: ...
587+
def __init__(self, items: Optional[list[Item]] = None) -> None: ...
580588
def __len__(self) -> int: ...
581589
def __getitem__(self, index: int) -> Item: ...
582590
def __setitem__(self, index: int, value: Item) -> None: ...
@@ -586,7 +594,7 @@ class StackedItem:
586594
class Inventory:
587595
slots: list[StackedItem]
588596

589-
def __init__(self, slots: list[StackedItem] | None = None) -> None: ...
597+
def __init__(self, slots: Optional[list[StackedItem]] = None) -> None: ...
590598
def __len__(self) -> int: ...
591599
def __getitem__(self, index: int) -> StackedItem: ...
592600
def __setitem__(self, index: int, value: StackedItem) -> None: ...

0 commit comments

Comments
 (0)