Skip to content

Commit

Permalink
feat: preliminary views for Mythic Harmony
Browse files Browse the repository at this point in the history
  • Loading branch information
vapidinfinity committed Jan 16, 2025
1 parent c2820dd commit 24028b5
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 3 deletions.
23 changes: 23 additions & 0 deletions Mythic/Assets.xcassets/Harmony+AppIcon.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "Mythic + Harmony.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Mythic + Harmony@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Mythic + Harmony@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions Mythic/Assets.xcassets/HarmonyIcon.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "Harmony Logo.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Harmony Logo@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Harmony Logo@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 18 additions & 3 deletions Mythic/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -2587,13 +2587,13 @@
"value" : "%1$@ \"%2$@\"..."
}
},
"nl" : {
"nb" : {
"stringUnit" : {
"state" : "new",
"value" : "%1$@ \"%2$@\"..."
}
},
"no" : {
"nl" : {
"stringUnit" : {
"state" : "new",
"value" : "%1$@ \"%2$@\"..."
Expand Down Expand Up @@ -5353,6 +5353,9 @@
}
}
}
},
"Are you sure you want to proceed without rating?" : {

},
"Are you sure you want to remove Mythic Engine?" : {
"localizations" : {
Expand Down Expand Up @@ -15287,6 +15290,9 @@
}
}
}
},
"Harmony ratings help every Mythic user understand how well a game runs." : {

},
"Hello, world!" : {
"localizations" : {
Expand Down Expand Up @@ -16240,6 +16246,9 @@
},
"Horizontal" : {

},
"How well did \"%@\" run?" : {

},
"I have read and agreed to the terms of the software license agreement." : {
"localizations" : {
Expand Down Expand Up @@ -26141,6 +26150,9 @@
}
}
}
},
"Please choose a rating." : {

},
"Preview" : {
"comment" : "Within the context of Mythic Engine",
Expand Down Expand Up @@ -33761,6 +33773,9 @@
}
}
}
},
"This will be uploaded to Harmony, Mythic's game compatibility database." : {

},
"This will cancel \"%@\"'s creation." : {
"localizations" : {
Expand Down Expand Up @@ -40432,4 +40447,4 @@
}
},
"version" : "1.0"
}
}
8 changes: 8 additions & 0 deletions Mythic/Utilities/Game.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,14 @@ class Game: ObservableObject, Hashable, Codable, Identifiable, Equatable {
case epic = "Epic"
case local = "Local"
}

enum Compatibility: String, CaseIterable {
case unplayable = "The game doesn't launch."
case launchable = "The game launches, but you are unable to play."
case runable = "The game launches and you are able to play, but some game features are nonfunctional."
case playable = "The game runs well, and is mostly feature-complete."
case excellent = "The game runs well, and is feature-complete."
}
}

/// Returns the app names of all favourited games.
Expand Down
50 changes: 50 additions & 0 deletions Mythic/Views/Unified/Modules/StarRatingView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// StarRatingView.swift
// Mythic
//
// Created by vapidinfinity (esi) on 16/1/2025.
//

import Foundation
import SwiftUI

struct StarRatingView: View {
@Binding var rating: Int
@Binding var hoveringOverIndex: Int
@State var isInteractive: Bool = true

var body: some View {
HStack {
ForEach(1..<6) { index in
Image(systemName: "star")
.symbolVariant(hoveringOverIndex >= index ? .fill : .none)
.shadow(color: .secondary, radius: hoveringOverIndex == index ? 10 : 0)
.onHover { hovering in
if isInteractive {
withAnimation {
hoveringOverIndex = hovering ? index : hoveringOverIndex
}
}
}
.onTapGesture {
if isInteractive {
withAnimation {
rating = index
}
}
}
}
}
.onAppear {
withAnimation {
hoveringOverIndex = rating
}
}
.onHover { hovering in
withAnimation {
hoveringOverIndex = hovering ? hoveringOverIndex : rating
}
}
.imageScale(.large)
}
}
101 changes: 101 additions & 0 deletions Mythic/Views/Unified/Sheets/HarmonyRatingView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
//
// HarmonyRatingView.swift
// Mythic
//
// Created by vapidinfinity (esi) on 16/1/2025.
//

import Foundation
import SwiftUI

struct HarmonyRatingView: View {
@Binding var isPresented: Bool
@Binding var game: Game

@State private var rating: Game.Compatibility?
@State private var hoveringOverIndex: Int = 0

@State private var isConfirmationPresented: Bool = false

@State private var isUploading: Bool = false

func uploadCompatibilityData() {
withAnimation { isUploading = true }

// TODO: handle upload w/ UUID of Mythic spam protection and whatnot

// TODO: if success
isPresented = false
}

var body: some View {
VStack {
Text("How well did \"\(game.title)\" run?")
.font(.title)

Text("This will be uploaded to Harmony, Mythic's game compatibility database.")
.foregroundStyle(.placeholder)
}
.padding()
.fixedSize()

StarRatingView(
rating: .init(
get: { rating.flatMap { Game.Compatibility.allCases.firstIndex(of: $0).map { $0 + 1 } } ?? 0 },
set: { rating = Game.Compatibility.allCases[$0 - 1] }
),
hoveringOverIndex: $hoveringOverIndex
)

Form {
if hoveringOverIndex > 0 {
Text(Game.Compatibility.allCases[hoveringOverIndex - 1].rawValue)
} else {
Text("Please choose a rating.")
}
}
.formStyle(.grouped)

HStack {
Button("Cancel", role: .cancel) {
isConfirmationPresented = true
}
.alert(isPresented: $isConfirmationPresented) {
Alert(
title: .init("Are you sure you want to proceed without rating?"),
message: .init("Harmony ratings help every Mythic user understand how well a game runs."),
primaryButton: .cancel(),
secondaryButton: .default(.init("OK")) {
isPresented = false
}
)
}

Spacer()

HStack {
if isUploading {
ProgressView()
.controlSize(.small)
.padding(0.5)
}

Button("Done") {
uploadCompatibilityData()
}
.buttonStyle(.borderedProminent)
.disabled(rating == nil)
}
}
.padding([.horizontal, .bottom])
}
}

#Preview {
Color.clear
.sheet(isPresented: .constant(true)) {
HarmonyRatingView(
isPresented: .constant(true),
game: .constant(.init(source: .epic, title: "poop")))
}
}

0 comments on commit 24028b5

Please sign in to comment.