Skip to content

Commit

Permalink
feat(settings): add setting for decorations
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuher committed Dec 29, 2024
1 parent eb1ad46 commit 726be0a
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 7 deletions.
11 changes: 10 additions & 1 deletion src/app/common/models/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@ export class Settings {
public spectators: boolean;
public spectatorsAnimation: boolean;
public particles: boolean;
public decorations: boolean;

constructor(sound = true, ghosts = true, spectators = true, spectatorsAnimation = true, particles = true) {
constructor(
sound = true,
ghosts = true,
spectators = true,
spectatorsAnimation = true,
particles = true,
decorations = true
) {
this.sound = sound;
this.ghosts = ghosts;
this.spectators = spectators;
this.spectatorsAnimation = spectatorsAnimation;
this.particles = particles;
this.decorations = decorations;
}
}
6 changes: 5 additions & 1 deletion src/app/common/services/settings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class SettingsService {
private static SPECTATORS_KEY = 'settings_spectators';
private static SPECTATORS_ANIMATION_KEY = 'settings_spectators_animation';
private static PARTICLES_KEY = 'settings_particles';
private static DECORATIONS_KEY = 'settings_decorations';

private settings: Settings;

Expand All @@ -20,7 +21,8 @@ export class SettingsService {
localStorage.getItem(SettingsService.GHOSTS_KEY) !== 'false',
localStorage.getItem(SettingsService.SPECTATORS_KEY) !== 'false',
localStorage.getItem(SettingsService.SPECTATORS_ANIMATION_KEY) !== 'false',
localStorage.getItem(SettingsService.PARTICLES_KEY) !== 'false'
localStorage.getItem(SettingsService.PARTICLES_KEY) !== 'false',
localStorage.getItem(SettingsService.DECORATIONS_KEY) !== 'false'
);
this.settings;
}
Expand All @@ -43,6 +45,7 @@ export class SettingsService {
}

public persistSettings(): void {
console.log('persist');
StorageManager.save(SettingsService.SOUND_KEY, this.settings.sound ? 'true' : 'false');
StorageManager.save(SettingsService.SPECTATORS_KEY, this.settings.spectators ? 'true' : 'false');
StorageManager.save(
Expand All @@ -51,5 +54,6 @@ export class SettingsService {
);
StorageManager.save(SettingsService.GHOSTS_KEY, this.settings.ghosts ? 'true' : 'false');
StorageManager.save(SettingsService.PARTICLES_KEY, this.settings.particles ? 'true' : 'false');
StorageManager.save(SettingsService.DECORATIONS_KEY, this.settings.decorations ? 'true' : 'false');
}
}
2 changes: 1 addition & 1 deletion src/app/game/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class Game extends Engine {
maxFps: 60,
canvasElementId: 'game',
suppressConsoleBootMessage: true,
antialiasing: true,
antialiasing: false,
suppressHiDPIScaling: true
});

Expand Down
2 changes: 1 addition & 1 deletion src/app/game/scenes/race.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export class Race extends Scene {
this.add(gate);
}

if (track.decorations?.length) {
if ((this.engine as Game).settingsService.getSettings().decorations && track.decorations?.length) {
for (const stockableDecoration of track.decorations) {
const decoration = new Decoration(
vec(stockableDecoration.x, stockableDecoration.y),
Expand Down
5 changes: 3 additions & 2 deletions src/app/pages/learning/learning.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@
Here, you can customize various settings:
<ul>
<li>Sounds</li>
<li>Ghosts (may affect performance)</li>
<li>Spectators (may affect performance)</li>
<li>Ghosts</li>
<li>Spectators</li>
<li>Particles (may affect performance)</li>
<li>Decorations</li>
</ul>
You can also restore the game to its default settings and erase all
data.
Expand Down
6 changes: 6 additions & 0 deletions src/app/pages/settings/settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@
<app-checkbox [(checked)]="settings().particles"></app-checkbox>
</div>
</div>
<div class="setting-item">
<div class="name">Decorations</div>
<div class="value">
<app-checkbox [(checked)]="settings().decorations"></app-checkbox>
</div>
</div>
</div>
1 change: 0 additions & 1 deletion src/app/pages/settings/settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { User } from '../../common/models/user';
})
export class SettingsComponent implements OnDestroy {
private location = inject(Location);
private router = inject(Router);

protected authService = inject(AuthService);
protected settingsService = inject(SettingsService);
Expand Down

0 comments on commit 726be0a

Please sign in to comment.