Add AutoTileset kinds
parent
60c6a5df8d
commit
d27051e526
|
@ -113,8 +113,7 @@ pub fn extractLevel(opt: Options) !void {
|
||||||
|
|
||||||
for (autotiles) |autotile_opt, i| {
|
for (autotiles) |autotile_opt, i| {
|
||||||
if (autotile_opt) |autotile| {
|
if (autotile_opt) |autotile| {
|
||||||
const li = autotile.to_u4();
|
const tile = tileset.find(autotile);
|
||||||
const tile = tileset.lookup[li];
|
|
||||||
map.tiles[i] = tile;
|
map.tiles[i] = tile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,12 +176,11 @@ pub fn extractLevel(opt: Options) !void {
|
||||||
|
|
||||||
for (autotiles) |autotile_opt, i| {
|
for (autotiles) |autotile_opt, i| {
|
||||||
if (autotile_opt) |autotile| {
|
if (autotile_opt) |autotile| {
|
||||||
const li = autotile.to_u4();
|
|
||||||
const tile = switch (circuit_map[i]) {
|
const tile = switch (circuit_map[i]) {
|
||||||
.Conduit, .Source, .Join => opt.conduit.lookup[li],
|
.Conduit, .Source, .Join => opt.conduit.find(autotile),
|
||||||
.Switch_On => opt.switch_on.lookup[li],
|
.Switch_On => opt.switch_on.find(autotile),
|
||||||
.Switch_Off => opt.switch_off.lookup[li],
|
.Switch_Off => opt.switch_off.find(autotile),
|
||||||
.Plug => opt.plug.lookup[li],
|
.Plug => opt.plug.find(autotile),
|
||||||
.And => 60,
|
.And => 60,
|
||||||
.Xor => 62,
|
.Xor => 62,
|
||||||
else => 0,
|
else => 0,
|
||||||
|
|
|
@ -44,7 +44,7 @@ pub fn start() !void {
|
||||||
.level = level,
|
.level = level,
|
||||||
.map = &map,
|
.map = &map,
|
||||||
.circuit = &circuit,
|
.circuit = &circuit,
|
||||||
.tileset = world.AutoTileset{ .lookup = .{
|
.tileset = world.AutoTileset.initFull(&.{
|
||||||
35, // Island
|
35, // Island
|
||||||
51, // North
|
51, // North
|
||||||
52, // West
|
52, // West
|
||||||
|
@ -61,8 +61,8 @@ pub fn start() !void {
|
||||||
37, // South-East-North
|
37, // South-East-North
|
||||||
22, // South-East-West
|
22, // South-East-West
|
||||||
0, // South-East-West-North
|
0, // South-East-West-North
|
||||||
}},
|
}),
|
||||||
.conduit = world.AutoTileset{ .lookup = .{
|
.conduit = world.AutoTileset.initFull(&.{
|
||||||
42, // Island
|
42, // Island
|
||||||
58, // North
|
58, // North
|
||||||
59, // West
|
59, // West
|
||||||
|
@ -79,61 +79,23 @@ pub fn start() !void {
|
||||||
75, // South-East-North
|
75, // South-East-North
|
||||||
72, // South-East-West
|
72, // South-East-West
|
||||||
43, // South-East-West-North
|
43, // South-East-West-North
|
||||||
} },
|
}),
|
||||||
.plug = world.AutoTileset{ .lookup = .{
|
.plug = world.AutoTileset.initCardinal(&.{
|
||||||
02, // Island
|
|
||||||
45, // North
|
45, // North
|
||||||
46, // West
|
46, // West
|
||||||
02, // West-North
|
|
||||||
47, // East
|
47, // East
|
||||||
02, // East-North
|
|
||||||
02, // East-West
|
|
||||||
02, // East-West-North
|
|
||||||
44, // South
|
44, // South
|
||||||
02, // South-North
|
}, 2),
|
||||||
02, // South-West
|
.switch_off = world.AutoTileset.initSwitches(&.{
|
||||||
02, // South-West-North
|
|
||||||
02, // South-East
|
|
||||||
02, // South-East-North
|
|
||||||
02, // South-East-West
|
|
||||||
02, // South-East-West-North
|
|
||||||
} },
|
|
||||||
.switch_off = world.AutoTileset{ .lookup = .{
|
|
||||||
02, // Island
|
|
||||||
02, // North
|
|
||||||
02, // West
|
|
||||||
02, // West-North
|
|
||||||
02, // East
|
|
||||||
02, // East-North
|
|
||||||
02, // East-West
|
|
||||||
02, // East-West-North
|
|
||||||
02, // South
|
|
||||||
32, // South-North
|
32, // South-North
|
||||||
02, // South-West
|
|
||||||
29, // South-West-North
|
29, // South-West-North
|
||||||
02, // South-East
|
|
||||||
31, // South-East-North
|
31, // South-East-North
|
||||||
02, // South-East-West
|
}, 2),
|
||||||
02, // South-East-West-North
|
.switch_on = world.AutoTileset.initSwitches(&.{
|
||||||
} },
|
|
||||||
.switch_on = world.AutoTileset{ .lookup = .{
|
|
||||||
02, // Island
|
|
||||||
02, // North
|
|
||||||
02, // West
|
|
||||||
02, // West-North
|
|
||||||
02, // East
|
|
||||||
02, // East-North
|
|
||||||
02, // East-West
|
|
||||||
02, // East-West-North
|
|
||||||
02, // South
|
|
||||||
48, // South-North
|
48, // South-North
|
||||||
02, // South-West
|
|
||||||
28, // South-West-North
|
28, // South-West-North
|
||||||
02, // South-East
|
|
||||||
02, // South-East-North
|
|
||||||
30, // South-East-West
|
30, // South-East-West
|
||||||
02, // South-East-West-North
|
}, 2),
|
||||||
} },
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ pub const Level = struct {
|
||||||
tiles: []TileStore,
|
tiles: []TileStore,
|
||||||
|
|
||||||
pub fn init(header: LevelHeader, buf: []TileStore) Level {
|
pub fn init(header: LevelHeader, buf: []TileStore) Level {
|
||||||
return Level {
|
return Level{
|
||||||
.world_x = header.world_x,
|
.world_x = header.world_x,
|
||||||
.world_y = header.world_y,
|
.world_y = header.world_y,
|
||||||
.width = header.width,
|
.width = header.width,
|
||||||
|
@ -122,5 +122,58 @@ pub const AutoTile = packed struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const AutoTileset = struct {
|
pub const AutoTileset = struct {
|
||||||
lookup: [16]u8,
|
lookup: []const u8,
|
||||||
|
kind: enum {
|
||||||
|
Cardinal,
|
||||||
|
Switches,
|
||||||
|
Full,
|
||||||
|
},
|
||||||
|
default: u8,
|
||||||
|
|
||||||
|
pub fn initFull(table: []const u8) AutoTileset {
|
||||||
|
std.debug.assert(table.len == 16);
|
||||||
|
return AutoTileset{
|
||||||
|
.lookup = table,
|
||||||
|
.kind = .Full,
|
||||||
|
.default = 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn initCardinal(table: []const u8, default: u8) AutoTileset {
|
||||||
|
std.debug.assert(table.len == 4);
|
||||||
|
return AutoTileset{
|
||||||
|
.lookup = table,
|
||||||
|
.kind = .Cardinal,
|
||||||
|
.default = default,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn initSwitches(table: []const u8, default: u8) AutoTileset {
|
||||||
|
std.debug.assert(table.len == 3);
|
||||||
|
return AutoTileset{
|
||||||
|
.lookup = table,
|
||||||
|
.kind = .Switches,
|
||||||
|
.default = default,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn find(tileset: AutoTileset, autotile: AutoTile) u8 {
|
||||||
|
const autoint = autotile.to_u4();
|
||||||
|
switch (tileset.kind) {
|
||||||
|
.Full => return tileset.lookup[autoint],
|
||||||
|
.Cardinal => switch (autoint) {
|
||||||
|
0b0001 => return tileset.lookup[0],
|
||||||
|
0b0010 => return tileset.lookup[1],
|
||||||
|
0b0100 => return tileset.lookup[2],
|
||||||
|
0b1000 => return tileset.lookup[3],
|
||||||
|
else => return tileset.default,
|
||||||
|
},
|
||||||
|
.Switches => switch (autoint) {
|
||||||
|
0b1001 => return tileset.lookup[0],
|
||||||
|
0b1011 => return tileset.lookup[1],
|
||||||
|
0b1101 => return tileset.lookup[2],
|
||||||
|
else => return tileset.default,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue