-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support the environment settings in games
- Loading branch information
1 parent
78bdae8
commit cc11ec0
Showing
5 changed files
with
105 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2020 Las Venturas Playground. All rights reserved. | ||
// Use of this source code is governed by the MIT license, a copy of which can | ||
// be found in the LICENSE file. | ||
|
||
import { EnvironmentSettings } from 'features/games/environment_settings.js'; | ||
import { Game } from 'features/games/game.js'; | ||
|
||
// Implementation of the Game class that provides the low-level functionality offered directly by | ||
// the Games API. Most features will want to extend this class rather than Game directly. | ||
export class GameBase extends Game { | ||
#gravity_ = null; | ||
#time_ = null; | ||
#weather_ = null; | ||
|
||
async onInitialized(settings, userData) { | ||
const environment = settings.get('game/environment'); | ||
if (environment) { | ||
this.#gravity_ = EnvironmentSettings.getGravityForOption(environment.gravity); | ||
this.#time_ = EnvironmentSettings.getTimeForOption(environment.time); | ||
this.#weather_ = EnvironmentSettings.getWeatherForOption(environment.weather); | ||
} | ||
} | ||
|
||
async onPlayerAdded(player) { | ||
// Update the gravity, time and weather for the |player|, but only when necessary. | ||
if (this.#gravity_) | ||
player.gravity = this.#gravity_; | ||
|
||
if (this.#time_) | ||
player.time = [ this.#time_, 20 ]; | ||
|
||
if (this.#weather_) | ||
player.weather = this.#weather_; | ||
} | ||
|
||
async onPlayerRemoved(player) { | ||
// Restore the gravity for the player. The |player|'s weather and time will be reset when | ||
// their state gets deserialized immediately after this. | ||
if (this.#gravity_) | ||
player.gravity = Player.kDefaultGravity; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters