Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persistence #19

Merged
merged 8 commits into from Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 65 additions & 0 deletions star-dash/star-dash.xcodeproj/project.pbxproj
Expand Up @@ -53,6 +53,15 @@
4E3458E92BA75E7C00E817C6 /* SpriteComponentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E3458E82BA75E7C00E817C6 /* SpriteComponentTests.swift */; };
4E3458EB2BA75E8B00E817C6 /* PhysicsComponentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E3458EA2BA75E8B00E817C6 /* PhysicsComponentTests.swift */; };
4E3458ED2BA75F1200E817C6 /* Util.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E3458EC2BA75F1200E817C6 /* Util.swift */; };
4E59E2512BAB2EAE007B3FA7 /* StorageManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E59E2502BAB2EAE007B3FA7 /* StorageManager.swift */; };
4E59E2532BAB3061007B3FA7 /* Database.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E59E2522BAB3061007B3FA7 /* Database.swift */; };
4E59E2562BAB33EC007B3FA7 /* SQLite in Frameworks */ = {isa = PBXBuildFile; productRef = 4E59E2552BAB33EC007B3FA7 /* SQLite */; };
4E59E2582BAB3B5B007B3FA7 /* data.json in Resources */ = {isa = PBXBuildFile; fileRef = 4E59E2572BAB3B5B007B3FA7 /* data.json */; };
4E59E25B2BAB3FDB007B3FA7 /* Level.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E59E25A2BAB3FDB007B3FA7 /* Level.swift */; };
4E59E25D2BAB405A007B3FA7 /* EntityPersistable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E59E25C2BAB405A007B3FA7 /* EntityPersistable.swift */; };
4E59E25F2BAB4134007B3FA7 /* EntityType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E59E25E2BAB4134007B3FA7 /* EntityType.swift */; };
4E59E2612BAB42FD007B3FA7 /* LevelPersistable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E59E2602BAB42FD007B3FA7 /* LevelPersistable.swift */; };
4E59E2632BACB9E2007B3FA7 /* LevelData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E59E2622BACB9E2007B3FA7 /* LevelData.swift */; };
4E630EF62B9F7E070008F887 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E630EF52B9F7E070008F887 /* AppDelegate.swift */; };
4E630EF82B9F7E070008F887 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E630EF72B9F7E070008F887 /* SceneDelegate.swift */; };
4E630EFA2B9F7E070008F887 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E630EF92B9F7E070008F887 /* ViewController.swift */; };
Expand Down Expand Up @@ -174,6 +183,14 @@
4E3458E82BA75E7C00E817C6 /* SpriteComponentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpriteComponentTests.swift; sourceTree = "<group>"; };
4E3458EA2BA75E8B00E817C6 /* PhysicsComponentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhysicsComponentTests.swift; sourceTree = "<group>"; };
4E3458EC2BA75F1200E817C6 /* Util.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Util.swift; sourceTree = "<group>"; };
4E59E2502BAB2EAE007B3FA7 /* StorageManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageManager.swift; sourceTree = "<group>"; };
4E59E2522BAB3061007B3FA7 /* Database.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Database.swift; sourceTree = "<group>"; };
4E59E2572BAB3B5B007B3FA7 /* data.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = data.json; sourceTree = "<group>"; };
4E59E25A2BAB3FDB007B3FA7 /* Level.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Level.swift; sourceTree = "<group>"; };
4E59E25C2BAB405A007B3FA7 /* EntityPersistable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntityPersistable.swift; sourceTree = "<group>"; };
4E59E25E2BAB4134007B3FA7 /* EntityType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntityType.swift; sourceTree = "<group>"; };
4E59E2602BAB42FD007B3FA7 /* LevelPersistable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LevelPersistable.swift; sourceTree = "<group>"; };
4E59E2622BACB9E2007B3FA7 /* LevelData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LevelData.swift; sourceTree = "<group>"; };
4E630EF22B9F7E070008F887 /* star-dash.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "star-dash.app"; sourceTree = BUILT_PRODUCTS_DIR; };
4E630EF52B9F7E070008F887 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
4E630EF72B9F7E070008F887 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -227,6 +244,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
4E59E2562BAB33EC007B3FA7 /* SQLite in Frameworks */,
14E247932BA2CA920071FFC0 /* DequeModule in Frameworks */,
E6E4B8302BA6C8D4005ABAB1 /* SDPhysicsEngine in Frameworks */,
);
Expand Down Expand Up @@ -383,6 +401,27 @@
path = Components;
sourceTree = "<group>";
};
4E59E24F2BAB2DBB007B3FA7 /* Persistence */ = {
isa = PBXGroup;
children = (
4E59E2502BAB2EAE007B3FA7 /* StorageManager.swift */,
4E59E2522BAB3061007B3FA7 /* Database.swift */,
4E59E2572BAB3B5B007B3FA7 /* data.json */,
4E59E25C2BAB405A007B3FA7 /* EntityPersistable.swift */,
4E59E2602BAB42FD007B3FA7 /* LevelPersistable.swift */,
4E59E2622BACB9E2007B3FA7 /* LevelData.swift */,
);
path = Persistence;
sourceTree = "<group>";
};
4E59E2592BAB3FC9007B3FA7 /* Model */ = {
isa = PBXGroup;
children = (
4E59E25A2BAB3FDB007B3FA7 /* Level.swift */,
);
path = Model;
sourceTree = "<group>";
};
4E630EE92B9F7E070008F887 = {
isa = PBXGroup;
children = (
Expand All @@ -409,6 +448,8 @@
4E630EF42B9F7E070008F887 /* star-dash */ = {
isa = PBXGroup;
children = (
4E59E2592BAB3FC9007B3FA7 /* Model */,
4E59E24F2BAB2DBB007B3FA7 /* Persistence */,
E6A011152BA5D111006904D9 /* GameBridge */,
46B8C0982BA328BF00498705 /* GameEngine */,
E6A745102BA057040080C1BE /* Rendering */,
Expand Down Expand Up @@ -475,6 +516,7 @@
isa = PBXGroup;
children = (
4E630F362B9F91DE0008F887 /* PlayerSprite.swift */,
4E59E25E2BAB4134007B3FA7 /* EntityType.swift */,
);
path = Enums;
sourceTree = "<group>";
Expand Down Expand Up @@ -576,6 +618,7 @@
packageProductDependencies = (
14E247922BA2CA920071FFC0 /* DequeModule */,
E6E4B82F2BA6C8D4005ABAB1 /* SDPhysicsEngine */,
4E59E2552BAB33EC007B3FA7 /* SQLite */,
);
productName = "star-dash";
productReference = 4E630EF22B9F7E070008F887 /* star-dash.app */;
Expand Down Expand Up @@ -651,6 +694,7 @@
mainGroup = 4E630EE92B9F7E070008F887;
packageReferences = (
14E247912BA2CA920071FFC0 /* XCRemoteSwiftPackageReference "swift-collections" */,
4E59E2542BAB33EC007B3FA7 /* XCRemoteSwiftPackageReference "SQLite.swift" */,
);
productRefGroup = 4E630EF32B9F7E070008F887 /* Products */;
projectDirPath = "";
Expand All @@ -672,6 +716,7 @@
4E630F022B9F7E090008F887 /* LaunchScreen.storyboard in Resources */,
4E630EFF2B9F7E090008F887 /* Assets.xcassets in Resources */,
4E630EFD2B9F7E070008F887 /* Main.storyboard in Resources */,
4E59E2582BAB3B5B007B3FA7 /* data.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -718,6 +763,7 @@
buildActionMask = 2147483647;
files = (
46D418182BA5CD840091A38B /* Player+Collidable.swift in Sources */,
4E59E25B2BAB3FDB007B3FA7 /* Level.swift in Sources */,
46D4181E2BA5D2620091A38B /* Monster+Collidable.swift in Sources */,
E6B1DC902BA34A4800473563 /* SDPhysicsEngine in Sources */,
4E630F272B9F7E770008F887 /* Entity.swift in Sources */,
Expand All @@ -736,17 +782,20 @@
46D4181A2BA5CDBD0091A38B /* CollisionHandler.swift in Sources */,
4E86605F2BA095E30035530D /* Collectible.swift in Sources */,
E64361122BA4C2CD003850FD /* ObjectModule.swift in Sources */,
4E59E2532BAB3061007B3FA7 /* Database.swift in Sources */,
4E8660662BA097D40035530D /* PhysicsConstants.swift in Sources */,
143AA3952BA4DF1C009C28E7 /* MonsterAttackPlayerEvent.swift in Sources */,
143AA3932BA4DBE7009C28E7 /* PlayerMonsterContactEvent.swift in Sources */,
46D418162BA5CBD60091A38B /* Collidable.swift in Sources */,
461148912BA1CDBF0073E7E1 /* SystemManager.swift in Sources */,
4E59E2512BAB2EAE007B3FA7 /* StorageManager.swift in Sources */,
145F2C842BA22CA300457549 /* EventModifiable.swift in Sources */,
4E630EFA2B9F7E070008F887 /* ViewController.swift in Sources */,
E6A011172BA5F4AD006904D9 /* EntitySyncInterface.swift in Sources */,
E6B0AAD52BAAE4EC009CB939 /* PlayerFloorContactEvent.swift in Sources */,
E64361132BA4C2CD003850FD /* PhysicsModule.swift in Sources */,
4E630F322B9F887C0008F887 /* PhysicsComponent.swift in Sources */,
4E59E25D2BAB405A007B3FA7 /* EntityPersistable.swift in Sources */,
1471B0AD2BA6AE4E00878B14 /* UseGrappleHookEvent.swift in Sources */,
4E630EF62B9F7E070008F887 /* AppDelegate.swift in Sources */,
461148962BA1D53D0073E7E1 /* PositionSystem.swift in Sources */,
Expand All @@ -769,8 +818,10 @@
143AA3972BA4E0D9009C28E7 /* PickupCollectibleEvent.swift in Sources */,
46D418242BA5D5280091A38B /* Tool+Collidable.swift in Sources */,
E64361142BA4C2CD003850FD /* CreationModule.swift in Sources */,
4E59E2612BAB42FD007B3FA7 /* LevelPersistable.swift in Sources */,
E6A745162BA057040080C1BE /* MTKRenderer.swift in Sources */,
E6A745182BA057040080C1BE /* Renderer.swift in Sources */,
4E59E25F2BAB4134007B3FA7 /* EntityType.swift in Sources */,
E6A745172BA057040080C1BE /* ControlView.swift in Sources */,
14970F562BA8177B00CC1E8A /* GameConstants.swift in Sources */,
1471B0A42BA6AAF200878B14 /* PlayerDeathEvent.swift in Sources */,
Expand All @@ -789,6 +840,7 @@
461148982BA1E41F0073E7E1 /* PhysicsSystem.swift in Sources */,
4E630F2E2B9F81850008F887 /* HealthComponent.swift in Sources */,
4E86605C2BA095460035530D /* Monster.swift in Sources */,
4E59E2632BACB9E2007B3FA7 /* LevelData.swift in Sources */,
145F2C802BA203B400457549 /* Event.swift in Sources */,
1471B0A22BA6AA2200878B14 /* RespawnEvent.swift in Sources */,
46D418112BA5C88B0091A38B /* Wall.swift in Sources */,
Expand Down Expand Up @@ -1171,6 +1223,14 @@
minimumVersion = 1.1.0;
};
};
4E59E2542BAB33EC007B3FA7 /* XCRemoteSwiftPackageReference "SQLite.swift" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/stephencelis/SQLite.swift.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.15.0;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand All @@ -1179,6 +1239,11 @@
package = 14E247912BA2CA920071FFC0 /* XCRemoteSwiftPackageReference "swift-collections" */;
productName = DequeModule;
};
4E59E2552BAB33EC007B3FA7 /* SQLite */ = {
isa = XCSwiftPackageProductDependency;
package = 4E59E2542BAB33EC007B3FA7 /* XCRemoteSwiftPackageReference "SQLite.swift" */;
productName = SQLite;
};
E6B1DC8E2BA3459600473563 /* SDPhysicsEngine */ = {
isa = XCSwiftPackageProductDependency;
productName = SDPhysicsEngine;
Expand Down
@@ -1,5 +1,14 @@
{
"pins" : [
{
"identity" : "sqlite.swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/stephencelis/SQLite.swift.git",
"state" : {
"revision" : "e78ae0220e17525a15ac68c697a155eb7a672a8e",
"version" : "0.15.0"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
Expand Down
14 changes: 14 additions & 0 deletions star-dash/star-dash/Enums/EntityType.swift
@@ -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"
}
Expand Up @@ -16,7 +16,6 @@ class EntityManager {
var componentMap: ComponentMap
var entityMap: EntityMap
var entityComponentMap: EntityComponentMap

init(componentMap: ComponentMap, entityMap: EntityMap, entityComponentMap: EntityComponentMap) {
self.componentMap = componentMap
self.entityMap = entityMap
Expand Down
21 changes: 21 additions & 0 deletions star-dash/star-dash/Model/Level.swift
@@ -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
}

Check failure on line 16 in star-dash/star-dash/Model/Level.swift

View workflow job for this annotation

GitHub Actions / build

Lines should not have trailing whitespace. (trailing_whitespace)
init(levelPersistable: LevelPersistable, entityPersistables: [EntityPersistable]) {
let entities = entityPersistables.map { $0.toEntity() }
self.init(name: levelPersistable.name, entities: entities)
}
}