Skip to content

Add CCUILib widgets & Update ccmod.json #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
12 changes: 12 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"semi": true,
"useTabs": true,
"tabWidth": 4,
"singleQuote": false,
"trailingComma": "es5",
"printWidth": 170,
"quoteProps": "as-needed",
"bracketSpacing": true,
"arrowParens": "avoid"
}

14 changes: 7 additions & 7 deletions Helpers/utils.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@

/**
* Rounds a value to a specified number of decimal places.
* A placeValue of 1000 corresponds to rounding to 3 decimal places, 100 means 2, and so on.
*
*
* @param {*} value Value to be rounded
* @param {*} placeValue Number by which to scale rounding by
* @returns Rounded result
*/
export function roundValue(value, placeValue = 1000) {
if(placeValue === 0.0) return value;
if (placeValue === 0.0) return value;

return Math.floor(value * placeValue) / placeValue;
}
Expand All @@ -21,19 +20,20 @@ let hasHooked = false;

/**
* Returns a frame counter starting from the first call of this function (once ig.game exists).
*
*
* Useful when you need to measure the number of frames passed, not very helpful if you want the
* exact number of total game frames.
*/
export function getFrameNumber() {
if(!hasHooked && ig.game) {
if (!hasHooked && ig.game) {
ig.game.addons.preUpdate.push({
onPreUpdate: () => { frameNumber += 1; }
onPreUpdate: () => {
frameNumber += 1;
},
});

hasHooked = true;
}

return frameNumber;
}

3 changes: 2 additions & 1 deletion Utilities/ballPrediction.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ ig.ENTITY.Crosshair.inject({
_updateCrossHair: function(b, e, g, h, i, j, bouncePoints, maxPoint, maxBounce){
this.parent(b, e, g, h, i, j, BOUNCE_POINTS, MAX_POINT, maxBounce);
}
});*/
});*/

