wip and næ næ
2
bundles/bundle.properties
Normal file
|
@ -0,0 +1,2 @@
|
|||
blocks.factory-buildings-factory-building.name = Factory Building
|
||||
blocks.factory-buildings-factory-building.description = A factory building
|
|
@ -1,8 +0,0 @@
|
|||
{
|
||||
"name": "Factory Building",
|
||||
"description": "A factory building",
|
||||
"requirements": ["lead/10", "copper/20"],
|
||||
"size": 4,
|
||||
"health": 1200
|
||||
}
|
||||
|
10
content/blocks/factory-wall.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"name": "Factory Wall",
|
||||
"localizedName": "Factory Wall",
|
||||
"description": "Walls for a factory block",
|
||||
"size": 1,
|
||||
"breakable": false,
|
||||
"destructible": false,
|
||||
"buildVisibility": "hidden"
|
||||
}
|
||||
|
|
@ -1,14 +1,40 @@
|
|||
const load = require("loadMap");
|
||||
const simulation = require("simulation");
|
||||
module.exports = (map) => {
|
||||
const facc = extendContent(Wall, "factory-building", {});
|
||||
print(0);
|
||||
var facc = extendContent(Wall, "factory-building", {
|
||||
icons() {
|
||||
return [
|
||||
Core.atlas.find("factory-buildings-factory-building"),
|
||||
];
|
||||
},
|
||||
});
|
||||
|
||||
facc.solid = true;
|
||||
// basic factory stuff
|
||||
facc.requirements = ItemStack.with(Items.lead, 10, Items.copper, 20);
|
||||
facc.size = 4;
|
||||
facc.health = 1200;
|
||||
facc.group = null;
|
||||
facc.buildVisibility = BuildVisibility.shown;
|
||||
facc.category = Category.effect;
|
||||
facc.consumesTap = true;
|
||||
facc.consumesPower = true;
|
||||
|
||||
facc.buildType = () => extendContent(Wall.WallBuild, facc, {
|
||||
factory: null,
|
||||
|
||||
placed() {
|
||||
// this.factory =
|
||||
print(simulation.create(map, facc).toString());
|
||||
},
|
||||
|
||||
//load map on click
|
||||
tapped() {
|
||||
load(map, this);
|
||||
simulation.load(this.factory);
|
||||
},
|
||||
|
||||
//simulate factory
|
||||
updateTile() {
|
||||
this.factory = simulation.simulate(this.factory);
|
||||
}
|
||||
});
|
||||
};
|
137
scripts/factory-wall.js
Normal file
|
@ -0,0 +1,137 @@
|
|||
// big thank to deltanedas for the block texture code
|
||||
|
||||
module.exports = () => {
|
||||
const diags = [
|
||||
[-1, 1],
|
||||
[1, 1],
|
||||
[1, -1],
|
||||
[-1, -1]
|
||||
];
|
||||
|
||||
const all = [
|
||||
[-1, 1], [0, 1], [1, 1],
|
||||
[-1, 0], [1, 0],
|
||||
[-1, -1], [0, -1], [1, -1]
|
||||
];
|
||||
|
||||
const dirs = [
|
||||
{ x: 0, y: 1 },
|
||||
{ x: 1, y: 0 },
|
||||
{ x: 0, y: -1 },
|
||||
{ x: -1, y: 0 }
|
||||
];
|
||||
const wall = extendContent(Wall/*CoreBlock*/, "factory-wall", {
|
||||
load() {
|
||||
/* Edges and corners which depend on the placement */
|
||||
this.edgeRegions = [
|
||||
Core.atlas.find(this.name + "-edge_0"),
|
||||
Core.atlas.find(this.name + "-edge_1")
|
||||
];
|
||||
|
||||
this.cornerRegions = [];
|
||||
this.icornerRegions = [];
|
||||
for (var i = 0; i < 4; i++) {
|
||||
this.cornerRegions[i] = Core.atlas.find(this.name + "-corner_" + i);
|
||||
this.icornerRegions[i] = Core.atlas.find(this.name + "-icorner_" + i);
|
||||
}
|
||||
},
|
||||
|
||||
draw(tile) {
|
||||
this.super$draw(tile);
|
||||
this.drawEdges(tile);
|
||||
this.drawCorners(tile);
|
||||
},
|
||||
|
||||
drawEdges(tile) {
|
||||
const bits = tile.entity.blendBits;
|
||||
const dx = tile.drawx(), dy = tile.drawy();
|
||||
|
||||
for (var i = 0; i < 4; i++) {
|
||||
// First nibble has the edges
|
||||
if ((bits & (1 << i)) == 0) {
|
||||
Draw.rect(this.edgeRegions[i >> 1], dx, dy, 90 * -i);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
drawCorners(tile) {
|
||||
const bits = tile.entity.blendBits;
|
||||
const dx = tile.drawx(), dy = tile.drawy();
|
||||
|
||||
for (var i = 0; i < 4; i++) {
|
||||
if ((bits & (256 << i)) != 0) {
|
||||
// Third nibble has the inner corners, which take priority
|
||||
Draw.rect(this.icornerRegions[i], dx, dy);
|
||||
} else if ((bits & (16 << i)) == 0) {
|
||||
// Second nibble has the outer corners
|
||||
Draw.rect(this.cornerRegions[i], dx, dy);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
placed(tile) {
|
||||
this.super$placed(tile);
|
||||
|
||||
// Server doesn't care about drawing, stop
|
||||
if (!Vars.ui) return;
|
||||
|
||||
this.reblendAll(tile);
|
||||
this.reblend(tile);
|
||||
},
|
||||
|
||||
removed(tile) {
|
||||
this.reblendAll(tile);
|
||||
},
|
||||
|
||||
reblendAll(tile) {
|
||||
for (var i in all) {
|
||||
var other = tile.getNearby(all[i][0], all[i][1]);
|
||||
if (other && other.block() == wall) {
|
||||
this.reblend(other);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
reblend(tile) {
|
||||
// All edges and outer corners by default
|
||||
var bits = 0;
|
||||
|
||||
for (var i = 0; i < 4; i++) {
|
||||
var prev = this.adjacent(tile, (i + 3) % 4);
|
||||
var current = this.adjacent(tile, i);;
|
||||
if (current || prev) {
|
||||
// Can't be a corner
|
||||
bits |= 16 << i;
|
||||
if (current) {
|
||||
// Can't be a straight edge
|
||||
bits |= 1 << i;
|
||||
if (prev && this.interior(tile, i)) {
|
||||
// It's a bend, show inner corner
|
||||
bits |= 256 << i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tile.entity.blendBits = bits;
|
||||
},
|
||||
|
||||
adjacent(tile, i) {
|
||||
const other = tile.getNearby(dirs[i].x, dirs[i].y);
|
||||
return other && other.block() == this;
|
||||
},
|
||||
|
||||
/* Whether a router is a corner of a square or just a bend */
|
||||
interior(tile, i) {
|
||||
const diag = tile.getNearby(diags[i][0], diags[i][1]);
|
||||
return diag && diag.block() != this;
|
||||
}
|
||||
});
|
||||
|
||||
// h
|
||||
// wall.outputsPower = true;
|
||||
wall.consumesTap = true;
|
||||
wall.buildType = () => extendContent(WallBlock.WallBuild/*CoreBlock.CoreBuild*/, wall, {
|
||||
tapped() { }
|
||||
});
|
||||
};
|
|
@ -1,10 +0,0 @@
|
|||
module.exports = (map, from) => {
|
||||
map.tags = "{playerteam=1, rules={unitCap: 9999}, height=12, width=12}"
|
||||
|
||||
var rules = new Rules();
|
||||
rules.unitCap = 999;
|
||||
rules.bannedBlocks.add(from);
|
||||
|
||||
Vars.world.loadMap(map, rules);
|
||||
Vars.logic.play();
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
const maps = require("maps");
|
||||
// for (var i in Object.keys(maps))
|
||||
// print(maps[i])
|
||||
require("factory-building")(maps.small);//(maps.small);
|
||||
require("factory-building")(maps.small);
|
||||
require("factory-wall")();
|
||||
Vars.content.getByName(ContentType.block, "factory-buildings-factory-wall").buildVisibility = BuildVisibility.shown
|
|
@ -1,12 +1,11 @@
|
|||
var maps = Vars.maps.all();
|
||||
// wip
|
||||
var maps = Vars.maps.all().copy();
|
||||
maps = maps.filter(i => i.mod != null && i.mod.name == this.modName);
|
||||
print(maps.count(i => true));
|
||||
// maps = maps.sort((a, b) => a.name > b.name);
|
||||
// print(maps);
|
||||
|
||||
module.exports = {
|
||||
small: maps.get(0),
|
||||
// medium: maps[1],
|
||||
// large: maps[2],
|
||||
}
|
||||
|
||||
// const keys=(obj)=>Object.keys(obj).toString();
|
||||
// const keys = (obj) => Object.keys(obj).toString();
|
52
scripts/simulation.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
module.exports = {
|
||||
create: (map, from) => {
|
||||
// copy rules from normal world
|
||||
const orgin = { world: Vars.world, state: Vars.state };
|
||||
const rules = Vars.state.rules;
|
||||
|
||||
// create new world + state
|
||||
const world = new World;
|
||||
const state = new GameState;
|
||||
|
||||
// load map
|
||||
world.loadMap(map);
|
||||
|
||||
// set rules
|
||||
state.rules = rules;
|
||||
state.rules.canGameOver = false;
|
||||
state.rules.unitCap = 9999;
|
||||
state.rules.bannedBlocks.add(from);
|
||||
|
||||
for (var i = 0; i < world.height; i++) {
|
||||
for (var j = 0; j < world.width; j++) {
|
||||
// TODO: convert walls to team
|
||||
}
|
||||
}
|
||||
|
||||
// for some reason the above code kicks to main menu
|
||||
// Vars.world.load(orgin.world);
|
||||
// Vars.logic.play();
|
||||
|
||||
return { world: world, state: state };
|
||||
},
|
||||
|
||||
load: (factory) => {
|
||||
// copy player from normal world
|
||||
const unit = Vars.player.unit();
|
||||
|
||||
// load map
|
||||
Vars.state = factory.state;
|
||||
Vars.world = factory.world;
|
||||
Vars.logic.play();
|
||||
|
||||
// spawn player
|
||||
Vars.player.unit((unit.type || UnitTypes).alpha.spawn(5 * 8, 5 * 8));
|
||||
Vars.player.team(unit.team);
|
||||
Vars.player.unit().health = unit.health;
|
||||
},
|
||||
|
||||
simulate: (world) => {
|
||||
//TODO: simulate world
|
||||
return world;
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 469 B After Width: | Height: | Size: 838 B |
BIN
sprites/factory-wall/factory-wall-corner_0.png
Normal file
After Width: | Height: | Size: 584 B |
BIN
sprites/factory-wall/factory-wall-corner_1.png
Normal file
After Width: | Height: | Size: 553 B |
BIN
sprites/factory-wall/factory-wall-corner_2.png
Normal file
After Width: | Height: | Size: 571 B |
BIN
sprites/factory-wall/factory-wall-corner_3.png
Normal file
After Width: | Height: | Size: 561 B |
BIN
sprites/factory-wall/factory-wall-edge_0.png
Normal file
After Width: | Height: | Size: 545 B |
BIN
sprites/factory-wall/factory-wall-edge_1.png
Normal file
After Width: | Height: | Size: 537 B |
BIN
sprites/factory-wall/factory-wall-icorner_0.png
Normal file
After Width: | Height: | Size: 583 B |
BIN
sprites/factory-wall/factory-wall-icorner_1.png
Normal file
After Width: | Height: | Size: 569 B |
BIN
sprites/factory-wall/factory-wall-icorner_2.png
Normal file
After Width: | Height: | Size: 572 B |
BIN
sprites/factory-wall/factory-wall-iicorner_3.png
Normal file
After Width: | Height: | Size: 578 B |
BIN
sprites/factory-wall/factory-wall.png
Normal file
After Width: | Height: | Size: 702 B |