-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The new `src/Configs` folder includes two classes which serve as an additional layer between raw data coming from JSON files and the game elements themselves. This layer is intended to be a simple yet efficient way to maintain game compatibility across different versions. You can read more about it in the following issue: Extract all JSON structures to their own classes #70
- Loading branch information
Showing
5 changed files
with
127 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
local class = require "com/class" | ||
|
||
---@class ShooterConfig | ||
---@overload fun(data):ShooterConfig | ||
local ShooterConfig = class:derive("ShooterConfig") | ||
|
||
local Vec2 = require("src/Essentials/Vector2") | ||
local ShooterMovementConfig = require("src/Configs/ShooterMovement") | ||
|
||
|
||
|
||
---Constructs a new Shooter Config. | ||
---@param data table Raw data parsed from `config/shooters/*.json`. | ||
---@param path string Path to the file. The file is not loaded here, but is used in error messages. | ||
function ShooterConfig:new(data, path) | ||
self._path = path | ||
|
||
self.movement = ShooterMovementConfig(data.movement, path) | ||
|
||
self.sprite = _Game.resourceManager:getSprite(data.sprite) | ||
self.shadowSprite = _Game.resourceManager:getSprite(data.shadowSprite) | ||
|
||
self.reticle = { | ||
---@type Sprite? | ||
sprite = data.reticle.sprite and _Game.resourceManager:getSprite(data.reticle.sprite), | ||
---@type Sprite? | ||
nextBallSprite = data.reticle.nextBallSprite and _Game.resourceManager:getSprite(data.reticle.nextBallSprite), | ||
---@type Vector2? | ||
nextBallOffset = _ParseVec2(data.reticle.nextBallOffset), | ||
---@type Sprite? | ||
radiusSprite = data.reticle.radiusSprite and _Game.resourceManager:getSprite(data.reticle.radiusSprite) | ||
} | ||
|
||
self.speedShotBeam = { | ||
sprite = _Game.resourceManager:getSprite(data.speedShotBeam.sprite), | ||
---@type number | ||
fadeTime = data.speedShotBeam.fadeTime, | ||
---@type string | ||
renderingType = data.speedShotBeam.renderingType, | ||
---@type boolean | ||
colored = data.speedShotBeam.colored | ||
} | ||
|
||
---@type string | ||
self.speedShotParticle = data.speedShotParticle | ||
---@type number | ||
self.shootSpeed = data.shootSpeed | ||
---@type Vector2 | ||
self.hitboxSize = _ParseVec2(data.hitboxSize) or Vec2() | ||
end | ||
|
||
|
||
|
||
return ShooterConfig |
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,41 @@ | ||
local class = require "com/class" | ||
|
||
---@class ShooterMovementConfig | ||
---@overload fun(data):ShooterMovementConfig | ||
local ShooterMovementConfig = class:derive("ShooterMovementConfig") | ||
|
||
-- Place your imports here | ||
|
||
|
||
|
||
---Constructs a new Shooter Movement Config. | ||
---@param data table Raw shooter movement data, found in `config/levels/*.json` and `config/shooters/*.json`. | ||
---@param path string Path to the file. The file is not loaded here, but is used in error messages. | ||
function ShooterMovementConfig:new(data, path) | ||
self._path = path | ||
|
||
---@type string | ||
self.type = data.type | ||
|
||
if self.type == "linear" then | ||
---@type number | ||
self.xMin = data.xMin | ||
---@type number | ||
self.xMax = data.xMax | ||
---@type number | ||
self.y = data.y | ||
---@type number | ||
self.angle = data.angle | ||
elseif self.type == "circular" then | ||
---@type number | ||
self.x = data.x | ||
---@type number | ||
self.y = data.y | ||
else | ||
error(string.format("Failed to load file %s, unknown shooter type: %s (expected \"linear\" or \"circular\")", path, data.type)) | ||
end | ||
end | ||
|
||
|
||
|
||
return ShooterMovementConfig |
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