Compare commits

...

2 Commits

Author SHA1 Message Date
Shadowfacts 112bca57ce
Fix keyboard input on Mac 2020-04-05 14:57:06 -04:00
Shadowfacts 9de568cb36
Fix ghost piece appearing on top of dropped piece 2020-04-05 14:56:59 -04:00
5 changed files with 28 additions and 40 deletions

View File

@ -16,14 +16,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Create the window and set the content view.
window = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: 634, height: 804),
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
backing: .buffered, defer: false)
window = TetrisWindow()
window.center()
window.setFrameAutosaveName("Main Window")
window.contentViewController = TetrisViewController()
window.title = "Tetris"
window.makeKeyAndOrderFront(nil)
}

View File

@ -13,9 +13,10 @@ import TetrisKit
class TetrisViewController: NSViewController {
let gameController = GameController()
let gameController: GameController
init() {
init(gameController: GameController) {
self.gameController = gameController
super.init(nibName: nil, bundle: nil)
preferredContentSize = NSSize(width: 634, height: 804)
}
@ -25,7 +26,7 @@ class TetrisViewController: NSViewController {
}
override func loadView() {
self.view = TetrisHostingView(gameController)
self.view = NSHostingView(rootView: ContentView(controller: gameController))
}
override func viewDidAppear() {

View File

@ -1,35 +1,28 @@
//
// TetrisHostingView.swift
// TetrisWindow.swift
// Tetris Mac
//
// Created by Shadowfacts on 10/16/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
// Created by Shadowfacts on 4/5/20.
// Copyright © 2020 Shadowfacts. All rights reserved.
//
import Cocoa
import SwiftUI
import Carbon
import TetrisKit
import Carbon
class TetrisHostingView: NSHostingView<ContentView> {
class TetrisWindow: NSWindow {
let gameController: GameController
let gameController = GameController()
override var acceptsFirstResponder: Bool {
return true
}
init() {
super.init(contentRect: NSRect(x: 0, y: 0, width: 634, height: 804),
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
backing: .buffered,
defer: false)
init(_ gameController: GameController) {
self.gameController = gameController
super.init(rootView: ContentView(controller: gameController))
}
required init(rootView: ContentView) {
fatalError("init(rootView:) has not been implemented")
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
setFrameAutosaveName("Main Window")
contentViewController = TetrisViewController(gameController: gameController)
title = "Tetris"
}
override func keyDown(with event: NSEvent) {

View File

@ -60,6 +60,7 @@
D608564723551602005BE4BC /* BoardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D608564523551602005BE4BC /* BoardView.swift */; };
D608564923551BAC005BE4BC /* GridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D608564823551BAC005BE4BC /* GridView.swift */; };
D608564A23551BAC005BE4BC /* GridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D608564823551BAC005BE4BC /* GridView.swift */; };
D640E3E9243A5F15008F9972 /* TetrisWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = D640E3E8243A5F14008F9972 /* TetrisWindow.swift */; };
D6AA0AE6235D273E00D2FFE8 /* GamePieceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6AA0AE4235D272200D2FFE8 /* GamePieceView.swift */; };
D6AA0AE7235D273F00D2FFE8 /* GamePieceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6AA0AE4235D272200D2FFE8 /* GamePieceView.swift */; };
D6AA0AE8235D273F00D2FFE8 /* GamePieceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6AA0AE4235D272200D2FFE8 /* GamePieceView.swift */; };
@ -93,7 +94,6 @@
D6E560722357D65700BF9ACF /* NextTetrominoesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6DC0E9823579A4D008A0A98 /* NextTetrominoesView.swift */; };
D6E560732357D65700BF9ACF /* Tetromino+Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6D84DF323567231002968FB /* Tetromino+Color.swift */; };
D6E560772357DF7D00BF9ACF /* TetrisViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6E560762357DF7D00BF9ACF /* TetrisViewController.swift */; };
D6E560792357E1EC00BF9ACF /* TetrisHostingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6E560782357E1EC00BF9ACF /* TetrisHostingView.swift */; };
D6E5609C2358C50A00BF9ACF /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D6E5609B2358C50A00BF9ACF /* Media.xcassets */; };
D6E5609D2358C50A00BF9ACF /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D6E5609B2358C50A00BF9ACF /* Media.xcassets */; };
D6E5609E2358C50A00BF9ACF /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D6E5609B2358C50A00BF9ACF /* Media.xcassets */; };
@ -305,6 +305,7 @@
D608562F23551269005BE4BC /* TilesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TilesView.swift; sourceTree = "<group>"; };
D608564523551602005BE4BC /* BoardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoardView.swift; sourceTree = "<group>"; };
D608564823551BAC005BE4BC /* GridView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridView.swift; sourceTree = "<group>"; };
D640E3E8243A5F14008F9972 /* TetrisWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TetrisWindow.swift; sourceTree = "<group>"; };
D6AA0AE4235D272200D2FFE8 /* GamePieceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GamePieceView.swift; sourceTree = "<group>"; };
D6D84DF323567231002968FB /* Tetromino+Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Tetromino+Color.swift"; sourceTree = "<group>"; };
D6D84DF72356B8F0002968FB /* TetrominoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TetrominoView.swift; sourceTree = "<group>"; };
@ -321,7 +322,6 @@
D6E560482357D5D300BF9ACF /* TetrisKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TetrisKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D6E560602357D63E00BF9ACF /* TetrisUI.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TetrisUI.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D6E560762357DF7D00BF9ACF /* TetrisViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TetrisViewController.swift; sourceTree = "<group>"; };
D6E560782357E1EC00BF9ACF /* TetrisHostingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TetrisHostingView.swift; sourceTree = "<group>"; };
D6E5609B2358C50A00BF9ACF /* Media.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Media.xcassets; sourceTree = "<group>"; };
D6E5609F2358C68C00BF9ACF /* BundleHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BundleHelper.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -546,8 +546,8 @@
isa = PBXGroup;
children = (
D6E560322357C8AF00BF9ACF /* AppDelegate.swift */,
D640E3E8243A5F14008F9972 /* TetrisWindow.swift */,
D6E560762357DF7D00BF9ACF /* TetrisViewController.swift */,
D6E560782357E1EC00BF9ACF /* TetrisHostingView.swift */,
D6E560342357C8AF00BF9ACF /* ContentView.swift */,
D6E560362357C8B100BF9ACF /* Assets.xcassets */,
D6E5603B2357C8B100BF9ACF /* Main.storyboard */,
@ -1082,9 +1082,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D6E560792357E1EC00BF9ACF /* TetrisHostingView.swift in Sources */,
D6E560352357C8AF00BF9ACF /* ContentView.swift in Sources */,
D6E560332357C8AF00BF9ACF /* AppDelegate.swift in Sources */,
D640E3E9243A5F15008F9972 /* TetrisWindow.swift in Sources */,
D6E560772357DF7D00BF9ACF /* TetrisViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View File

@ -25,12 +25,12 @@ public struct BoardView: View {
ZStack(alignment: .topLeading) {
TilesView(board: self.$board)
if self.currentPiece != nil {
GamePieceView(size: min(geometry.size.width / CGFloat(self.board.width), geometry.size.height / CGFloat(self.board.height)), piece: self.currentPiece!)
}
if self.droppedPiece != nil {
GamePieceView(size: min(geometry.size.width / CGFloat(self.board.width), geometry.size.height / CGFloat(self.board.height)), piece: self.droppedPiece!, color: .gray, border: false)
}
if self.currentPiece != nil {
GamePieceView(size: min(geometry.size.width / CGFloat(self.board.width), geometry.size.height / CGFloat(self.board.height)), piece: self.currentPiece!)
}
}
}
}