diff --git a/StickerSlack.xcodeproj/project.pbxproj b/StickerSlack.xcodeproj/project.pbxproj index 64cef0a..67b3fa4 100644 --- a/StickerSlack.xcodeproj/project.pbxproj +++ b/StickerSlack.xcodeproj/project.pbxproj @@ -49,6 +49,8 @@ A97322A12FA7B9C8004B657D /* JumboMoji.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97322A02FA7B9C8004B657D /* JumboMoji.swift */; }; A97322A22FA7B9C8004B657D /* JumboMoji.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97322A02FA7B9C8004B657D /* JumboMoji.swift */; }; A97322A32FA7B9C8004B657D /* JumboMoji.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97322A02FA7B9C8004B657D /* JumboMoji.swift */; }; + A97322A52FA8CA2B004B657D /* JumboMojiTestView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97322A42FA8CA2B004B657D /* JumboMojiTestView.swift */; }; + A97322A62FA8CA2B004B657D /* JumboMojiTestView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97322A42FA8CA2B004B657D /* JumboMojiTestView.swift */; }; A975F9192FA38C8D00A5C62E /* EmojiPackGridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A975F9182FA38C8D00A5C62E /* EmojiPackGridView.swift */; }; A975F91A2FA38C8D00A5C62E /* EmojiPackGridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A975F9182FA38C8D00A5C62E /* EmojiPackGridView.swift */; }; A975F9202FA52B3600A5C62E /* AddToPackMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A975F91F2FA52B3600A5C62E /* AddToPackMenuView.swift */; }; @@ -219,6 +221,7 @@ A957C17D2ECFAA1100EA3EE9 /* GifView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GifView.swift; sourceTree = ""; }; A969D6932EA3E86500399C05 /* Messages.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Messages.framework; path = Library/Frameworks/Messages.framework; sourceTree = DEVELOPER_DIR; }; A97322A02FA7B9C8004B657D /* JumboMoji.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JumboMoji.swift; sourceTree = ""; }; + A97322A42FA8CA2B004B657D /* JumboMojiTestView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JumboMojiTestView.swift; sourceTree = ""; }; A975F9182FA38C8D00A5C62E /* EmojiPackGridView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPackGridView.swift; sourceTree = ""; }; A975F91F2FA52B3600A5C62E /* AddToPackMenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddToPackMenuView.swift; sourceTree = ""; }; A9773C2E2EA54AF000F3B753 /* StickerPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerPreview.swift; sourceTree = ""; }; @@ -363,6 +366,7 @@ A957C1732ECCE2CE00EA3EE9 /* SettingsView.swift */, A955B3F42EC22EE900E1732D /* SearchView.swift */, A975F91F2FA52B3600A5C62E /* AddToPackMenuView.swift */, + A97322A42FA8CA2B004B657D /* JumboMojiTestView.swift */, ); path = SwiftUI; sourceTree = ""; @@ -711,6 +715,7 @@ A9104C802EB4022500D160EA /* MSSticker.swift in Sources */, A9A7A43F2F6835F800BB84C6 /* Trending.swift in Sources */, A9A7A4422F68360200BB84C6 /* GifObject.swift in Sources */, + A97322A62FA8CA2B004B657D /* JumboMojiTestView.swift in Sources */, A97BFFBC2F9E6092000441E5 /* EmptyEmojiPackView.swift in Sources */, A975F9192FA38C8D00A5C62E /* EmojiPackGridView.swift in Sources */, A957C1772ECD008E00EA3EE9 /* Bundle.swift in Sources */, @@ -836,6 +841,7 @@ A9CD6C392EDDE37500B7F421 /* EmojiPackManager.swift in Sources */, A97BFFBD2F9E6092000441E5 /* EmptyEmojiPackView.swift in Sources */, A955B3F62EC22EE900E1732D /* SearchView.swift in Sources */, + A97322A52FA8CA2B004B657D /* JumboMojiTestView.swift in Sources */, A9BDEADF2F82BC93002798DF /* NoStickersView.swift in Sources */, A97BFFC02F9E745C000441E5 /* EmojiCollectionViewCell.swift in Sources */, A9B9A8322EB2CD29004C9245 /* SlackResponse.swift in Sources */, diff --git a/StickerSlack/JumboMoji.swift b/StickerSlack/JumboMoji.swift index 8929c9b..aedd0af 100644 --- a/StickerSlack/JumboMoji.swift +++ b/StickerSlack/JumboMoji.swift @@ -6,28 +6,131 @@ // import Foundation +import CoreGraphics -struct JumboMoji { +struct JumboMoji: CustomStringConvertible, Hashable { + var baseName: String var width: Int var height: Int - var baseName: String var type: JumboMoji.Style var items: [String] -// init(baseName: String, items: [String]) { -// let itemsBaseNameRemoved = items.map { String($0.dropFirst(baseName.count+1)) } -// -// -// let coordinates = itemsBaseNameRemoved.map { $0.dropLast($0.split(separator: "-").last?.count ?? 0) }.split(separator: "-").map { Int(String($0)) } -// self.width = width -// self.height = height -// self.baseName = baseName -// self.type = type -// self.items = items -// } + var description: String { + self.baseName + " " + "\(width)x\(height)" + } + + init(baseName: String, items: [String]) { + fatalError() + let itemsBaseNameRemoved = items.map { String($0.dropFirst(baseName.count+1)) } + var coordinates: [(Int, Int)] = [] + for item in itemsBaseNameRemoved { + let split = item.dropLast(item.split(separator: "-").last?.count ?? 0) + print(split) + } + self.width = 0 + self.height = 0 + self.baseName = baseName + self.type = .grid + self.items = items + } + + init?(components: [JumboMoji.Components]) { + guard components.allSatisfy({$0.baseName == components.first?.baseName}) else { return nil } + self.baseName = components.first!.baseName + + let coords = components.map { CGPoint(x: $0.x, y: $0.y) } + guard let width = Int(coords.sorted { $0.x > $1.x }.first?.x.formatted() ?? "") else { return nil } + self.width = width + guard let height = Int(coords.sorted { $0.y > $1.y }.first?.y.formatted() ?? "") else { return nil } + self.height = height + + self.type = .grid + self.items = components.map { "\($0.baseName)-\($0.coordinate)-\($0.id)-" } + } enum Style { case grid case btn } + + static func from(names input: [String]) -> [JumboMoji] { + guard input.count > 0 else { return [] } + let input = input.sorted() + + var jumboMojiComponents: [String: [JumboMoji.Components]] = [:] + for i in input.indices { + guard let currentComponents = splitIntoComponents(string: input[i]) else { continue } + + if jumboMojiComponents.isEmpty || jumboMojiComponents[currentComponents.baseName] == nil { + jumboMojiComponents[currentComponents.baseName] = [currentComponents] + } else { + jumboMojiComponents[currentComponents.baseName]?.append(currentComponents) + } + } + + print(jumboMojiComponents.mapValues({JumboMoji(components: $0)}).count) + var result: [JumboMoji] = [] + for item in jumboMojiComponents { + if let jumbomoji = JumboMoji(components: item.value) { + result.append(jumbomoji) + } + } + return result + } + + static func splitIntoComponents(string input: String) -> JumboMoji.Components? { + var string = input + + var baseNameCount: Int = -1 + for char in string { + if Int(String(char)) == nil { + baseNameCount += 1 + } else { break } + } + guard baseNameCount > -1 && baseNameCount != input.count else { return nil } + let baseName = String(input.prefix(baseNameCount)) + string = String(string.dropFirst(baseName.count+1)) + guard input.dropFirst(baseNameCount).first == "-" else { return nil } + + var coordCount = 1 + var freeSkip = 1 + for char in string { + if Int(String(char)) == nil { + guard freeSkip > 0 else { break } + freeSkip -= 1 + continue + } else { + coordCount += 1 + } + } + let coord = String(string.prefix(coordCount)) + let coordSplit = coord.split(separator: "-").map { String($0) } + guard coord.contains("-") && + Int(coordSplit.first ?? "x") != nil && + Int(coordSplit.last ?? "x") != nil + else { return nil } + string = String(string.dropFirst(coordCount+1)) + + let id = string + + return JumboMoji.Components( + baseName: baseName, + coordinate: coord, + id: id + ) + } + + struct Components { + var baseName: String + var coordinate: String + var x: Int { + let split = coordinate.split(separator: "-").first ?? "0" + return Int(split) ?? 0 + } + var y: Int { + let split = coordinate.split(separator: "-").last ?? "0" + return Int(split) ?? 0 + } + var id: String + } } diff --git a/StickerSlack/SwiftUI/JumboMojiTestView.swift b/StickerSlack/SwiftUI/JumboMojiTestView.swift new file mode 100644 index 0000000..a294c82 --- /dev/null +++ b/StickerSlack/SwiftUI/JumboMojiTestView.swift @@ -0,0 +1,51 @@ +// +// JumboMojiTestView.swift +// StickerSlack +// +// Created by neon443 on 04/05/2026. +// + +import SwiftUI + +struct JumboMojiTestView: View { + @State var hoarder: EmojiHoarder + @State var searchTerm: String = "" + @State var searchResult: [String] = [] + + var body: some View { + ScrollView { + TextField("search", text: $searchTerm) + .autocorrectionDisabled() + .onChange(of: searchTerm) { _ in + searchResult = hoarder.trie.search(for: searchTerm, previousQuery: nil, previousResult: nil) + } + ForEach(JumboMoji.from(names: searchResult), id: \.self) { jumboMoji in + VStack { + ForEach(0..?) -> [String] { + guard !query.isEmpty else { return [] } var result: Set = wordlist if let previousQuery, let previousResult,