mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 17:24:24 +02:00
added redo and undo functionality to mouse component of paint script, and fixed overlay not being deleted on script ending bug
This commit is contained in:
parent
8c32f8f396
commit
9264ef980c
1 changed files with 34 additions and 13 deletions
|
@ -66,9 +66,11 @@ function hydraCheck() {
|
||||||
return hydrasConnected; //hydrasConnected;
|
return hydrasConnected; //hydrasConnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//************ Mouse Paint **************************
|
||||||
|
|
||||||
function MousePaint() {
|
function MousePaint() {
|
||||||
var lines = [];
|
var lines = [];
|
||||||
|
var deletedLines = [];
|
||||||
var isDrawing = false;
|
var isDrawing = false;
|
||||||
var path = [];
|
var path = [];
|
||||||
|
|
||||||
|
@ -152,6 +154,19 @@ function MousePaint() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function undoStroke() {
|
||||||
|
var deletedLine = lines.pop();
|
||||||
|
var deletedLineProps = Entities.getEntityProperties(deletedLine);
|
||||||
|
deletedLines.push(deletedLineProps);
|
||||||
|
Entities.deleteEntity(deletedLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
function redoStroke() {
|
||||||
|
var restoredLine = Entities.addEntity(deletedLines.pop());
|
||||||
|
Entities.addEntity(restoredLine);
|
||||||
|
lines.push(restoredLine);
|
||||||
|
}
|
||||||
|
|
||||||
function mousePressEvent(event) {
|
function mousePressEvent(event) {
|
||||||
lineRider.mousePressEvent(event);
|
lineRider.mousePressEvent(event);
|
||||||
path = [];
|
path = [];
|
||||||
|
@ -172,6 +187,12 @@ function MousePaint() {
|
||||||
color: currentColor
|
color: currentColor
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (event.text === "z") {
|
||||||
|
undoStroke();
|
||||||
|
}
|
||||||
|
if(event.text === "x") {
|
||||||
|
redoStroke();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
|
@ -179,6 +200,7 @@ function MousePaint() {
|
||||||
Entities.deleteEntity(line);
|
Entities.deleteEntity(line);
|
||||||
});
|
});
|
||||||
Entities.deleteEntity(brush);
|
Entities.deleteEntity(brush);
|
||||||
|
lineRider.cleanup();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +219,6 @@ function MousePaint() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function HydraPaint() {
|
function HydraPaint() {
|
||||||
|
|
||||||
|
|
||||||
|
@ -431,7 +452,7 @@ function HydraPaint() {
|
||||||
currentTime += deltaTime;
|
currentTime += deltaTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
function scriptEnding() {
|
function cleanup() {
|
||||||
rightController.cleanup();
|
rightController.cleanup();
|
||||||
leftController.cleanup();
|
leftController.cleanup();
|
||||||
lineRider.cleanup();
|
lineRider.cleanup();
|
||||||
|
@ -450,20 +471,20 @@ function HydraPaint() {
|
||||||
var leftController = new controller(LEFT, LEFT_BUTTON_3, LEFT_BUTTON_4, LEFT_BUTTON_1, LEFT_BUTTON_2);
|
var leftController = new controller(LEFT, LEFT_BUTTON_3, LEFT_BUTTON_4, LEFT_BUTTON_1, LEFT_BUTTON_2);
|
||||||
|
|
||||||
Script.update.connect(update);
|
Script.update.connect(update);
|
||||||
Script.scriptEnding.connect(scriptEnding);
|
Script.scriptEnding.connect(cleanup);
|
||||||
Controller.mousePressEvent.connect(mousePressEvent);
|
Controller.mousePressEvent.connect(mousePressEvent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function randFloat(low, high) {
|
function randFloat(low, high) {
|
||||||
return low + Math.random() * ( high - low );
|
return low + Math.random() * (high - low);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function randInt(low, high) {
|
function randInt(low, high) {
|
||||||
return Math.floor(randFloat(low, high));
|
return Math.floor(randFloat(low, high));
|
||||||
}
|
}
|
||||||
|
|
||||||
function map(value, min1, max1, min2, max2) {
|
function map(value, min1, max1, min2, max2) {
|
||||||
return min2 + (max2 - min2) * ((value - min1) / (max1 - min1));
|
return min2 + (max2 - min2) * ((value - min1) / (max1 - min1));
|
||||||
}
|
}
|
Loading…
Reference in a new issue