How to use the nexus.grid function in nexus

To help you get started, we’ve selected a few nexus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vonWolfehaus / von-grid / editor / app.js View on Github external
function update() {
		currentGridCell = nexus.grid.pixelToCell(nexus.input.editorWorldPos);
		if (nexus.mouse.down && keyboard.shift && nexus.mouse.allHits && nexus.mouse.allHits.length) {
			// only check if the user's mouse is over the editor plane
			if (!currentGridCell.equals(prevGridCell)) {
				addTile(currentGridCell);
			}
			prevGridCell.copy(currentGridCell);
		}
	}
github vonWolfehaus / von-grid / editor / modules / Editor.js View on Github external
function update() {
		currentGridCell = nexus.grid.pixelToCell(nexus.input.editorWorldPos);
		if (nexus.mouse.down && keyboard.shift && nexus.mouse.allHits && nexus.mouse.allHits.length) {
			// only check if the user's mouse is over the editor plane
			if (!currentGridCell.equals(prevGridCell)) {
				addTile(currentGridCell);
			}
			prevGridCell.copy(currentGridCell);
		}
	}
github vonWolfehaus / von-grid / editor / modules / main.js View on Github external
// listen to the orbit controls to disable the raycaster while user adjusts the view
	scene.controls.addEventListener('wheel', onControlWheel);

	var grid = new vg.HexGrid({
		rings: 5,
		cellSize: 10
	});
	var board = new vg.Board(grid);
	var mouse = new vg.MouseCaster(board.group, scene.camera, canvas);
	var input = new Input(board.group, mouse);
	var plane = new EditorPlane(board.group, grid, mouse);

	nexus.input = input;
	nexus.plane = plane;
	nexus.board = board;
	nexus.grid = grid;
	nexus.scene = scene;
	nexus.mouse = mouse;

	var boardSize = 20; // TODO: get from settings
	plane.generatePlane(boardSize * boardSize * 1.8, boardSize * boardSize * 1.8);
	plane.addHoverMeshToGroup(scene.container);

	board.generateOverlay(boardSize);

	tower.tileAction.add(onMapChange, this);

	// scene.add(board.group);
	scene.focusOn(board.group);

	if (map) {
		loadMap(map);
github vonWolfehaus / von-grid / editor / modules / tilemaker.js View on Github external
function getTile(cell, matid) { // eslint-disable-line no-unused-vars
		var mat = materials[matid];
		var map = data.get('map');
		if (cell.tile) {
			// don't rebuild, just update
			cell.tile.material = mat;
			cell.tile.mesh.material = mat;
			return cell.tile;
		}
		var t = tilePool.pop();
		if (t) {
			t.material = mat;
			t.mesh.material = mat;
			t.cell = cell;
			cell.tile = t;
			t.position.copy(nexus.grid.cellToPixel(cell));
			t.position.y = t.cell.h * nexus.board.tileHeightStep;
		}
		else {
			t = new vg.Tile({
				cell: cell,
				geometry: map.mesh || nexus.gen.geoGen.tileGeo,
				material: materials[matid]
			});
		}

		nexus.board.addTile(t);

		return t;
	}
github vonWolfehaus / von-grid / editor / modules / Editor.js View on Github external
function addTile(cell) {
		if (!cell || nexus.board.getTileAtCell(cell)) return;

		var newCell = new vg.Cell();
		newCell.copy(cell);
		newCell.h = Math.abs(nexus.mouse.wheel * heightStep);

		var newTile = nexus.grid.generateTile(newCell, 0.95);

		nexus.board.addTile(newTile);

		tower.tileAction.dispatch(tower.TILE_ADD, newTile);

		return newTile;
	}
github vonWolfehaus / von-grid / editor / app.js View on Github external
function addTile(cell) {
		if (!cell || nexus.board.getTileAtCell(cell)) return;

		var newCell = new vg.Cell();
		newCell.copy(cell);
		newCell.h = Math.abs(nexus.mouse.wheel * heightStep);

		var newTile = nexus.grid.generateTile(newCell, 0.95);

		nexus.board.addTile(newTile);

		tower.tileAction.dispatch(tower.TILE_ADD, newTile);

		return newTile;
	}