Woo, it works like a charm, thanks all! The script below lets you create a configurable line of dots (it's for Storytelling/White Wolf/Onyx Path games). Wiggle a dot up, and it fills the bar up to that dot. Wiggle a dot down, and it empties that dot and everything below it. Being new to this whole thing, I figured I'd post it in case anyone is inclined to offer feedback on anything I could have done better, coding/best-practices wise. Thanks again for all your help! var DotTracker = DotTracker || {}
'use strict';
var imgDotEmpty = '<a href="https://s3.amazonaws.com/files.d20.io/images/32477494/jX2dkr4WDfMaGEca9vt66w/thumb.png?1493802973" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/32477494/jX2dkr4WDfMaGEca9vt66w/thumb.png?1493802973</a>';
var imgDotFull = '<a href="https://s3.amazonaws.com/files.d20.io/images/32477493/9CH89MKVpxfV6NrUpMUxog/thumb.png?1493802967" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/32477493/9CH89MKVpxfV6NrUpMUxog/thumb.png?1493802967</a>';
DotTracker.dotLine = function (startGridX, startGridY, gridWidth, gridHeight, gridSpacing, dotCount) {
var pageID = Campaign().get('playerpageid');
var cellSize = 70 * getObj('page', pageID).get('snapping_increment');
this.width = cellSize * gridWidth;
this.height = cellSize * gridHeight;
this.startX = cellSize * (startGridX - 1) + 0.5 * this.width;
this.startY = cellSize * (startGridY - 1) + 0.5 * this.height;
this.gridSpacing = gridSpacing;
this.dotCount = dotCount;
this.currentValue = 0;
this.dots = [];
var xShift = 0
for (i = 0; i < this.dotCount; i++) {
this.dots[i] = createObj('graphic', {
_pageid: pageID,
name: 'dotTrackerButton',
isdrawing: true,
imgsrc: imgDotEmpty,
left: this.startX + xShift,
top: this.startY,
width: this.width,
height: this.height,
controlledby: 'all',
layer: 'objects'
});
this.dots[i].value = i + 1;
this.dots[i].controller = this;
xShift += this.width + this.gridSpacing * cellSize;
};
this.SetValue = function (value) {
this.currentValue = (value > this.dotCount) ? this.dotCount : (value < 0) ? 0 : value;
for (i = 0; i < this.currentValue; i++)
this.dots[i].set('imgsrc', imgDotFull);
for (i = this.dotCount - 1; i >= this.currentValue ; i--)
this.dots[i].set('imgsrc', imgDotEmpty);
};
this.AdjustDotLine = function (obj, prev) {
var newYPos = obj.get('top');
obj.set({ left: prev.left, top: prev.top });
if (prev.top > newYPos)
this.SetValue(obj.value);
else
this.SetValue(obj.value - 1);
};
};
on("change:graphic", function (obj, prev) {
if (obj.get('name') === 'dotTrackerButton') {
obj.controller.AdjustDotLine(obj, prev);
}
});
on("ready", function () {
var testDotLine1 = new DotTracker.dotLine(6, 7, 2, 2, 0.5, 10);
var testDotLine2 = new DotTracker.dotLine(6, 12, 2, 2, 0.5, 10);
var testDotLine3 = new DotTracker.dotLine(6, 17, 2, 2, 0.5, 10);
var testDotLine4 = new DotTracker.dotLine(6, 22, 2, 2, 0.5, 10);
testDotLine1.SetValue(0);
testDotLine2.SetValue(3);
testDotLine3.SetValue(8);
testDotLine4.SetValue(10);
});