Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AoS/OpenSpades compatibility #2

Closed
bztsrc opened this issue May 7, 2022 · 2 comments
Closed

AoS/OpenSpades compatibility #2

bztsrc opened this issue May 7, 2022 · 2 comments

Comments

@bztsrc
Copy link

bztsrc commented May 7, 2022

Hi,

Here's a little patch that adds vxl (AoS, OpenSpades) to the export menu. The only difference is, libvxl allows saving arbitrary sized maps, but the original AoS needs a fixed sized map. This option configures libvxl in a way that the saved map will be 100% guaranteed to be compatible with the original vxl spec.

diff --git a/src/formats/vxl.c b/src/formats/vxl.c
index 28cad28e..4cfecd66 100644
--- a/src/formats/vxl.c
+++ b/src/formats/vxl.c
@@ -108,5 +108,43 @@ static int export_as_vxl(const image_t* image, const char* path) {
 	return 0;
 }
 
+static int export_as_vxl_aos(const image_t* image, const char* path) {
+	if(!path)
+		return -1;
+
+	const mesh_t* mesh = goxel_get_layers_mesh(image);
+
+	int bbox[2][3], x, y, z;
+	if(!mesh_get_bbox(mesh, bbox, true))
+		return -1;
+
+	struct libvxl_map map;
+	if(!libvxl_create(&map, 512, 512, 64, NULL, 0))
+		return -1;
+
+	int pos[3];
+	mesh_iterator_t it = mesh_get_iterator(mesh, MESH_ITER_SKIP_EMPTY);
+
+	while(mesh_iter(&it, pos)) {
+		uint8_t color[4];
+		mesh_get_at(mesh, &it, pos, color);
+
+		x = bbox[1][0] - 1 - pos[0];
+		y = pos[1] - bbox[0][1];
+		z = bbox[1][2] - 1 - pos[2];
+		if(x >= 0 && x < 512 && y >= 0 && y < 512 && z >= 0 && z < 64 && color[3] > 0)
+			libvxl_map_set(&map, x, y, z,
+						   RGB(color[2], color[1], color[0]));
+	}
+
+	libvxl_writefile(&map, (char*)path);
+	libvxl_free(&map);
+
+	return 0;
+}
+
 FILE_FORMAT_REGISTER(vxl, .name = "vxl", .ext = "vxl\0*.vxl\0",
 					 .import_func = import_vxl, .export_func = export_as_vxl)
+
+FILE_FORMAT_REGISTER(vxlaos, .name = "vxl (AoS, OpenSpades)", .ext = "vxl\0*.vxl\0",
+					 .export_func = export_as_vxl_aos)

Cheers,
bzt

@xtreme8000
Copy link
Owner

xtreme8000 commented Jun 29, 2022

The current code allows for import/export of arbitrary sizes, since AoS 1.0 Battle Builder uses non-standard maps. Maybe a checkbox or input fields to specify size would be better.

@bztsrc
Copy link
Author

bztsrc commented Jul 8, 2022

The current code allows for import/export of arbitrary sizes, since AoS 1.0 Battle Builder uses non-standard maps.

I don't know about that, all I know that others had issues so I was kind to add this little patch for them. I don't play AoS myself, and I have no reason to question my friends complaining about the map loading. It could be that AoS was fixed in the meantime.

Maybe a checkbox or input fields to specify size would be better.

Yeah, and would also require a significant redesign of the UI (currently there's no form at all when exporting). This patch aims to be as minimal as possible, that's why it just adds a new "format" to the menu, nothing else.

But do as you please, it is your project. If you can use this, that's fine, if you can't no hard feelings :-)

Cheers,
bzt

@bztsrc bztsrc closed this as completed Jul 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants