Skip to content

Copy organism Discord emoji code to clipboard with one click! #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dist/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ button:active{
#editor-panel{
display: flex;
}
.edit-mode-btn {
.edit-mode-btn, .copy-code {
width: 30px;
height: 30px;
margin-top: 5px;
Expand All @@ -184,7 +184,7 @@ button:active{
#organism-options {
display: none;
}
#drop-org {
#copy-dc-code {
bottom: 0;
}
#editor-env {
Expand Down
13 changes: 8 additions & 5 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<title>The Life Engine</title>
<link rel="icon" href="./img/icon.png">
<link rel="stylesheet" href="./css/style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/v4-shims.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>

Expand Down Expand Up @@ -67,8 +68,9 @@ <h3>The Life Engine</h3>
<iframe id="video" src="https://www.youtube.com/embed/iSAKEnRfles"></iframe>
</div>
<div class='icon-links'>
<a href=https://github.com/MaxRobinsonTheGreat/EvolutionSimulatorV2 title='View the code'><i class="fa fa-github"></i></a>
<a href="https://twitter.com/max_romana"><i class="fa fa-twitter"></i></a>
<a href=https://github.com/MaxRobinsonTheGreat/EvolutionSimulatorV2 target="_blank" title='View the code'><i class="fa fa-github"></i></a>
<a href="https://discord.com/invite/ZsrAAByEnr" target="_blank" title='Join the growing community'><i class="fab fa-discord"></i></a>
<a href="https://twitter.com/max_romana" target="_blank"><i class="fa fa-twitter"></i></a>
</div>
</div>

Expand All @@ -78,6 +80,7 @@ <h3>The Life Engine</h3>
<button class="edit-mode-btn select" id="select" title="Select organism from world. Hotkey: Z"><i class="fa fa-hand-pointer-o"></i></button>
<button class="edit-mode-btn edit" id="edit" title="Edit organism. Hotkey: X"><i class="fa fa-pencil"></i></button>
<button class="edit-mode-btn drop-org" id="drop-org" title="Drop organism in world. Hotkey: C"><i class="fa fa-plus"></i></button>
<button class="copy-code" id='copy-dc-code' title='Copy organism emoji code to clipboard Hotkey: V (Emergent Garden server)'><i class="fab fa-discord"></i></button>
</div>
<div id='editor-env'>
<canvas id='editor-canvas'></canvas>
Expand Down Expand Up @@ -120,7 +123,7 @@ <h3>Edit Organism</h3>
<p class='cell-count'>Cell count: </p>
<div id='move-range-cont'>
<label for="move-range-edit" title='The number of cells to move before randomly changing direction. Overriden by brain decisions.'>Move Range:</label>
<input type="number" id="move-range-edit" min="1" max="100" value=3 step="1">
<input type="number" id="move-range-edit" min="1" max="100" value=4 step="1">
</div>
<div id='mutation-rate-cont'>
<label for="mutation-rate-edit" title='Probability that offspring of this organism will mutate'>Mutation Rate:</label>
Expand Down Expand Up @@ -183,7 +186,7 @@ <h3>Reset Options</h3>
<div class='right-half'>
<br>
<button id='random-walls' title="Generates random walls.">Generate random walls</button> <br>
<button id="clear-walls" title="Clear All Walls. Hotkey: B">Clear all walls</button>
<button id="clear-walls" title="Clear All Walls. Hotkey: N">Clear all walls</button>
<br>
<label for="clear-walls-reset" title='When on, walls will be cleared when the environment resets'>Clear walls on reset</label>
<input type="checkbox" id="clear-walls-reset">
Expand Down
96 changes: 94 additions & 2 deletions src/Controllers/ControlPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const Modes = require("./ControlModes");
const StatsPanel = require("../Stats/StatsPanel");
const RandomOrganismGenerator = require("../Organism/RandomOrganismGenerator")
const WorldConfig = require("../WorldConfig");
const CellStates = require("../Organism/Cell/CellStates");

class ControlPanel {
constructor(engine) {
Expand Down Expand Up @@ -90,7 +91,10 @@ class ControlPanel {
case 'c':
$('#drop-org').click();
break;
case 'v': // toggle hud
case 'v':
$('#copy-dc-code').click();
break;
case 'b': // toggle hud
if (this.no_hud) {
let control_panel_display = this.control_panel_active ? 'grid' : 'none';
let hot_control_display = !this.control_panel_active ? 'block' : 'none';
Expand All @@ -106,7 +110,7 @@ class ControlPanel {
}
this.no_hud = !this.no_hud;
break;
case 'b':
case 'n':
$('#clear-walls').click();
}
});
Expand Down Expand Up @@ -361,6 +365,94 @@ class ControlPanel {
this.env_controller.resetView();
}.bind(this));

$('#copy-dc-code').click( function(){
let org = this.engine.organism_editor.organism;
let anatomy = org.anatomy;
let cells = anatomy.cells;
let code = "";
let startx = 0;
let starty = 0;
let endx = 0;
let endy = 0;

for (var cell of cells) {
if(cell.loc_col < startx) {
startx = cell.loc_col;
}
if(cell.loc_col > endx) {
endx = cell.loc_col;
}
if(cell.loc_row < starty) {
starty = cell.loc_row;
}
if(cell.loc_row > endy) {
endy = cell.loc_row;
}
}
//iterate from top left to bottom right
for(var i = starty; i <= endy; i++) {
for(var j = startx; j <= endx; j++) {
let cell = cells.find(c => c.loc_row == i && c.loc_col == j);
if(cell == undefined) {
code += CellStates.empty.dc_code;
}else {
if(cell.state.dc_code == ':eye:'){
switch (cell.direction) {
case 0://up
code += ':eyeu:';
break;
case 1://right
code += ':eyer:';
break;
case 2://down
code += ':eyed:';
break;
case 3://left
code += ':eyel:';
break;
default:
code += ':eye:';
break;
}
}else{
code += cell.state.dc_code;
}
}
}

code += '\n';
}

code += "Cell Count: " + cells.length + "\n";
if(anatomy.is_mover) code += "Move Range: " + org.move_range + "\n";
code += "Mutation Rate: " + org.mutability + "\n";
if(anatomy.is_mover && anatomy.has_eyes){
let brain = org.brain;

let chase_types = [];
let retreat_types = [];
for(let cell_name in brain.decisions) {
let decision = brain.decisions[cell_name];
if (decision == 1) {
retreat_types.push(cell_name)
}
else if (decision == 2) {
chase_types.push(cell_name);
}
}

if(chase_types.length > 0) {
code += "Move Towards: " + chase_types.join(', ') + "\n";
}
if(retreat_types.length > 0) {
code += "Move Away From: " + retreat_types.join(', ') + "\n";
}
}

console.log(code);
navigator.clipboard.writeText(code);
}.bind(this));

var env = this.engine.env;
$('#reset-env').click( function() {
env.reset();
Expand Down
21 changes: 11 additions & 10 deletions src/Organism/Cell/CellStates.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// A cell state is used to differentiate type and render the cell
class CellState{
constructor(name) {
constructor(name, dc_code = ':__:') {
this.name = name;
this.color = 'black';
this.dc_code = dc_code;
}

render(ctx, cell, size) {
Expand All @@ -13,47 +14,47 @@ class CellState{

class Empty extends CellState {
constructor() {
super('empty');
super('empty',':vd:');
}
}
class Food extends CellState {
constructor() {
super('food');
super('food',':food:');
}
}
class Wall extends CellState {
constructor() {
super('wall');
super('wall',':wall:');
}
}
class Mouth extends CellState {
constructor() {
super('mouth');
super('mouth',':eat:');
}
}
class Producer extends CellState {
constructor() {
super('producer');
super('producer',':prod:');
}
}
class Mover extends CellState {
constructor() {
super('mover');
super('mover',':mov:');
}
}
class Killer extends CellState {
constructor() {
super('killer');
super('killer',':kill:');
}
}
class Armor extends CellState {
constructor() {
super('armor');
super('armor',':arm:');
}
}
class Eye extends CellState {
constructor() {
super('eye');
super('eye',':eye:');
this.slit_color = 'black';
}
render(ctx, cell, size) {
Expand Down