Cleaning up specs

This commit is contained in:
Devine Lu Linvega 2019-01-09 16:19:50 +12:00
parent 23c53ef37e
commit d4812be0a8
3 changed files with 16 additions and 19 deletions

View File

@ -89,7 +89,7 @@ function Cursor () {
}
this.pos_snap = function (pos) {
const grid = DOTGRID.tool.settings.size.width / DOTGRID.grid_x
const grid = DOTGRID.tool.settings.size.width / DOTGRID.grid.x
return {
x: clamp(step(pos.x, grid), grid, DOTGRID.tool.settings.size.width),
y: clamp(step(pos.y, grid), grid, DOTGRID.tool.settings.size.height + grid)

View File

@ -1,6 +1,6 @@
'use strict'
function Dotgrid (width, height, grid_x, grid_y, block_x, block_y) {
function Dotgrid (width, height) {
this.controller = null
const defaultTheme = { background: '#eee', f_high: '#000', f_med: '#999', f_low: '#ccc', f_inv: '#000', b_high: '#000', b_med: '#888', b_low: '#aaa', b_inv: '#ffb545' }
@ -8,10 +8,7 @@ function Dotgrid (width, height, grid_x, grid_y, block_x, block_y) {
this.theme = new Theme(defaultTheme)
this.history = new History()
this.grid_x = grid_x
this.grid_y = grid_y
this.block_x = block_x
this.block_y = block_y
this.grid = {x:20,y:20}
// ISU
@ -121,11 +118,11 @@ function Dotgrid (width, height, grid_x, grid_y, block_x, block_y) {
console.log('No window')
}
this.grid_x = size.width / 15
this.grid_y = size.height / 15
this.grid.x = size.width / 15
this.grid.y = size.height / 15
this.grid_width = this.tool.settings.size.width / this.grid_x
this.grid_height = this.tool.settings.size.height / this.grid_y
this.grid_width = this.tool.settings.size.width / this.grid.x
this.grid_height = this.tool.settings.size.height / this.grid.y
DOTGRID.renderer.resize(size)
@ -170,11 +167,11 @@ function Dotgrid (width, height, grid_x, grid_y, block_x, block_y) {
DOTGRID.tool.settings.size.width = size.width
DOTGRID.tool.settings.size.height = size.height
DOTGRID.grid_x = size.width / 15
DOTGRID.grid_y = size.height / 15
DOTGRID.grid.x = size.width / 15
DOTGRID.grid.y = size.height / 15
DOTGRID.grid_width = DOTGRID.tool.settings.size.width / DOTGRID.grid_x
DOTGRID.grid_height = DOTGRID.tool.settings.size.height / DOTGRID.grid_y
DOTGRID.grid_width = DOTGRID.tool.settings.size.width / DOTGRID.grid.x
DOTGRID.grid_height = DOTGRID.tool.settings.size.height / DOTGRID.grid.y
DOTGRID.renderer.resize(size)
@ -263,4 +260,4 @@ function isEqual (a, b) { return a && b && a.x == b.x && a.y == b.y }
function clamp (v, min, max) { return v < min ? min : v > max ? max : v }
function step (v, s) { return Math.round(v / s) * s }
const DOTGRID = new Dotgrid(300, 300, 20, 20, 4, 4)
const DOTGRID = new Dotgrid(300, 300)

View File

@ -93,12 +93,12 @@ function Renderer (dotgrid) {
const cursor = { x: parseInt(dotgrid.cursor.pos.x / dotgrid.grid_width), y: parseInt(dotgrid.cursor.pos.y / dotgrid.grid_width) }
for (let x = dotgrid.grid_x - 1; x >= 0; x--) {
for (let y = dotgrid.grid_y; y >= 0; y--) {
let is_step = x % dotgrid.block_x == 0 && y % dotgrid.block_y == 0
for (let x = dotgrid.grid.x - 1; x >= 0; x--) {
for (let y = dotgrid.grid.y; y >= 0; y--) {
let is_step = x % 4 == 0 && y % 4 == 0
// Color
let color = is_step ? dotgrid.theme.active.b_med : dotgrid.theme.active.b_low
if ((y == 0 || y == dotgrid.grid_y) && cursor.x == x + 1) { color = dotgrid.theme.active.b_high } else if ((x == 0 || x == dotgrid.grid_x - 1) && cursor.y == y + 1) { color = dotgrid.theme.active.b_high } else if (cursor.x == x + 1 && cursor.y == y + 1) { color = dotgrid.theme.active.b_high }
if ((y == 0 || y == dotgrid.grid.y) && cursor.x == x + 1) { color = dotgrid.theme.active.b_high } else if ((x == 0 || x == dotgrid.grid.x - 1) && cursor.y == y + 1) { color = dotgrid.theme.active.b_high } else if (cursor.x == x + 1 && cursor.y == y + 1) { color = dotgrid.theme.active.b_high }
this.drawMarker({
x: parseInt(x * dotgrid.grid_width) + dotgrid.grid_width,