Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                h1 creep calculator for 
	a(href="https://screeps.com") screeps.com
div.content.top(ng-app='calc' ng-controller="parts")
	.controls
		table
			tr
				th part/struct
				th price
				th
				th count 
				th 
				th sum
			tr(ng-repeat='i in parts' ng-class="{have: i.count && i.mul<0, source: i.count && i.mul>0, error: i.count<i.min}")
				td {{ i.type }}
				td {{ i.price }}
				td
					button(tabindex="-1" ng-click="i.count = i.min") min
					button(tabindex="-1" ng-click="subtract(i.type)") -
				td: input(type="number" ng-model="i.count" size="5")
				td
					button(tabindex="-1" ng-click="add(i.type)") +
					button(tabindex="-1" ng-if="i.type!=='spawn'" ng-click="add(i.type, 10)") +10
				td {{ i.count * i.price * i.mul }}
			tr
				th.left
					span units*
						input(type="number" ng-model="units" ng-init="units=1")
				th
				th parts
				th(ng-class="{error: getPartsCount()>50}") {{ getPartsCount() | num:0 }}
					span(title="all parts") ({{ getPartsCount()*units | num:0 }})
				th sum
				th {{ getSum()*units | num }}
			tr
				th.left
					label(for="controllerLevelId") controller: 
					select(id="controllerLevelId" ng-model="controllerLevel" ng-options="l as l.text for l in controllerLevels")
				th
				th
				th
				th(title="number of units keeps builded from one source") per source
				th {{ (1500/300*3000 / getSum() / units) | num }}
			tr
				th
				th
				th
				th
				th balance
				th(ng-class="{error: getBalance()<0}") {{ getBalance() | num }}
		div
			.fr
				button(ng-click="parseInput()") parse
				button(ng-click="reset()") reset
			div
				label(for="inputTextId") field to parse body array
				textarea(id="inputTextId" ng-model="inputText" rows="2")
						
			
			
			
			
	.stats
		table.stats(border="1")
			tr
				td health:
				td(colspan="4") {{ getPartsCount()*100*units | num }} (by TOUGH {{assoc['TOUGH'].count*100*units  | num }})
			tr(ng-repeat="stat in [\
				{name: 'harvest', part: 'WORK', mul: 2},\
				{name: 'upgradeController', part: 'WORK', mul: 1},\
				{name: 'build walls/ramparts', part: 'WORK', mul: 100},\
				{name: 'build structures', part: 'WORK', mul: 5},\
				{name: 'attack', part: 'ATTACK', mul: 30},\
				{name: 'ranged attack', part: 'RANGED_ATTACK', mul: 10},\
				{name: 'mass attack 1', part: 'RANGED_ATTACK', mul: 10},\
				{name: 'mass attack 2', part: 'RANGED_ATTACK', mul: 4},\
				{name: 'mass attack 3', part: 'RANGED_ATTACK', mul: 1},\
				{name: 'heal', part: 'HEAL', mul: 10},\
				{name: 'ranged heal', part: 'HEAL', mul: 4},\
				]")
				td {{ ::stat.name }}
				td {{ assoc[stat.part].count*stat.mul*units | num }}
					span.tip /T
				td {{ assoc[stat.part].count*stat.mul*1500*units | num }}
					span.tip /1500T
				td {{ assoc[stat.part].count*stat.mul*60*60*units | num }}
					span.tip /H
				td {{ assoc[stat.part].count*stat.mul*60*60*24*units | num }}
					span.tip /D
			tr
				td carry
				td(colspan="4") {{ assoc['CARRY'].count*50*units | num }}
			tr
				td walk time empty,full
				td(colspan="4")
					span(ng-repeat="place in [\
						{name: 'plain', k:1},\
						{name: 'road', k:0.5},\
						{name: 'swamp', k:5},\
					]") {{ place.name }}=
						span {{ getWait(place.k, false) }},
						span {{ getWait(place.k, true) }}&nbsp;&nbsp; 
		div
			textarea(rows="2" onmouseup="this.select()" ng-model="getParts()")
			br
			div: textarea(rows="1" onmouseup="this.select()" ng-model="getParts(true)")

div links
	ul
		li: a(href="http://jsonviewer.stack.hu/") good online JSON viewer

div changes
	ul
		li 2015-08-26 fixed harvest amount
		li 2015-10-08 max parts warning set to 50
		li 2015-10-14 fixed attack,heal values; added units multiplier; captions shinked;
              
            
!

CSS

              
                tr:nth-child(odd) {
	background-color: #f8f8f8;
}

tr.have {
	background-color: #ff0;
}

tr.source {
	background-color: #afa;
}

tr.error, td.error, th.error {
	background-color: #f88 !important;
}

textarea {
	width: calc(100% - 4px);
	border: 1px solid #888;
	padding: 1px;
	margin: 1px;
}

div.controls, div.stats { display: inline-block; padding: 10px; }

table.stats {
	border-collapse: collapse;
	width: calc(100% - 4px);
	border: 1px solid #888;
	padding: 1px;
	margin: 1px;
}

table.stats td {
	padding: 4px;
}