17 changes: 9 additions & 8 deletions Utilities/bombTimer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ sc.BombEntity.inject({
start(...args) {
this.parent(...args);

if(sc.options && sc.options.get("show-bomb-timer")) {
const timingText = (this.timer) ? `Time: ${roundValue(this.timer)}` : `Unknown`;
if (sc.options && sc.options.get("show-bomb-timer")) {
const timingText = this.timer ? `Time: ${roundValue(this.timer)}` : `Unknown`;

this.bombTimingGui = new sc.SmallEntityBox(this, timingText, this.timer + 3);
this.bombTimingGui.stopRumble();
Expand All @@ -26,8 +26,8 @@ sc.BombEntity.inject({
enterHeatMode(...args) {
this.parent(...args);

if(sc.options && sc.options.get("show-bomb-timer")) {
const timingText = (this.timer) ? `Time: ${roundValue(this.timer)}` : `Unknown`;
if (sc.options && sc.options.get("show-bomb-timer")) {
const timingText = this.timer ? `Time: ${roundValue(this.timer)}` : `Unknown`;

this.bombTimingGui = new sc.SmallEntityBox(this, timingText, this.timer + 3);
this.bombTimingGui.stopRumble();
Expand All @@ -38,10 +38,11 @@ sc.BombEntity.inject({
update() {
this.parent();

if(this.bombTimingGui) {
const timingText = (this.timer) ? `Time: ${roundValue(this.timer)}` : `Unknown`;
if (this.bombTimingGui) {
const timingText = this.timer ? `Time: ${roundValue(this.timer)}` : `Unknown`;

this.bombTimingGui.textGui.setText(timingText);
}
}
});
},
});

51 changes: 22 additions & 29 deletions Utilities/finisherIndicator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* CrossCode Speedrun Utilities - finisherIndicator.js
*
*
* HUD Indicator for how early or late the player is on
* dash cancelling the bonus hit of a Full Combo
*/
Expand Down Expand Up @@ -36,7 +36,6 @@ let hitTime = null; //The hit time of the 2nd finisher hit

let hitFrame = -1;


function resetFinisherStatus() {
isInFinisher = false;
hitCount = 0;
Expand All @@ -54,26 +53,23 @@ function resetFinisherStatus() {
*/
ig.ENTITY.Combatant.inject({
onDamage(damagingEntity, attackInfo, partEntity) {

if(damagingEntity.getCombatant() === sc.model.player.params.combatant) {
if(isInFinisher) {
if(hitCount === 0) {
if (damagingEntity.getCombatant() === sc.model.player.params.combatant) {
if (isInFinisher) {
if (hitCount === 0) {
hitTarget = this;

if(partEntity) {
if (partEntity) {
hitTargetPart = partEntity;
}
else {
} else {
hitTargetPart = null;
}

hitCount += 1;
}
else if(hitCount === 1) {
} else if (hitCount === 1) {
//Have we hit the same target for this hit?
if(hitTarget && hitTarget === this) {
if (hitTarget && hitTarget === this) {
//If this target consists of several parts, have we hit the same part?
if(!hitTargetPart || (hitTargetPart === partEntity)) {
if (!hitTargetPart || hitTargetPart === partEntity) {
hitTime = ig.Timer.time;
hitFrame = getFrameNumber();
hitCount += 1;
Expand All @@ -84,7 +80,7 @@ ig.ENTITY.Combatant.inject({
}

return this.parent(damagingEntity, attackInfo, partEntity);
}
},
});

/**
Expand All @@ -94,48 +90,45 @@ ig.ENTITY.Combatant.inject({
*/
ig.ENTITY.Player.inject({
startCloseCombatAction(actionKey, input) {

if(actionKey == "ATTACK_FINISHER") {
if (actionKey == "ATTACK_FINISHER") {
isInFinisher = true;
}
else {
} else {
resetFinisherStatus();
}

this.parent(actionKey,input);
this.parent(actionKey, input);
},

startDash() {
if(this.state == 3 && isInFinisher) {
if(hitTarget && sc.options && sc.options.get("show-finisher-indicator")) {

if (this.state == 3 && isInFinisher) {
if (hitTarget && sc.options && sc.options.get("show-finisher-indicator")) {
let timingText;
const frameDelta = getFrameNumber() - hitFrame;

//No hit occurred before this dash, early
if(hitFrame < 0) {
if (hitFrame < 0) {
timingText = `Early`;
}
//We dashed on the immediate frame after the hit, perfect
else if((getFrameNumber() - hitFrame) <= 1) {
else if (getFrameNumber() - hitFrame <= 1) {
timingText = `Perfect`;
}
//We were late and want to show time passed
else if(sc.options.get("show-finisher-time")) {
else if (sc.options.get("show-finisher-time")) {
timingText = `Late (${roundValue(ig.Timer.time - hitTime)})`;
}
//We were late and want to show the number of frames late
else {
timingText = `Late (${frameDelta - 1} frame${(frameDelta - 1 === 1) ? '' : 's'})`;
timingText = `Late (${frameDelta - 1} frame${frameDelta - 1 === 1 ? "" : "s"})`;
}

let dashTimingGui = new sc.SmallEntityBox(ig.game.playerEntity, timingText, finisherDisplayTime);
dashTimingGui.stopRumble();
ig.gui.addGuiElement(dashTimingGui);
}
}
}

this.parent();
}
},
});

});
15 changes: 9 additions & 6 deletions Utilities/freeSP.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* CrossCode Speedrun Utilities - freeSP.js
*
*
* Hotkey for giving SP, gives points past the regular cap.
*/

Expand Down Expand Up @@ -31,7 +31,7 @@ sc.OPTIONS_DEFINITION["keys-free-sp"] = {
type: "CONTROLS",
init: {
key1: ig.KEY.U,
key2: undefined
key2: undefined,
},
cat: sc.OPTION_CATEGORY.CONTROLS,
hasDivider: true,
Expand All @@ -55,19 +55,22 @@ sc.OPTIONS_DEFINITION["free-sp-value"] = {
sc.Control.inject({
freeSPPress: function () {
return ig.input.pressed("free-sp");
}
},
});

export function giveFreeSp() {
ig.game.playerEntity.params.currentSp += sc.options.get("free-sp-value");
}
/**
* @inject
* Handle execution of keybinds
*/
ig.ENTITY.Player.inject({
gatherInput(...args) {
if (sc.options && sc.control.freeSPPress()) {
this.params.currentSp += sc.options.get("free-sp-value");
giveFreeSp();
}

return this.parent(...args);
}
});
},
});
61 changes: 32 additions & 29 deletions Utilities/gameSpeed.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
/**
* CrossCode Speedrun Utilities - gameSpeed.js
*
*
* Hotkey for toggling game speed to a different value.
*/

sc.GAME_SPEED_PERCENTAGE_VALUES = {
SPEED_10: 0.10,
SPEED_20: 0.20,
SPEED_30: 0.30,
SPEED_40: 0.40,
SPEED_50: 0.50,
SPEED_60: 0.60,
SPEED_70: 0.70,
SPEED_80: 0.80,
SPEED_90: 0.90,
SPEED_100: 1.00,
SPEED_150: 1.50,
SPEED_200: 2.00,
SPEED_250: 2.50,
SPEED_300: 3.00,
SPEED_400: 4.00,
SPEED_500: 5.00,
SPEED_600: 6.00,
SPEED_700: 7.00,
SPEED_800: 8.00,
SPEED_900: 9.00,
SPEED_1000: 10.00
SPEED_10: 0.1,
SPEED_20: 0.2,
SPEED_30: 0.3,
SPEED_40: 0.4,
SPEED_50: 0.5,
SPEED_60: 0.6,
SPEED_70: 0.7,
SPEED_80: 0.8,
SPEED_90: 0.9,
SPEED_100: 1.0,
SPEED_150: 1.5,
SPEED_200: 2.0,
SPEED_250: 2.5,
SPEED_300: 3.0,
SPEED_400: 4.0,
SPEED_500: 5.0,
SPEED_600: 6.0,
SPEED_700: 7.0,
SPEED_800: 8.0,
SPEED_900: 9.0,
SPEED_1000: 10.0,
};

sc.OPTIONS_DEFINITION["keys-toggle-game-speed"] = {
type: "CONTROLS",
init: {
key1: ig.KEY.PERIOD,
key2: undefined
key2: undefined,
},
cat: sc.OPTION_CATEGORY.CONTROLS,
hasDivider: false,
Expand All @@ -50,6 +50,11 @@ sc.OPTIONS_DEFINITION["game-speed-value"] = {
};

let isToggledSpeed = false;
export function toggleGameSpeed() {
isToggledSpeed = !isToggledSpeed;

ig.Timer.timeScale = isToggledSpeed ? sc.options.get("game-speed-value") : 1;
}

/**
* @inject
Expand All @@ -58,7 +63,7 @@ let isToggledSpeed = false;
sc.Control.inject({
toggleGameSpeedPress: function () {
return ig.input.pressed("toggle-game-speed");
}
},
});

/**
Expand All @@ -68,11 +73,9 @@ sc.Control.inject({
ig.ENTITY.Player.inject({
gatherInput(...args) {
if (sc.control.toggleGameSpeedPress() && sc.options) {
isToggledSpeed = !isToggledSpeed;

ig.Timer.timeScale = isToggledSpeed ? sc.options.get("game-speed-value") : 1;
toggleGameSpeed();
}

return this.parent(...args);
}
});
},
});
Loading