edit mode fixes
This commit is contained in:
@@ -29,7 +29,7 @@ class ControlPanel {
|
||||
$('#fps').text("Target FPS: "+this.fps);
|
||||
}.bind(this);
|
||||
$('#pause-button').click(function() {
|
||||
if ($('#pause-button').text() == "Pause" && this.engine.running) {
|
||||
if (this.engine.running) {
|
||||
$('#pause-button').text("Play");
|
||||
this.engine.stop();
|
||||
}
|
||||
@@ -150,14 +150,10 @@ class ControlPanel {
|
||||
|
||||
defineModeControls() {
|
||||
var self = this;
|
||||
$('#editor-mode').change( function(el) {
|
||||
var selection = $(this).children("option:selected").val();
|
||||
$('.edit-mode-btn').click( function() {
|
||||
var prev_mode = self.env_controller.mode;
|
||||
$('#cell-selections').css('display', 'none');
|
||||
switch(selection){
|
||||
case "none":
|
||||
self.setMode(Modes.None);
|
||||
break;
|
||||
switch(this.id){
|
||||
case "food":
|
||||
self.setMode(Modes.FoodDrop);
|
||||
break;
|
||||
@@ -168,27 +164,20 @@ class ControlPanel {
|
||||
self.setMode(Modes.ClickKill);
|
||||
break;
|
||||
case "select":
|
||||
if (prev_mode==Modes.Edit || prev_mode==Modes.Clone && self.engine.organism_editor.organism.cells.length > 1){
|
||||
if (confirm("Selecting a new organism will clear the current organism. Are you sure you wish to switch?")) {
|
||||
self.setMode(Modes.Select);
|
||||
}
|
||||
else {
|
||||
$("#editor-mode").val('edit');
|
||||
}
|
||||
}
|
||||
else {
|
||||
self.setMode(Modes.Select);
|
||||
}
|
||||
self.setMode(Modes.Select);
|
||||
break;
|
||||
case "edit":
|
||||
self.setMode(Modes.Edit);
|
||||
$('#cell-selections').css('display', 'grid');
|
||||
$('#cell-selections').css('display', 'block');
|
||||
break;
|
||||
case "clone":
|
||||
case "drop-org":
|
||||
self.setMode(Modes.Clone);
|
||||
self.env_controller.org_to_clone = self.engine.organism_editor.getCopyOfOrg();
|
||||
break;
|
||||
}
|
||||
$('.edit-mode-btn').css('background-color', 'white');
|
||||
$('#'+this.id).css('background-color', 'lightblue');
|
||||
|
||||
});
|
||||
|
||||
var env = this.engine.env;
|
||||
@@ -198,11 +187,10 @@ class ControlPanel {
|
||||
$('#auto-reset').change(function() {
|
||||
env.auto_reset = this.checked;
|
||||
});
|
||||
$('#kill-all').click( function() {
|
||||
this.engine.env.clearOrganisms();
|
||||
}.bind(this));
|
||||
$('#clear-walls').click( function() {
|
||||
this.engine.env.clearWalls();
|
||||
if (confirm("Are you sure you want to clear all the walls?")) {
|
||||
this.engine.env.clearWalls();
|
||||
}
|
||||
}.bind(this));
|
||||
$('#clear-editor').click( function() {
|
||||
this.engine.organism_editor.clear();
|
||||
@@ -232,6 +220,8 @@ class ControlPanel {
|
||||
this.organism_record = org_count;
|
||||
$('#org-record').text("Highest count: " + this.organism_record);
|
||||
$('#avg-mut').text("Average Mutation Rate: " + Math.round(this.engine.env.averageMutability() * 100) / 100);
|
||||
$('#largest-org').text("Largest Organism: " + this.engine.env.largest_cell_count + " cells");
|
||||
$('#reset-count').text("Auto reset count: " + this.engine.env.reset_count);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,10 +12,15 @@ class EditorController extends CanvasController{
|
||||
}
|
||||
|
||||
mouseMove() {
|
||||
|
||||
if (this.right_click || this.left_click)
|
||||
this.editOrganism();
|
||||
}
|
||||
|
||||
mouseDown() {
|
||||
this.editOrganism();
|
||||
}
|
||||
|
||||
editOrganism() {
|
||||
if (this.edit_cell_type == null || this.mode != Modes.Edit)
|
||||
return;
|
||||
if (this.left_click)
|
||||
|
||||
@@ -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