table.stats tr td:nth-child(2), td:nth-child(3), td:nth-child(4) {
	text-align: center;
}

span.tip {
	color: grey;
}

.left {
	text-align: left;
}

.fr {
	float: right;
}

.top {
	display: table-cell;
	vertical-align: top;
}

h1 {
	font-size: 28px;
	margin: 2px;
	padding: 1px;
}

button, select, input {
	border: 1px solid #ccc;
	border-radius: 4px;
	padding: 4px;
	margin: 1px;
	background-color: #e8e8a0;
}

button:focus, select:focus, input:focus {
	border: 1px solid #000;
}
              
            
!

JS

              
                angular.module('calc', [])
.controller('parts',function($scope){
	var assoc = $scope.assoc = {};
	$scope.add = function(type, n){
		var t = assoc[type];
		if(!n)
			n = 1;
		t.count = +t.count + +n;
	};
	$scope.subtract = function(type){
		var t = assoc[type];
		if(t.count===t.min)
			return;
		t.count -= 1;
	};
	$scope.parts = [
		{type: 'TOUGH', price: 10, count: 0, mul: -1},
		{type: 'MOVE', price: 50, count: 1, mul: -1, min: 1},
		{type: 'WORK', price: 100, count: 0, mul: -1},
		{type: 'CARRY', price: 50, count: 0, mul: -1},
		{type: 'ATTACK', price: 80, count: 0, mul: -1},
		{type: 'RANGED_ATTACK', price: 150, count: 0, mul: -1},
		{type: 'HEAL', price: 250, count: 0, mul: -1},
		{type: 'spawn', price: 300, count: 1, mul: 1, min: 1},
		{type: 'extension', price: 50, count: 0, mul: 1},
	];
	for(var t of $scope.parts){
		assoc[t.type] = t;
		t.min = t.min || 0;
	}
	$scope.getBalance = function(){
		var s = 0;
		for(var t of $scope.parts){
			s += t.count * t.price * t.mul;
		}
		return s;
	}
	$scope.getSum = function(){
		var s = 0;
		for(var t of $scope.parts){
			if(t.mul<0)
				s += t.count * t.price;
		}
		return s;
	}
	$scope.getPartsCount = function(){
		var c = 0;
		for(var t of $scope.parts)
			if(t.mul<0)
				c += +t.count;
		return c;
	}
	$scope.getParts = function(hm){
		if(hm){
			return $scope.parts
				.filter(function(part){ return part.count>0 && part.mul<0;})
				.map(function(part){ return part.type+'*'+part.count;})
				.join(',');
		}
		var out = [];
		for(var t of $scope.parts){
			if(t.mul>0)
				continue;
			var a = [];
			for(var j=0; j<t.count; ++j)
					out.push(t.type);
		}
		return '['+out.join(',')+']';
	}
	$scope.reset = function(){
			for(var i in $scope.parts)
				if($scope.parts[i].mul<0)
					$scope.parts[i].count = $scope.parts[i].min;
	}
	$scope.parseInput = function(){
		for(var p of $scope.parts)
			if(p.mul<0){
				var match = $scope.inputText.match(new RegExp("\\b"+p.type+"\\b", 'g'));
				p.count = match ? Math.max(match.length, p.min) : p.min;
			}
	}
	$scope.controllerLevels = [
		{spawns: 0, extensions: 0, text: 'no (='},
		{spawns: 1, extensions: 0, text: '1'},
		{spawns: 1, extensions: 5, text: '2'},
		{spawns: 1, extensions: 10, text: '3'},
		{spawns: 1, extensions: 20, text: '4'},
		{spawns: 1, extensions: 30, text: '5'},
		{spawns: 1, extensions: 40, text: '6'},
		{spawns: 2, extensions: 50, text: '7'},
		{spawns: 3, extensions: 200, text: '8'},
	];
	$scope.controllerLevel = $scope.controllerLevels['1'];
	$scope.$watch('controllerLevel', function(val){
			if(!val)
				return;
			assoc['spawn'].count = val.spawns;
			assoc['extension'].count = val.extensions;
	});
	$scope.maxHarvest = function(mul){
		return Math.min(60*60/300*1500*mul, assoc['WORK'].count*5*60*60*mul);
	};
/*
t = ceil(k * W / M)

Where:
    t = time (game ticks)
    k = terrain factor (1x for plain, 0.5x for road, 5x for swamp)
    W = creep weight (Number of body parts, excluding MOVE and empty CARRY parts)
    M = number of MOVE parts
*/
	$scope.getWait = function(k, full){
		var W = $scope.getPartsCount() - +assoc['MOVE'].count - (full ? 0 : +assoc['CARRY'].count);
		var M = +assoc['MOVE'].count;
		var speed = Math.ceil(k * W / M);
		return Math.max(1,speed);
	};
})

.filter('num', function(){
	return function(n, w){
		if(w === undefined)
				w = 3;
		if(n<1000)
			return n.toFixed(w);
		else if(n<1000000)
			return (n/1000).toFixed(w)+'K';
		else
			return (n/1000000).toFixed(w)+'M';
	};
})

;
              
            
!
999px

Console