Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from cs3217-2324/feat/persistence
Persistence
- Loading branch information
Showing
19 changed files
with
677 additions
and
16 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
9 changes: 9 additions & 0 deletions
9
star-dash/star-dash.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
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,14 @@ | ||
// | ||
// EntityType.swift | ||
// star-dash | ||
// | ||
// Created by Lau Rui han on 21/3/24. | ||
// | ||
|
||
import Foundation | ||
enum EntityType: String, Encodable, Decodable { | ||
case Monster = "monster" | ||
case Collectible = "collectible" | ||
case Obstacle = "obstacle" | ||
case Tool = "tool" | ||
} |
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
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,21 @@ | ||
// | ||
// Level.swift | ||
// star-dash | ||
// | ||
// Created by Lau Rui han on 21/3/24. | ||
// | ||
|
||
import Foundation | ||
struct Level { | ||
var name: String | ||
var entities: [Entity] | ||
init(name: String, entities: [Entity]) { | ||
self.name = name | ||
self.entities = entities | ||
} | ||
|
||
init(levelPersistable: LevelPersistable, entityPersistables: [EntityPersistable]) { | ||
let entities = entityPersistables.compactMap { $0.toEntity() } | ||
self.init(name: levelPersistable.name, entities: entities) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
star-dash/star-dash/Persistence/CollectibleEntityPersistable.swift
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,19 @@ | ||
// | ||
// CollectibleEntityPersistable.swift | ||
// star-dash | ||
// | ||
// Created by Lau Rui han on 22/3/24. | ||
// | ||
|
||
import Foundation | ||
struct CollectibleEntityPersistable: Codable, EntityPersistable { | ||
|
||
var levelId: Int64 | ||
var position: CGPoint | ||
var sprite: String | ||
var points: Int | ||
var size: CGSize | ||
func toEntity() -> Entity { | ||
Collectible(position: self.position, sprite: self.sprite, points: self.points, size: self.size) | ||
} | ||
} |
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,18 @@ | ||
// | ||
// LevelData.swift | ||
// star-dash | ||
// | ||
// Created by Lau Rui han on 22/3/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct LevelData: Codable { | ||
var id: Int64 | ||
var name: String | ||
var size: CGSize | ||
var monsters: [MonsterEntityPersistable] | ||
var obstacles: [ObstacleEntityPersistable] | ||
var collectibles: [CollectibleEntityPersistable] | ||
var tools: [ToolEntityPersistable] | ||
} |
Oops, something went wrong.