it kinda works
This commit is contained in:
parent
b234305690
commit
d5046535c9
4 changed files with 150 additions and 143 deletions
Binary file not shown.
|
@ -4,7 +4,7 @@ module.exports = (map) => {
|
|||
var facc = extendContent(Wall, "factory-building", {
|
||||
icons() {
|
||||
return [
|
||||
Core.atlas.find("factory-buildings-factory-building"),
|
||||
Core.atlas.find(this.name),
|
||||
];
|
||||
},
|
||||
});
|
||||
|
@ -17,24 +17,27 @@ module.exports = (map) => {
|
|||
facc.buildVisibility = BuildVisibility.shown;
|
||||
facc.category = Category.effect;
|
||||
facc.consumesTap = true;
|
||||
facc.consumesPower = true;
|
||||
// facc.hasPower = true;
|
||||
// facc.outputsPower = true;
|
||||
// facc.consumesPower = true;
|
||||
|
||||
facc.buildType = () => extendContent(Wall.WallBuild, facc, {
|
||||
factory: null,
|
||||
|
||||
placed() {
|
||||
// this.factory =
|
||||
print(simulation.create(map, facc).toString());
|
||||
},
|
||||
pocketDimension: {},
|
||||
used: false,
|
||||
|
||||
//load map on click
|
||||
tapped() {
|
||||
simulation.load(this.factory);
|
||||
if (this.used) simulation.load(this.pocketDimension);
|
||||
|
||||
if (!this.used) {
|
||||
this.pocketDimension = simulation.create(map, facc);
|
||||
this.used = true;
|
||||
}
|
||||
},
|
||||
|
||||
//simulate factory
|
||||
updateTile() {
|
||||
this.factory = simulation.simulate(this.factory);
|
||||
if (this.used) this.pocketDimension = simulation.tick(this.pocketDimension);
|
||||
}
|
||||
});
|
||||
};
|
|
@ -1,137 +1,139 @@
|
|||
// big thank to deltanedas for the block texture code
|
||||
|
||||
module.exports = () => {
|
||||
const diags = [
|
||||
[-1, 1],
|
||||
[1, 1],
|
||||
[1, -1],
|
||||
[-1, -1]
|
||||
];
|
||||
// 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 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")
|
||||
];
|
||||
// const dirs = [
|
||||
// { x: 0, y: 1 },
|
||||
// { x: 1, y: 0 },
|
||||
// { x: 0, y: -1 },
|
||||
// { x: -1, y: 0 }
|
||||
// ];
|
||||
const wall = extendContent(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);
|
||||
}
|
||||
},
|
||||
// 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);
|
||||
},
|
||||
// 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();
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
},
|
||||
// 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();
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
},
|
||||
// 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);
|
||||
// placed(tile) {
|
||||
// this.super$placed(tile);
|
||||
|
||||
// Server doesn't care about drawing, stop
|
||||
if (!Vars.ui) return;
|
||||
// // Server doesn't care about drawing, stop
|
||||
// if (!Vars.ui) return;
|
||||
|
||||
this.reblendAll(tile);
|
||||
this.reblend(tile);
|
||||
},
|
||||
// this.reblendAll(tile);
|
||||
// this.reblend(tile);
|
||||
// },
|
||||
|
||||
removed(tile) {
|
||||
this.reblendAll(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);
|
||||
}
|
||||
}
|
||||
},
|
||||
// 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;
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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;
|
||||
},
|
||||
// tile.entity.blendBits = bits;
|
||||
// },
|
||||
|
||||
adjacent(tile, i) {
|
||||
const other = tile.getNearby(dirs[i].x, dirs[i].y);
|
||||
return other && other.block() == this;
|
||||
},
|
||||
// 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;
|
||||
}
|
||||
// /* 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, {
|
||||
wall.unitType = null;
|
||||
wall.unitCapModifier = 0;
|
||||
wall.buildType = () => extendContent(CoreBlock.CoreBuild, wall, {
|
||||
tapped() { }
|
||||
});
|
||||
};
|
|
@ -1,52 +1,54 @@
|
|||
module.exports = {
|
||||
create: (map, from) => {
|
||||
// copy rules from normal world
|
||||
const simulation = {
|
||||
create: function (map, from) {
|
||||
// copy rules/world 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;
|
||||
// copy player from normal world
|
||||
const unit = Vars.player.unit();
|
||||
|
||||
// load map
|
||||
world.loadMap(map);
|
||||
Vars.world.loadMap(map);
|
||||
|
||||
// set rules
|
||||
state.rules = rules;
|
||||
state.rules.canGameOver = false;
|
||||
state.rules.unitCap = 9999;
|
||||
state.rules.bannedBlocks.add(from);
|
||||
Vars.state.rules.canGameOver = false;
|
||||
Vars.state.rules.unitCap = 9999;
|
||||
Vars.state.rules.bannedBlocks.add(from);
|
||||
|
||||
for (var i = 0; i < world.height; i++) {
|
||||
for (var j = 0; j < world.width; j++) {
|
||||
for (var i = 0; i < map.height; i++) {
|
||||
for (var j = 0; j < map.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();
|
||||
this.setPlayer(unit);
|
||||
Vars.logic.play();
|
||||
|
||||
return { world: world, state: state };
|
||||
return { world: Vars.world, state: Vars.state, orgin: orgin };
|
||||
},
|
||||
|
||||
load: (factory) => {
|
||||
// copy player from normal world
|
||||
const unit = Vars.player.unit();
|
||||
|
||||
load: function (factory) {
|
||||
// load map
|
||||
Vars.state = factory.state;
|
||||
Vars.world = factory.world;
|
||||
Vars.logic.play();
|
||||
|
||||
this.setPlayer();
|
||||
},
|
||||
|
||||
setPlayer: function (unit) {
|
||||
Groups.unit.clear();
|
||||
|
||||
// spawn player
|
||||
Vars.player.unit((unit.type || UnitTypes).alpha.spawn(5 * 8, 5 * 8));
|
||||
print(unit.type);
|
||||
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) => {
|
||||
tick: function (world) {
|
||||
//TODO: simulate world
|
||||
return world;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = simulation;
|
Loading…
Reference in a new issue