unnatural organisms/more community creations

This commit is contained in:
MaxRobinsonTheGreat
2023-04-23 18:56:41 -05:00
parent d77e8c12f6
commit 53118e9340
24 changed files with 177 additions and 49 deletions

View File

@@ -427,6 +427,9 @@ class ControlPanel {
env.reset(true, false);
this.stats_panel.reset();
});
$('#brush-slider').on('input change', function () {
WorldConfig.brush_size = this.value;
});
$('#random-walls').click( function() {
this.env_controller.randomizeWalls();
}.bind(this));
@@ -434,7 +437,7 @@ class ControlPanel {
this.engine.env.clearWalls();
}.bind(this));
$('#clear-editor').click( function() {
this.engine.organism_editor.clear();
this.engine.organism_editor.setDefaultOrg();
this.editor_controller.setEditorPanel();
}.bind(this));
$('#generate-random').click( function() {

View File

@@ -54,6 +54,12 @@ class EditorController extends CanvasController{
updateDetails() {
$('.cell-count').text("Cell count: "+this.env.organism.anatomy.cells.length);
if (this.env.organism.isNatural()){
$('#unnatural-org-warning').css('display', 'none');
}
else {
$('#unnatural-org-warning').css('display', 'block');
}
}
defineCellTypeSelection() {
@@ -150,13 +156,14 @@ class EditorController extends CanvasController{
this.setEditorPanel();
else
this.setDetailsPanel();
}
setDetailsPanel() {
this.clearDetailsPanel();
var org = this.env.organism;
$('.cell-count').text("Cell count: "+org.anatomy.cells.length);
this.updateDetails();
$('#move-range').text("Move Range: "+org.move_range);
$('#mutation-rate').text("Mutation Rate: "+org.mutability);

View File

@@ -110,19 +110,18 @@ class EnvironmentController extends CanvasController{
switch(mode) {
case Modes.FoodDrop:
if (left_click){
this.dropCellType(cell.col, cell.row, CellStates.food, false);
this.dropCellType(cell.col, cell.row, CellStates.food, false, CellStates.wall);
}
else if (right_click){
this.dropCellType(cell.col, cell.row, CellStates.empty, false);
this.dropCellType(cell.col, cell.row, CellStates.empty, false, CellStates.wall);
}
break;
case Modes.WallDrop:
if (left_click){
this.dropCellType(cell.col, cell.row, CellStates.wall, true);
}
else if (right_click){
this.dropCellType(cell.col, cell.row, CellStates.empty, false);
this.dropCellType(cell.col, cell.row, CellStates.empty, false, CellStates.food);
}
break;
case Modes.ClickKill:
@@ -144,26 +143,25 @@ class EnvironmentController extends CanvasController{
}
break;
case Modes.Drag:
var cur_top = parseInt($('#env-canvas').css('top'), 10);
var cur_left = parseInt($('#env-canvas').css('left'), 10);
var new_top = cur_top + ((this.mouse_y - this.start_y)*this.scale);
var new_left = cur_left + ((this.mouse_x - this.start_x)*this.scale);
$('#env-canvas').css('top', new_top+'px');
$('#env-canvas').css('left', new_left+'px');
this.dragScreen();
break;
}
}
else if (this.middle_click) {
//drag on middle click
var cur_top = parseInt($('#env-canvas').css('top'), 10);
var cur_left = parseInt($('#env-canvas').css('left'), 10);
var new_top = cur_top + ((this.mouse_y - this.start_y)*this.scale);
var new_left = cur_left + ((this.mouse_x - this.start_x)*this.scale);
$('#env-canvas').css('top', new_top+'px');
$('#env-canvas').css('left', new_left+'px');
this.dragScreen();
}
}
dragScreen() {
var cur_top = parseInt($('#env-canvas').css('top'), 10);
var cur_left = parseInt($('#env-canvas').css('left'), 10);
var new_top = cur_top + ((this.mouse_y - this.start_y)*this.scale);
var new_left = cur_left + ((this.mouse_x - this.start_x)*this.scale);
$('#env-canvas').css('top', new_top+'px');
$('#env-canvas').css('left', new_left+'px');
}
dropOrganism(organism, col, row) {
// close the organism and drop it in the world
@@ -187,8 +185,8 @@ class EnvironmentController extends CanvasController{
return false;
}
dropCellType(col, row, state, killBlocking=false) {
for (var loc of Neighbors.allSelf){
dropCellType(col, row, state, killBlocking=false, ignoreState=null) {
for (var loc of Neighbors.inRange(WorldConfig.brush_size)){
var c=col + loc[0];
var r=row + loc[1];
var cell = this.env.grid_map.cellAt(c, r);
@@ -200,23 +198,32 @@ class EnvironmentController extends CanvasController{
else if (cell.owner != null) {
continue;
}
if (ignoreState != null && cell.state == ignoreState)
continue;
this.env.changeCell(c, r, state, null);
}
}
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 != null && cell.owner != null)
return cell.owner;
let closest = null;
let closest_dist = 100;
for (let loc of Neighbors.inRange(WorldConfig.brush_size)){
let c = this.cur_cell.col + loc[0];
let r = this.cur_cell.row + loc[1];
let cell = this.env.grid_map.cellAt(c, r);
let dist = Math.abs(loc[0]) + Math.abs(loc[1]);
if (cell != null && cell.owner != null) {
if (closest === null || dist < closest_dist) {
closest = cell.owner;
closest_dist = dist;
}
}
}
return null;
return closest;
}
killNearOrganisms() {
for (var loc of Neighbors.allSelf){
for (var loc of Neighbors.inRange(WorldConfig.brush_size)){
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);

View File

@@ -11,7 +11,6 @@ const LoadController = {
});
let panel = this;
$(".load-panel").on('click', '.list-item', async function() {
console.log('howdy')
let list_name = $(this).closest(".list-container").attr('id');
let value = $(this).find('.hidden-value').text();
if (list_name === 'worlds-list-container') {
@@ -61,12 +60,13 @@ const LoadController = {
let id = `#${name}-list`
$(id).empty();
for (let item of list) {
$(id).append(
`<li class="list-item">
${item.name}
<div class="hidden-value" hidden>${item.value}</div>
</li>`
);
let html = `<li class="list-item">
${item.name}`;
if (item.subname)
html += `<br>(${item.subname})`;
html +=`<div class="hidden-value" hidden>${item.value}</div>
</li>`;
$(id).append(html);
}
},