edit mode fixes

This commit is contained in:
MaxRobinsonTheGreat
2020-07-22 12:07:27 -06:00
parent c94e137ae4
commit b0292ae0e6
10 changed files with 152 additions and 390 deletions

View File

@@ -2,6 +2,8 @@ const CanvasController = require("./CanvasController");
const Organism = require('../Organism/Organism');
const Modes = require("./ControlModes");
const CellTypes = require("../Organism/Cell/CellTypes");
const Neighbors = require("../Grid/Neighbors");
const Cell = require("../Organism/Cell/Cell");
class EnvironmentController extends CanvasController{
constructor(env, canvas) {
@@ -29,27 +31,30 @@ class EnvironmentController extends CanvasController{
}
switch(mode) {
case Modes.FoodDrop:
if (left_click && cell.type == CellTypes.empty){
this.env.changeCell(cell.col, cell.row, CellTypes.food, null);
if (left_click){
this.dropCellType(cell.col, cell.row, CellTypes.food, false);
}
else if (right_click && cell.type == CellTypes.food){
this.env.changeCell(cell.col, cell.row, CellTypes.empty, null);
else if (right_click){
this.dropCellType(cell.col, cell.row, CellTypes.empty, false);
}
break;
case Modes.WallDrop:
if (left_click && (cell.type == CellTypes.empty || cell.type == CellTypes.food)){
this.env.changeCell(cell.col, cell.row, CellTypes.wall, null);
if (left_click){
this.dropCellType(cell.col, cell.row, CellTypes.wall, true);
}
else if (right_click && cell.type == CellTypes.wall){
this.env.changeCell(cell.col, cell.row, CellTypes.empty, null);
else if (right_click){
this.dropCellType(cell.col, cell.row, CellTypes.empty, false);
}
break;
case Modes.ClickKill:
if (this.cur_org != null)
this.cur_org.die();
this.killNearOrganisms();
break;
case Modes.Select:
if (this.cur_org == null) {
this.cur_org = this.findNearOrganism();
}
if (this.cur_org != null){
this.control_panel.setEditorOrganism(this.cur_org);
}
@@ -67,12 +72,42 @@ class EnvironmentController extends CanvasController{
}
}
dropWall(cell) {
dropCellType(col, row, type, killBlocking=false) {
for (var loc of Neighbors.allSelf){
var c=col + loc[0];
var r=row + loc[1];
var cell = this.env.grid_map.cellAt(c, r);
if (cell == null)
continue;
if (killBlocking && cell.owner != null){
cell.owner.die();
}
else if (cell.owner != null) {
continue;
}
this.env.changeCell(c, r, type, null);
}
}
dropFood(cell) {
findNearOrganism() {
for (var loc of Neighbors.all){
var c = this.cur_cell.col + loc[0];
var r = this.cur_cell.row + loc[1];
var cell = this.env.grid_map.cellAt(c, r);
if (cell.owner != null)
return cell.owner;
}
return null;
}
killNearOrganisms() {
for (var loc of Neighbors.allSelf){
var c = this.cur_cell.col + loc[0];
var r = this.cur_cell.row + loc[1];
var cell = this.env.grid_map.cellAt(c, r);
if (cell.owner != null)
cell.owner.die();
}
}