cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              table#table
	tr
		th Name
		th Pieces Needed
		th Sets That You Can Use
            
          
!
            
              @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);
		}
	}
}
            
          
!
            
              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
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console