Skip to content

Commit

Permalink
[#2] ADD: MonsterListItem View, MonsterListInformation View
Browse files Browse the repository at this point in the history
  • Loading branch information
psychehose committed Jun 10, 2023
1 parent ec5f867 commit 1beb51c
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 77 deletions.
22 changes: 19 additions & 3 deletions RunningRPG.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
770A00292A34221900160BD6 /* Character.swift in Sources */ = {isa = PBXBuildFile; fileRef = 770A00282A34221900160BD6 /* Character.swift */; };
770A002B2A34236700160BD6 /* Equiment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 770A002A2A34236700160BD6 /* Equiment.swift */; };
770A002D2A34240200160BD6 /* Monster.swift in Sources */ = {isa = PBXBuildFile; fileRef = 770A002C2A34240200160BD6 /* Monster.swift */; };
7DF63E742A342F3A0051985C /* HomeBottomView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DF63E732A342F3A0051985C /* HomeBottomView.swift */; };
770A00302A34303100160BD6 /* MonsterListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 770A002F2A34303100160BD6 /* MonsterListItem.swift */; };
770A00332A34385A00160BD6 /* MonsterListItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 770A00322A34385A00160BD6 /* MonsterListItemView.swift */; };
770A00352A34402400160BD6 /* MonsterInformationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 770A00342A34402400160BD6 /* MonsterInformationView.swift */; };
7DF63E742A342F3A0051985C /* HomeBottomView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DF63E732A342F3A0051985C /* HomeBottomView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -102,8 +104,10 @@
770A00282A34221900160BD6 /* Character.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Character.swift; sourceTree = "<group>"; };
770A002A2A34236700160BD6 /* Equiment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Equiment.swift; sourceTree = "<group>"; };
770A002C2A34240200160BD6 /* Monster.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Monster.swift; sourceTree = "<group>"; };
7DF63E732A342F3A0051985C /* HomeBottomView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeBottomView.swift; sourceTree = "<group>"; };
770A002F2A34303100160BD6 /* MonsterListItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MonsterListItem.swift; sourceTree = "<group>"; };
770A00322A34385A00160BD6 /* MonsterListItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MonsterListItemView.swift; sourceTree = "<group>"; };
770A00342A34402400160BD6 /* MonsterInformationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MonsterInformationView.swift; sourceTree = "<group>"; };
7DF63E732A342F3A0051985C /* HomeBottomView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeBottomView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -234,6 +238,7 @@
2A9A06D62A342BD400EC8141 /* MonsterList */ = {
isa = PBXGroup;
children = (
770A00312A34384B00160BD6 /* Model */,
770A002E2A34301B00160BD6 /* Subviews */,
2A9A06CE2A3426B800EC8141 /* MonsterListView.swift */,
);
Expand Down Expand Up @@ -283,11 +288,20 @@
770A002E2A34301B00160BD6 /* Subviews */ = {
isa = PBXGroup;
children = (
770A002F2A34303100160BD6 /* MonsterListItem.swift */,
770A00322A34385A00160BD6 /* MonsterListItemView.swift */,
770A00342A34402400160BD6 /* MonsterInformationView.swift */,
);
path = Subviews;
sourceTree = "<group>";
};
770A00312A34384B00160BD6 /* Model */ = {
isa = PBXGroup;
children = (
770A002F2A34303100160BD6 /* MonsterListItem.swift */,
);
path = Model;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -450,6 +464,7 @@
buildActionMask = 2147483647;
files = (
3985AB322A344859004F1AA6 /* RunningRPGDynamicIslandLiveActivity.swift in Sources */,
770A00332A34385A00160BD6 /* MonsterListItemView.swift in Sources */,
7DF63E742A342F3A0051985C /* HomeBottomView.swift in Sources */,
2A9A06DA2A34311A00EC8141 /* HomeTopView.swift in Sources */,
2A9A06A12A3414B500EC8141 /* HomeView.swift in Sources */,
Expand All @@ -460,6 +475,7 @@
2A9A069F2A3414B500EC8141 /* RunningRPGApp.swift in Sources */,
3985AB2B2A3447EF004F1AA6 /* RunningRPGDynamicIsland.intentdefinition in Sources */,
770A00292A34221900160BD6 /* Character.swift in Sources */,
770A00352A34402400160BD6 /* MonsterInformationView.swift in Sources */,
770A002D2A34240200160BD6 /* Monster.swift in Sources */,
770A002B2A34236700160BD6 /* Equiment.swift in Sources */,
3961A9A12A343C9F000745FC /* Avatar.swift in Sources */,
Expand Down
20 changes: 20 additions & 0 deletions RunningRPG/Model/Monster.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,23 @@ struct Monster: Hashable, Codable, Identifiable {
name
}
}

enum MonsterType {
case swordShield
case pizza
case gun
case squirrel

var urls: String {
switch self {
case .squirrel:
return "monster_ squirrel"
case .gun:
return "monster_gun"
case .pizza:
return "monster_pizza"
case .swordShield:
return "monster_swordshield"
}
}
}
63 changes: 63 additions & 0 deletions RunningRPG/Tabbar/MonsterList/Model/MonsterListItem.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// MonsterListItem.swift
// RunningRPG
//
// Created by 김호세 on 6/10/23.
//

import Foundation

internal final class MonsterListItem: Identifiable {
var monster: Monster

internal init(monster: Monster) {
self.monster = monster
}
}


extension MonsterListItem {
static func generateMonsters() -> [MonsterListItem] {
return [
MonsterListItem(
monster: Monster.init(
name: "총든 몬스터",
hp: 10.0,
currentHp: 10.0,
avatar: MonsterType.gun.urls,
level: 0, isOpen: true
)
),
MonsterListItem(
monster: Monster.init(
name: "다람쥐 몬스터",
hp: 20.0,
currentHp: 20.0,
avatar: MonsterType.squirrel.urls,
level: 1,
isOpen: true
)
),
MonsterListItem(
monster: Monster.init(
name: "피자 몬스터",
hp: 30.0,
currentHp: 30.0,
avatar: MonsterType.pizza.urls,
level: 2,
isOpen: true
)
),
MonsterListItem(
monster: Monster.init(
name: "칼이랑 방패든 몬스터",
hp: 40.0,
currentHp: 40.0,
avatar: MonsterType.swordShield.urls,
level: 3,
isOpen: true
)
),
]
}
}
48 changes: 4 additions & 44 deletions RunningRPG/Tabbar/MonsterList/MonsterListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,55 +18,15 @@ struct MonsterListView: View {

List {
ForEach(listItems) { item in
NavigationLink {
Text("Hello")
} label: {
Image(systemName: "sun.min")
Text("\(item.monster.name)")
}

MonsterListItemView(item: item)
}
}

// NavigationView {
// List {
// ForEach(listItems) { item in
// NavigationLink {
// Text("Item at \(item.monster., format: Date.FormatStyle(date: .numeric, time: .standard))")
// } label: {
// Text(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))
// }
// }
// .onDelete(perform: deleteItems)
// }
// .toolbar {
// ToolbarItem(placement: .navigationBarTrailing) {
// EditButton()
// }
// ToolbarItem {
// Button(action: addItem) {
// Label("Add Item", systemImage: "plus")
// }
// }
// }
// Text("Select an item")
// }
.listRowSpacing(20)
}

private func addItem() {
// withAnimation {
// let newItem = Item(timestamp: Date())
// modelContext.insert(newItem)
// }
}
private func addItem() {}

private func deleteItems(offsets: IndexSet) {
// withAnimation {
// for index in offsets {
// modelContext.delete(items[index])
// }
// }
}
private func deleteItems(offsets: IndexSet) { }
}

#Preview {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// MonsterInformationView.swift
// RunningRPG
//
// Created by 김호세 on 6/10/23.
//

import SwiftUI

struct MonsterInformationView: View {

let item: MonsterListItem

var body: some View {
VStack(alignment: .leading, spacing: 10, content: {
HStack(content: {
Text("\(item.monster.name)")
Spacer()
Text("Level - \(item.monster.level)")
})
HStack(alignment: .top, spacing: 5, content: {
Text("\(item.monster.currentHp) / \(item.monster.hp)")
})
})
}
}
30 changes: 0 additions & 30 deletions RunningRPG/Tabbar/MonsterList/Subviews/MonsterListItem.swift

This file was deleted.

22 changes: 22 additions & 0 deletions RunningRPG/Tabbar/MonsterList/Subviews/MonsterListItemView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// MonsterListItemView.swift
// RunningRPG
//
// Created by 김호세 on 6/10/23.
//


import SwiftUI

struct MonsterListItemView: View {

let item: MonsterListItem

var body: some View {

HStack(alignment: .center, spacing: 10, content: {
Image(item.monster.avatar).resizable().frame(width: 50, height: 50)
MonsterInformationView(item: item)
})
}
}

0 comments on commit 1beb51c

Please sign in to comment.