Skip to content

Commit

Permalink
Bugfix: Breaklet score board not working
Browse files Browse the repository at this point in the history
  • Loading branch information
p-z-l committed Aug 22, 2020
1 parent e821bfa commit 1161e42
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Breaklet/Breaklet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
B372CBA5247FD15A008DEA68 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
B372CBA8247FD15A008DEA68 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
B372CBAA247FD15A008DEA68 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
B372CBAB247FD15A008DEA68 /* Breakout.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Breakout.entitlements; sourceTree = "<group>"; };
B372CBAB247FD15A008DEA68 /* Breaklet.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Breaklet.entitlements; sourceTree = "<group>"; };
B372CBB1247FD1FF008DEA68 /* BlockSpriteNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockSpriteNode.swift; sourceTree = "<group>"; };
B372CBB3247FD25C008DEA68 /* NSColorExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSColorExtension.swift; sourceTree = "<group>"; };
B372CBB5247FDB80008DEA68 /* PaddleSpriteNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaddleSpriteNode.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -99,7 +99,7 @@
B39B4480247FE54C00C35D59 /* SpriteNodes */,
B372CBA5247FD15A008DEA68 /* Assets.xcassets */,
B372CBAA247FD15A008DEA68 /* Info.plist */,
B372CBAB247FD15A008DEA68 /* Breakout.entitlements */,
B372CBAB247FD15A008DEA68 /* Breaklet.entitlements */,
);
path = Breaklet;
sourceTree = "<group>";
Expand Down Expand Up @@ -335,7 +335,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = Breakout/Breakout.entitlements;
CODE_SIGN_ENTITLEMENTS = Breaklet/Breaklet.entitlements;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
Expand All @@ -356,7 +356,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = Breakout/Breakout.entitlements;
CODE_SIGN_ENTITLEMENTS = Breaklet/Breaklet.entitlements;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
Expand Down
File renamed without changes.
24 changes: 10 additions & 14 deletions Breaklet/Breaklet/Score.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,21 @@ class ScoreBoard: NSObject {
}

func insert(_ score: Score) {
guard scores.count >= 10 else {
if (score >= scores.last!) || scores.count<=10 {
scores.append(score)
return
}
if score >= scores.last! {
scores.append(score)
scores.sort()
scores.removeLast()
scores.sort { (lhs, rhs) -> Bool in
return lhs.value > rhs.value
}
if scores.count > 10 {
scores.removeLast()
}
print(scores)
}
}

func saveToUserDefaults() {
for i in 0..<10 {
guard i < scores.count else {
for indexToRemove in i..<10 {
UserDefaults.standard.removeObject(forKey: "HighScore_\(indexToRemove)")
}
return
}
for i in 0..<scores.count {
guard i < 10 else { return }
let score = scores[i]
let encoder = JSONEncoder()
if let encoded = try? encoder.encode(score) {
Expand Down
7 changes: 7 additions & 0 deletions Breaklet/Breaklet/SpriteNodes/ScoreBoardNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ class ScoreBoardNode: SKSpriteNode {
self.zPosition = 200
}

private var rowNodes: [SKShapeNode] {
return self.children.filter { $0.name == "rowNode" } as! [SKShapeNode]
}

func updateData() {
for rowNode in rowNodes {
rowNode.removeFromParent()
}
let scores = ScoreBoard.shared.scores
drawRow(index: 0, scoreText: "Score", nameText: "PlayerName")
for i in 0..<scores.count {
Expand Down

0 comments on commit 1161e42

Please sign in to comment.