Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion scripts/initgame.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function(Osu, _, sound, Playback) {
window: window,
stage: null,
scene: null,
updatePlayerActions: null,
updatePlayerActions: function(){},

// note: preference values here will be overwritten by gamesettings (in settings.js)
// display
Expand Down Expand Up @@ -41,6 +41,8 @@ function(Osu, _, sound, Playback) {

// mods
autoplay: false,
autopilot: false,
relax: false,
nightcore: false,
daycore: false,
hardrock: false,
Expand Down
4 changes: 2 additions & 2 deletions scripts/launchgame.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function launchOSU(osu, beatmapid, version){
}

// load cursor
if (!game.showhwmouse || game.autoplay) {
if (!game.showhwmouse || game.autoplay || game.autopilot) {
game.cursor = new PIXI.Sprite(Skin["cursor.png"]);
game.cursor.anchor.x = game.cursor.anchor.y = 0.5;
game.cursor.scale.x = game.cursor.scale.y = 0.3 * game.cursorSize;
Expand All @@ -59,7 +59,7 @@ function launchOSU(osu, beatmapid, version){
var pMainPage = document.getElementById("main-page");
var pNav = document.getElementById("main-nav");
pGameArea.appendChild(app.view);
if (game.autoplay) {
if (game.autoplay || game.autopilot) {
pGameArea.classList.remove("shownomouse");
pGameArea.classList.remove("showhwmousemedium");
pGameArea.classList.remove("showhwmousesmall");
Expand Down
2 changes: 2 additions & 0 deletions scripts/overlay/score.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ define([], function()
if (game.hidden) l.push("HD");
if (game.hardrock) l.push("HR");
if (game.nightcore) l.push("NC");
if (game.relax) l.push("RL");
if (game.autopilot) l.push("AP");
if (game.autoplay) l.push("AT");
if (l.length == 0) return "";
let s = l[0];
Expand Down
12 changes: 7 additions & 5 deletions scripts/playback.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ function(Osu, setPlayerActions, SliderMesh, ScoreOverlay, VolumeMenu, LoadingMen
self.ended = false;
// mods
self.autoplay = game.autoplay;
self.autopilot = game.autopilot;
self.relax = game.relax;
self.modhidden = game.hidden;
self.playbackRate = 1.0;
if (self.game.nightcore) self.playbackRate *= 1.5;
Expand Down Expand Up @@ -469,7 +471,7 @@ function(Osu, setPlayerActions, SliderMesh, ScoreOverlay, VolumeMenu, LoadingMen
hit.approach = newHitSprite("approachcircle.png", 8 + 0.0001 * hit.hitIndex);
hit.approach.tint = combos[hit.combo % combos.length];

hit.judgements.push(this.createJudgement(hit.x, hit.y, 4, hit.time + this.MehTime));
hit.judgements.push(this.createJudgement(hit.x, hit.y, 10, hit.time + this.MehTime));

// create combo number
hit.numbers = [];
Expand All @@ -494,13 +496,13 @@ function(Osu, setPlayerActions, SliderMesh, ScoreOverlay, VolumeMenu, LoadingMen
body.depth = 4.9999-0.0001*hit.hitIndex;
hit.objects.push(body);

function newSprite(spritename, x, y, scalemul = 1) {
function newSprite(spritename, x, y, scalemul = 1, reverseArr) {
let sprite = new PIXI.Sprite(Skin[spritename]);
sprite.scale.set(self.hitSpriteScale * scalemul);
sprite.anchor.set(0.5);
sprite.x = x;
sprite.y = y;
sprite.depth = 4.9999-0.0001*hit.hitIndex;
sprite.depth = (reverseArr ? 9.9999 : 4.9999) - 0.0001*hit.hitIndex;
sprite.alpha = 0;
hit.objects.push(sprite);
return sprite;
Expand Down Expand Up @@ -528,14 +530,14 @@ function(Osu, setPlayerActions, SliderMesh, ScoreOverlay, VolumeMenu, LoadingMen
// curve points are of about-same distance, so these 2 points should be different
let p = hit.curve.curve[hit.curve.curve.length-1];
let p2 = hit.curve.curve[hit.curve.curve.length-2];
hit.reverse = newSprite("reversearrow.png", p.x, p.y, 0.36);
hit.reverse = newSprite("reversearrow.png", p.x, p.y, 0.36, true);
hit.reverse.rotation = Math.atan2(p2.y - p.y, p2.x - p.x);
}
if (hit.repeat > 2) {
// curve points are of about-same distance, so these 2 points should be different
let p = hit.curve.curve[0];
let p2 = hit.curve.curve[1];
hit.reverse_b = newSprite("reversearrow.png", p.x, p.y, 0.36);
hit.reverse_b = newSprite("reversearrow.png", p.x, p.y, 0.36, true);
hit.reverse_b.rotation = Math.atan2(p2.y - p.y, p2.x - p.x);
hit.reverse_b.visible = false; // Only visible when it's the next end to hit
}
Expand Down
197 changes: 131 additions & 66 deletions scripts/playerActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,84 +51,145 @@ define([], function() {
}

var playerActions = function(playback){

playback.auto = {
currentObject: null,
curid: 0,
lastx: playback.game.mouseX,
lasty: playback.game.mouseY,
lasttime: 0
};
if (playback.autoplay) {
playback.auto = {
currentObject: null,
curid: 0,
lastx: playback.game.mouseX,
lasty: playback.game.mouseY,
lasttime: 0
playback.game.updatePlayerActions = autoMod;
} else if (playback.relax) {
playback.game.updatePlayerActions = relaxMod;
} else if (playback.autopilot) {
playback.game.updatePlayerActions = autopilotMod;
}

function relaxMod(time) {
playback.game.down = true;
let cur = playback.hits[playback.auto.curid];
if (!cur)
return;
let finalTime = cur.judgements[cur.judgements.length-1].finalTime;
if (cur.score < 0) {
if (time >= finalTime) {
playback.auto.curid++;
} else if (cur.time <= time) {
checkClickdown();
}
} else {
playback.auto.curid++;
}
}
playback.game.updatePlayerActions = function(time){
if (playback.autoplay) {
const spinRadius = 60;
let cur = playback.auto.currentObject;
// auto move cursor
if (playback.game.down && cur) { // already on an object
if (cur.type == "circle" || time > cur.endTime) {
// release cursor
playback.game.down = false;
playback.auto.currentObject = null;
playback.auto.lasttime = time;
playback.auto.lastx = playback.game.mouseX;
playback.auto.lasty = playback.game.mouseY;
}
else if (cur.type == "slider") { // follow slider ball

function autopilotMod(time) {
const spinRadius = 60;
let cur = playback.hits[playback.auto.curid];
if (!cur)
return;
let finalTime = cur.judgements[cur.judgements.length-1].finalTime;
let finalScore = cur.judgements[cur.judgements.length-1].points;

if (finalScore < 0){
if (time >= finalTime) { //current obj time out, save status and go to next obj
playback.auto.curid++;
playback.auto.lasttime = finalTime;
playback.auto.lastx = playback.game.mouseX;
playback.auto.lasty = playback.game.mouseY;
} else if (cur.type != "circle" && time > cur.time) { //moving the cursor on slider or spin
if (cur.type == "slider") { // follow slider ball
playback.game.mouseX = cur.ball.x || cur.x;
playback.game.mouseY = cur.ball.y || cur.y;
}
else { // spin
} else { // spin
let currentAngle = Math.atan2(playback.game.mouseY - cur.y, playback.game.mouseX - cur.x);
currentAngle += 0.8;
playback.game.mouseY = cur.y + spinRadius * Math.sin(currentAngle);
playback.game.mouseX = cur.x + spinRadius * Math.cos(currentAngle);
}
}
// looking for next target
cur = playback.auto.currentObject;
while (playback.auto.curid < playback.hits.length && playback.hits[playback.auto.curid].time < time) {
if (playback.hits[playback.auto.curid].score < 0) {
playback.game.mouseX = playback.hits[playback.auto.curid].x;
playback.game.mouseY = playback.hits[playback.auto.curid].y;
if (playback.hits[playback.auto.curid].type == "spinner")
playback.game.mouseY -= spinRadius;
playback.game.down = true;
checkClickdown();
}
++playback.auto.curid;
}
if (!cur && playback.auto.curid < playback.hits.length) {
cur = playback.hits[playback.auto.curid];
playback.auto.currentObject = cur;
}
if (!cur || cur.time > time + playback.approachTime) {
// no object to click, just rest
playback.auto.lasttime = time;
return;
}
if (!playback.game.down) {
// move toward the object
} else { //moving the cursor to next obj
let targX = cur.x;
let targY = cur.y;
if (cur.type == "spinner")
targY -= spinRadius;
let t = (time - playback.auto.lasttime) / (cur.time - playback.auto.lasttime);
let t = (time - playback.auto.lasttime) / Math.max(0, cur.time - playback.auto.lasttime);
t = Math.max(0, Math.min(1, t));
t = 0.5-Math.sin((Math.pow(1-t,1.5)-0.5)*Math.PI)/2; // easing
playback.game.mouseX = t * targX + (1-t) * playback.auto.lastx;
playback.game.mouseY = t * targY + (1-t) * playback.auto.lasty;
t = 0.5 - Math.sin((Math.pow(1 - t, 3) - 0.5) * Math.PI) / 2; // easing
playback.game.mouseX = t * targX + (1 - t) * playback.auto.lastx;
playback.game.mouseY = t * targY + (1 - t) * playback.auto.lasty;
}
} else { //current obj finish, save status and go to next obj
playback.auto.curid++;
playback.auto.lasttime = time;
playback.auto.lastx = playback.game.mouseX;
playback.auto.lasty = playback.game.mouseY;
}
}

let diff = time - cur.time;
if (diff > -8) {
// click the object
playback.game.down = true;
checkClickdown();
}
function autoMod(time) {
const spinRadius = 60;
let cur = playback.auto.currentObject;
// auto move cursor
if (playback.game.down && cur) { // already on an object
if (cur.type == "circle" || time > cur.endTime) {
// release cursor
playback.game.down = false;
playback.auto.currentObject = null;
playback.auto.lasttime = time;
playback.auto.lastx = playback.game.mouseX;
playback.auto.lasty = playback.game.mouseY;
} else if (cur.type == "slider") { // follow slider ball
playback.game.mouseX = cur.ball.x || cur.x;
playback.game.mouseY = cur.ball.y || cur.y;
} else { // spin
let currentAngle = Math.atan2(playback.game.mouseY - cur.y, playback.game.mouseX - cur.x);
currentAngle += 0.8;
playback.game.mouseY = cur.y + spinRadius * Math.sin(currentAngle);
playback.game.mouseX = cur.x + spinRadius * Math.cos(currentAngle);
}
}
};
// looking for next target
cur = playback.auto.currentObject;
while (playback.auto.curid < playback.hits.length && playback.hits[playback.auto.curid].time < time) {
if (playback.hits[playback.auto.curid].score < 0) {
playback.game.mouseX = playback.hits[playback.auto.curid].x;
playback.game.mouseY = playback.hits[playback.auto.curid].y;
if (playback.hits[playback.auto.curid].type == "spinner")
playback.game.mouseY -= spinRadius;
playback.game.down = true;
checkClickdown();
}
++playback.auto.curid;
}
if (!cur && playback.auto.curid < playback.hits.length) {
cur = playback.hits[playback.auto.curid];
playback.auto.currentObject = cur;
}
if (!cur || cur.time > time + playback.approachTime) {
// no object to click, just rest
playback.auto.lasttime = time;
return;
}
if (!playback.game.down) {
// move toward the object
let targX = cur.x;
let targY = cur.y;
if (cur.type == "spinner")
targY -= spinRadius;
let t = (time - playback.auto.lasttime) / (cur.time - playback.auto.lasttime);
t = Math.max(0, Math.min(1, t));
t = 0.5 - Math.sin((Math.pow(1 - t, 1.5) - 0.5) * Math.PI) / 2; // easing
playback.game.mouseX = t * targX + (1 - t) * playback.auto.lastx;
playback.game.mouseY = t * targY + (1 - t) * playback.auto.lasty;

let diff = time - cur.time;
if (diff > -8) {
// click the object
playback.game.down = true;
checkClickdown();
}
}
}


var movehistory = [{x:512/2, y:384/2, t: new Date().getTime()}];
Expand All @@ -148,6 +209,8 @@ define([], function() {
}

var mousemoveCallback = function(e) {
if (playback.autopilot)
return;
playback.game.mouseX = (e.clientX - gfx.xoffset) / gfx.width * 512;
playback.game.mouseY = (e.clientY - gfx.yoffset) / gfx.height * 384;
movehistory.unshift({
Expand Down Expand Up @@ -218,13 +281,15 @@ define([], function() {
if (!playback.autoplay) {
playback.game.window.addEventListener("mousemove", mousemoveCallback);
// mouse click handling for gameplay
if (playback.game.allowMouseButton) {
playback.game.window.addEventListener("mousedown", mousedownCallback);
playback.game.window.addEventListener("mouseup", mouseupCallback);
if (!playback.relax) {
if (playback.game.allowMouseButton) {
playback.game.window.addEventListener("mousedown", mousedownCallback);
playback.game.window.addEventListener("mouseup", mouseupCallback);
}
// keyboard click handling for gameplay
playback.game.window.addEventListener("keydown", keydownCallback);
playback.game.window.addEventListener("keyup", keyupCallback);
}
// keyboard click handling for gameplay
playback.game.window.addEventListener("keydown", keydownCallback);
playback.game.window.addEventListener("keyup", keyupCallback);
}

playback.game.cleanupPlayerActions = function() {
Expand Down
Loading