edit mode fixes
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user