iOS 1.1.0 - Drag and Drop

This commit is contained in:
2025-12-08 11:55:58 -07:00
parent 88be16c0c6
commit de05681425
4 changed files with 39 additions and 5 deletions

View File

@@ -411,7 +411,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
@@ -426,7 +426,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.0;
MARKETING_VERSION = 1.1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.atridad.MagicCounter;
PRODUCT_NAME = "$(TARGET_NAME)";
STRING_CATALOG_GENERATE_SYMBOLS = YES;
@@ -446,7 +446,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
@@ -461,7 +461,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.0;
MARKETING_VERSION = 1.1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.atridad.MagicCounter;
PRODUCT_NAME = "$(TARGET_NAME)";
STRING_CATALOG_GENERATE_SYMBOLS = YES;

View File

@@ -6,6 +6,7 @@
//
import SwiftUI
import UniformTypeIdentifiers
/**
* Main game screen displaying the grid of players.
@@ -17,6 +18,7 @@ struct GameView: View {
@State private var gameState: GameState
@State private var showingStopConfirmation = false
@State private var selectedPlayerForCommander: PlayerState?
@State private var draggedPlayer: PlayerState?
init(match: MatchRecord) {
self._gameState = State(initialValue: match.state)
@@ -97,6 +99,11 @@ struct GameView: View {
onScoop: { scoopPlayer(player) }
)
.frame(height: 260)
.onDrag {
self.draggedPlayer = player
return NSItemProvider(object: String(player.id) as NSString)
}
.onDrop(of: [.text], delegate: PlayerDropDelegate(item: player, items: $gameState.players, draggedItem: $draggedPlayer))
}
}
.padding(24)
@@ -357,3 +364,30 @@ struct CommanderDamageView: View {
}
}
}
struct PlayerDropDelegate: DropDelegate {
let item: PlayerState
@Binding var items: [PlayerState]
@Binding var draggedItem: PlayerState?
func performDrop(info: DropInfo) -> Bool {
return true
}
func dropEntered(info: DropInfo) {
guard let draggedItem = draggedItem else { return }
if draggedItem.id != item.id {
if let from = items.firstIndex(where: { $0.id == draggedItem.id }),
let to = items.firstIndex(where: { $0.id == item.id }) {
withAnimation {
let movedItem = items.remove(at: from)
items.insert(movedItem, at: to)
}
}
}
}
func dropUpdated(info: DropInfo) -> DropProposal? {
return DropProposal(operation: .move)
}
}

View File

@@ -8,7 +8,7 @@
"layers" : [
{
"image-name" : "logo 2.png",
"name" : "logo 2",
"name" : "logo",
"position" : {
"scale" : 0.85,
"translation-in-points" : [