How to use the nexus.mouse 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.

github vonWolfehaus / von-grid / editor / modules / main.js View on Github external
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);
	}
	else {
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 / 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 / app.js View on Github external
function onUserAction(type, overTile, data) {
		var hit = nexus.mouse.allHits[0]
		switch (type) {
			case vg.MouseCaster.WHEEL:
				if (keyboard.shift && overTile) {
					if (!overTile.cell) {
						overTile.dispose();
						return;
					}
					_cel.copy(overTile.cell);
					_cel.tile = null;

					var dif = lastHeight - data;
					var last = _cel.h;
					_cel.h += dif > 0 ? -heightStep : heightStep;
					if (_cel.h < 1) _cel.h = 1;

					nexus.mouse.wheel = Math.round((_cel.h / heightStep) + (dif > 0 ? -1 : 1));
github vonWolfehaus / von-grid / editor / modules / Editor.js View on Github external
switch (type) {
			case vg.MouseCaster.WHEEL:
				if (keyboard.shift && overTile) {
					if (!overTile.cell) {
						overTile.dispose();
						return;
					}
					_cel.copy(overTile.cell);
					_cel.tile = null;

					var dif = lastHeight - data;
					var last = _cel.h;
					_cel.h += dif > 0 ? -heightStep : heightStep;
					if (_cel.h < 1) _cel.h = 1;

					nexus.mouse.wheel = Math.round((_cel.h / heightStep) + (dif > 0 ? -1 : 1));
					lastHeight = nexus.mouse.wheel;

					if (last === _cel.h) return;
					removeTile(overTile);

					var tile = addTile(_cel);
					tile.select();

					tower.tileAction.dispatch(tower.TILE_CHANGE_HEIGHT, tile);
				}
				break;

			case vg.MouseCaster.OVER:
				if (keyboard.shift) {
					if (overTile && nexus.mouse.rightDown) {
						removeTile(overTile);
github vonWolfehaus / von-grid / editor / app.js View on Github external
switch (type) {
			case vg.MouseCaster.WHEEL:
				if (keyboard.shift && overTile) {
					if (!overTile.cell) {
						overTile.dispose();
						return;
					}
					_cel.copy(overTile.cell);
					_cel.tile = null;

					var dif = lastHeight - data;
					var last = _cel.h;
					_cel.h += dif > 0 ? -heightStep : heightStep;
					if (_cel.h < 1) _cel.h = 1;

					nexus.mouse.wheel = Math.round((_cel.h / heightStep) + (dif > 0 ? -1 : 1));
					lastHeight = nexus.mouse.wheel;

					if (last === _cel.h) return;
					removeTile(overTile);

					var tile = addTile(_cel);
					tile.select();

					tower.tileAction.dispatch(tower.TILE_CHANGE_HEIGHT, tile);
				}
				break;

			case vg.MouseCaster.OVER:
				if (keyboard.shift) {
					if (overTile && nexus.mouse.rightDown) {
						removeTile(overTile);
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 / modules / tools / addTile.js View on Github external
function over(cell, tile, mesh) {
		if (cell.tile) return;
		if (!tile && nexus.mouse.down) {
			addTile(cell);
		}
	}
github vonWolfehaus / von-grid / editor / modules / tools / walkableTile.js View on Github external
function over(cell, tile, mesh) {
		if (tile && nexus.mouse.down) {
			walkableTile(tile);
		}
	}