Compare commits
No commits in common. "112bca57ce1de6d98d90751e6fc10d1c0d122ea3" and "907d92b3b8348d663beac07b12c81802d08861e3" have entirely different histories.
112bca57ce
...
907d92b3b8
|
@ -16,8 +16,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
|
||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||
// Create the window and set the content view.
|
||||
window = TetrisWindow()
|
||||
window = NSWindow(
|
||||
contentRect: NSRect(x: 0, y: 0, width: 634, height: 804),
|
||||
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
|
||||
backing: .buffered, defer: false)
|
||||
window.center()
|
||||
window.setFrameAutosaveName("Main Window")
|
||||
window.contentViewController = TetrisViewController()
|
||||
window.title = "Tetris"
|
||||
window.makeKeyAndOrderFront(nil)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,28 +1,35 @@
|
|||
//
|
||||
// TetrisWindow.swift
|
||||
// TetrisHostingView.swift
|
||||
// Tetris Mac
|
||||
//
|
||||
// Created by Shadowfacts on 4/5/20.
|
||||
// Copyright © 2020 Shadowfacts. All rights reserved.
|
||||
// Created by Shadowfacts on 10/16/19.
|
||||
// Copyright © 2019 Shadowfacts. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
import TetrisKit
|
||||
import SwiftUI
|
||||
import Carbon
|
||||
import TetrisKit
|
||||
|
||||
class TetrisWindow: NSWindow {
|
||||
class TetrisHostingView: NSHostingView<ContentView> {
|
||||
|
||||
let gameController = GameController()
|
||||
let gameController: GameController
|
||||
|
||||
init() {
|
||||
super.init(contentRect: NSRect(x: 0, y: 0, width: 634, height: 804),
|
||||
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
|
||||
backing: .buffered,
|
||||
defer: false)
|
||||
override var acceptsFirstResponder: Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
setFrameAutosaveName("Main Window")
|
||||
contentViewController = TetrisViewController(gameController: gameController)
|
||||
title = "Tetris"
|
||||
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")
|
||||
}
|
||||
|
||||
override func keyDown(with event: NSEvent) {
|
|
@ -13,10 +13,9 @@ import TetrisKit
|
|||
|
||||
class TetrisViewController: NSViewController {
|
||||
|
||||
let gameController: GameController
|
||||
let gameController = GameController()
|
||||
|
||||
init(gameController: GameController) {
|
||||
self.gameController = gameController
|
||||
init() {
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
preferredContentSize = NSSize(width: 634, height: 804)
|
||||
}
|
||||
|
@ -26,7 +25,7 @@ class TetrisViewController: NSViewController {
|
|||
}
|
||||
|
||||
override func loadView() {
|
||||
self.view = NSHostingView(rootView: ContentView(controller: gameController))
|
||||
self.view = TetrisHostingView(gameController)
|
||||
}
|
||||
|
||||
override func viewDidAppear() {
|
||||
|
|
|
@ -60,7 +60,6 @@
|
|||
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 */; };
|
||||
|
@ -94,6 +93,7 @@
|
|||
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,7 +305,6 @@
|
|||
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>"; };
|
||||
|
@ -322,6 +321,7 @@
|
|||
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;
|
||||
|
|
|
@ -25,12 +25,12 @@ public struct BoardView: View {
|
|||
ZStack(alignment: .topLeading) {
|
||||
TilesView(board: self.$board)
|
||||
|
||||
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!)
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue