Skip to content
Merged
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
2 changes: 1 addition & 1 deletion www/games/orbit-idle/src/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class Button implements Drawable {
constructor(protected text: string, protected color: Color, protected enabled: boolean, protected x: number, protected y: number, protected w: number, protected h: number, protected callback: () => void) {
this.isHover = false;
this.label = new Label(text, color.getContrastingColor(), 1, false, 'center', 'top', this.x + this.w / 2, this.y + Label.fontSize / 2);
this.disabledColor = new Color(color.red, color.green, color.blue, color.alpha * 0.75);
this.disabledColor = new Color(color.red, color.green, color.blue, color.alpha * 0.5);
}
/**
* Update the value, color, and positioning of the button text.
Expand Down
2 changes: 1 addition & 1 deletion www/games/orbit-idle/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const canv: Canvas = new Canvas({
canv.clear(1);
canv.clear(2);
system.step(dt);
menu.autosave(dt);
menu.tick(dt);
canv.draw(system, 0);
canv.draw(player, 1);
canv.draw(zoom, 1);
Expand Down
12 changes: 11 additions & 1 deletion www/games/orbit-idle/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@
*/
export function N(num: number): string {
const log10: number = Math.log10(Math.abs(num)) | 0;
if (log10 >= 21) {
if (log10 >= 36) {
return `${(num / (10 ** log10)).toFixed(2)}E${log10}`;
} else if (log10 >= 33) {
return `${(num / 1e33).toFixed(2)}D`;
} else if (log10 >= 30) {
return `${(num / 1e30).toFixed(2)}N`;
} else if (log10 >= 27) {
return `${(num / 1e27).toFixed(2)}o`;
} else if (log10 >= 24) {
return `${(num / 1e24).toFixed(2)}S`;
} else if (log10 >= 21) {
return `${(num / 1e21).toFixed(2)}s`;
} else if (log10 >= 18) {
return `${(num / 1e18).toFixed(2)}Q`;
} else if (log10 >= 15) {
Expand Down
38 changes: 35 additions & 3 deletions www/games/orbit-idle/src/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export class Menu implements Drawable {
* Autosave label duration shown in milliseconds
*/
private static readonly autosaveLabelDuration: number = 2e3;
/**
* Button reset duration in milliseconds
*/
private static readonly buttonResetDuration: number = 5e3;
/**
* Menu title
*/
Expand Down Expand Up @@ -64,6 +68,14 @@ export class Menu implements Drawable {
* Autosave timer in milliseconds
*/
private autosaveTick: number;
/**
* The number of milliseconds until resetting the save button
*/
private saveReset: number;
/**
* The number of milliseconds until resetting the clear button
*/
private clearReset: number;
/**
* The callback for saving data
*/
Expand All @@ -86,10 +98,12 @@ export class Menu implements Drawable {
constructor(x: number, y: number, width: number) {
this.isOpen = false;
this.autosaveTick = 0;
this.saveReset = 0;
this.clearReset = 0;
this.title = new Label('Menu', new Color(255, 255, 255), 1, false, 'center', 'bottom', x, y - Menu.btnPadding);
this.autosaveLabel = new Label(`Created by Nicolas Ventura [${version}]`, new Color(255, 255, 255), 1, false, 'right', 'bottom', 0, 0);
this.save = new ToggleButton([
['Save', Menu.btnColor, () => this.saveCallback()],
['Save', Menu.btnColor, () => { this.saveReset = Menu.buttonResetDuration; this.saveCallback(); }],
['Saved!', new Color(150, 250, 150), () => { return }],
], x - (width / 2), y, width, Menu.btnHeight);
this.help = new ToggleButton([
Expand All @@ -101,7 +115,7 @@ export class Menu implements Drawable {
['Unmute', Menu.btnColor, () => this.unmuteCallback()],
], x - (width / 2), y + (Menu.btnHeight + Menu.btnPadding) * 2, width, Menu.btnHeight);
this.clear = new ToggleButton([
['Wipe Data', Menu.btnColor, () => { return }],
['Wipe Data', Menu.btnColor, () => this.clearReset = Menu.buttonResetDuration],
['Confirm', new Color(255, 0, 0), () => this.clearCallback()],
['Reload Page', Menu.btnColor, () => window.location.reload()],
], x - (width / 2), y + (Menu.btnHeight + Menu.btnPadding) * 3, width, Menu.btnHeight);
Expand All @@ -127,10 +141,28 @@ export class Menu implements Drawable {
this.save.reset();
this.clear.reset();
}
/**
* Menu tick for resetting buttons and autosaving
*/
public tick(dt: number): void {
if (this.saveReset > 0) {
this.saveReset -= dt;
if (this.saveReset <= 0) {
this.save.reset();
}
}
if (this.clearReset > 0) {
this.clearReset -= dt;
if (this.clearReset <= 0) {
this.clear.reset();
}
}
this.autosave(dt);
}
/**
* Perform an autosave at the specified interval
*/
public autosave(dt: number): void {
private autosave(dt: number): void {
this.autosaveTick += dt;
if (this.autosaveTick > Menu.autosaveInterval) {
this.autosaveLabel.value = 'Autosaved!';
Expand Down
2 changes: 1 addition & 1 deletion www/games/orbit-idle/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Tutorial } from './tutorial';
import { Zoom } from './zoom';

// Global constants
export const version = 'v1.2.0';
export const version = 'v1.2.1-alpha';

// UI elements
export const cursor: Cursor = new Cursor();
Expand Down