Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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

              
                table#table
	tr
		th Name
		th Pieces Needed
		th Sets That You Can Use
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Roboto');

html,
body {
	font-family: 'Roboto', sans-serif;
	background: black;
	color: white;
	font-size: 14px;
}

table {
	border-collapse: collapse;
}

tr {
	&:not(:last-child) {
		border-bottom: 1px solid hsla(0, 0%, 100%, 0.2);
	}
}

td, th {
	vertical-align: top;
	padding: 4px;
	
	&:not(:last-child) {
		border-right: 1px solid hsla(0, 0%, 100%, 0.2);
	}
	
	div {
		padding: 3px 4px;
		
		&:hover {
			background-color: hsla(0, 0%, 100%, 0.05);
		}
		&:not(:last-child) {
			border-bottom: 1px solid hsla(0, 0%, 100%, 0.075);
		}
	}
}
              
            
!

JS

              
                let data;

function preload() {
	data = loadJSON('https://alca.tv/static/codepen/pens/GvZdJY/magformers.js');
}

function makeName(key, count) {
	let name = key.split('_')
		.reduce((p, n) => `${p} ${n[0].toUpperCase() + n.slice(1)}`, '');
	if(count > 1) {
		name += (name[name.length - 1] === 's' ? 'e' : '') + 's';
	}
	return name;
}

function setup() {
	noCanvas();
	
	// Select the implicit tbody inside of the table
	let table = select('tbody');
	
	// Loop over the models
	data.models.forEach(model => {
		
		// Set up our elements
		let tr = createElement('tr').parent(table);
		let tdName = createElement('td', model.name).parent(tr);
		let tdPieces = createElement('td').parent(tr);
		let tdSets = createElement('td').parent(tr);
		
		// Loop over the model's key
		Object.keys(model).forEach(key => {
			// Avoid the 'name' key, this causes trouble
			if(key === 'name') {
				return;
			}
			
			// Get the count for this key
			let count = model[key];
			// Check the the key is not 0
			if(!count) {
				return;
			}
			// Make a readable version of the key
			let piece = makeName(key, count);
			// Add the data to the second column
			createDiv(`${piece}: ${count}`).parent(tdPieces);
		});
		
		// Loop over the sets for each model
		data.sets.forEach(set => {
			// Check if the set can be used to create the model, automatically
			// return true if the key is 'name'
			let canUse = Object.keys(set)
					.every(key => key === 'name' || model[key] <= set[key]);
			if(canUse) {
				// Add the set to the third column
				createDiv(set.name).parent(tdSets);
			}
		});
		
	});
}
              
            
!
999px

Console