Skip to content
This repository was archived by the owner on Aug 27, 2023. It is now read-only.

Commit 772ad3d

Browse files
committed
Core 0.9.1 upgrade
- Solar2D plugin - Lua plugin upgraded to core 0.9.1 api - Lua plugin made to avoid symbol collisions with Solar2D Plugin - Bug fixes
1 parent e0edbd5 commit 772ad3d

8 files changed

Lines changed: 170 additions & 29 deletions

File tree

src/Core/plugin_manifest.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
-- For more information on plugin_manifest.lua, see:
33
-- https://docs.appmakerios.com/#/plugin-manifest
44
--
5-
local appMakerCoreVersion = "0.9.0"
5+
local appMakerCoreVersion = "0.9.1"
66

77
local function getXCFrameworkURL(filename)
88
local repoOwner = "App-Maker-Software"

src/Lua/Sources/Lua.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ final class LuaBuildSystem: AppMakerBuildSystemImplementation {
169169

170170
let entryPath: RawProjectFilePath
171171

172-
init(entryPath: RawProjectFilePath) {
172+
init(entryPath: RawProjectFilePath, projectRootFolderUrl: URL) {
173173
self.entryPath = entryPath
174174
}
175175

@@ -185,6 +185,10 @@ final class LuaBuildSystem: AppMakerBuildSystemImplementation {
185185
]
186186
}
187187

188+
func doBuild(for product: AnyBuildProduct) async -> Result<Void, Error> {
189+
fatalError()
190+
}
191+
188192

189193
#if DEBUG
190194
var isDestroyed = false

src/Lua/Sources/LuaScriptRunner.swift

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ import AppMakerCompanionCore
1111
#endif
1212

1313
final class LuaScriptRunner: AppMakerBuildProductRunnerImplementation {
14+
var canRender: Bool { false }
15+
1416
let logger: RunnerLogger
15-
let buildProduct: SimpleOfflineBuildProduct
17+
let _buildProduct: SimpleOfflineBuildProduct
18+
var buildProduct: AnyBuildProduct {
19+
self._buildProduct
20+
}
1621
var vm: LuaSwiftBindings.VirtualMachine?
1722
let sendAction: (BuildProductRunnerAction) -> Void
18-
init(
19-
logger: RunnerLogger,
20-
buildProduct: SimpleOfflineBuildProduct,
21-
sendAction: @escaping (BuildProductRunnerAction) -> Void
22-
) {
23+
init(logger: RunnerLogger, buildProduct: AnyBuildProduct, sendAction: @escaping (BuildProductRunnerAction) -> Void) {
2324
self.logger = logger
24-
self.buildProduct = buildProduct
25+
self._buildProduct = buildProduct as! SimpleOfflineBuildProduct
2526
self.sendAction = sendAction
2627
}
2728
private func log(_ msg: String, addNewLine: Bool = true) {
@@ -52,8 +53,8 @@ final class LuaScriptRunner: AppMakerBuildProductRunnerImplementation {
5253
}
5354
vm.globals["sandbox"] = sandboxTable
5455
// save user code path
55-
let executionURL: URL = buildProduct.buildProductPath.deletingLastPathComponent()
56-
vm.globals["entryFileName"] = buildProduct.buildProductPath.lastPathComponent
56+
let executionURL: URL = _buildProduct.buildProductPath.deletingLastPathComponent()
57+
vm.globals["entryFileName"] = _buildProduct.buildProductPath.lastPathComponent
5758
vm.globals["getSandboxedUrl"] = vm.createUncheckedFunction { [weak self] args in
5859
if let self = self {
5960
if let fileName: String = args.first as? String {
@@ -67,7 +68,7 @@ final class LuaScriptRunner: AppMakerBuildProductRunnerImplementation {
6768
}
6869
return .nothing
6970
}
70-
self.log("Running \(buildProduct.buildProductPath.lastPathComponent)")
71+
self.log("Running \(_buildProduct.buildProductPath.lastPathComponent)")
7172
let evalResult = vm.eval(#"""
7273
local amDoFile
7374
local env = {

src/Lua/plugin_manifest.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ manifest =
4343
{
4444
name = "LuaSwiftBindings",
4545
productName = "LuaSwiftBindings",
46-
exactVersion = "5.4.4",
46+
revision = "60a5ad37c0ddd7a3521be0f6b1ab5b2387e7f802", -- Lua 5.4.4 with suffixed exported symbols to avoid collisions with CoronaCard's embedded Lua interpreter.
4747
url = "https://github.com/App-Maker-Software/LuaSwiftBindings.git",
4848
},
4949
},
5050
},
51-
}
51+
}

src/Solar2D/Sources/Solar2D.swift

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import AppMakerCompanionCore
1111
import SwiftUI
1212

1313
func solar2d_main() {
14+
1415
// Install sandbox and runner
1516
solar2DRunner.licenseInformation = [
1617
"Solar2D (c) Solar2D, MIT license" // https://github.com/coronalabs/corona/
@@ -54,7 +55,7 @@ func solar2d_main() {
5455
return aFileOrFolder.lastPathComponent.lowercased() == "main.lua"
5556
}
5657
},
57-
priority: 1,
58+
priority: 2,
5859
projectFileViewersSupports: ["Project Files"]
5960
)
6061
try! solar2DProjectType.install()
@@ -78,10 +79,10 @@ func solar2d_main() {
7879
relativeFolderPath: "",
7980
fileName: "main.lua",
8081
contents: """
81-
//
82-
// main.lua
83-
// PROJECT_NAME
84-
//
82+
--
83+
-- main.lua
84+
-- PROJECT_NAME
85+
--
8586
8687
local myText = display.newText( "Hello World from PROJECT_NAME!", 100, 200, native.systemFont, 16 )
8788
myText:setFillColor( 1, 0, 0 )
@@ -120,24 +121,43 @@ private let solar2DRunner: AppMakerBuildProductRunner = AppMakerBuildProductRunn
120121
final class Solar2DBuildSystem: AppMakerBuildSystemImplementation {
121122

122123
let entryPath: RawProjectFilePath
124+
let entryPathUrl: URL
123125

124-
init(entryPath: RawProjectFilePath) {
126+
init(entryPath: RawProjectFilePath, projectRootFolderUrl: URL) {
125127
self.entryPath = entryPath
128+
self.entryPathUrl = entryPath.asLocalURL(withStartingUrl: projectRootFolderUrl)!
126129
}
127130

128131
func buildProductsOnStartup() -> [(buildProductCreator: BuildProductCreator, recommendedRunnerName: String?)] {
129132
return [
130133
(
131-
buildProductCreator: .simpleOfflineBuildProduct(
132-
name: "main",
133-
path: entryPath
134+
buildProductCreator: .generatedHiddenFolderOfflineBuildProduct(
135+
name: "main"
134136
),
135137
recommendedRunnerName: solar2dScriptRunnerName
136138
)
137139
]
138140
}
139141

140142

143+
144+
func doBuild(for product: AnyBuildProduct) async -> Result<Void, Error> {
145+
let product = product as! GeneratedHiddenFolderOfflineBuildProduct
146+
try? FileManager.default.removeItem(at: product.buildProductPath)
147+
let coronaSourceFolder = self.entryPathUrl.deletingLastPathComponent()
148+
try? FileManager.default.createDirectory(at: product.buildProductPath.deletingLastPathComponent(), withIntermediateDirectories: true)
149+
do {
150+
try FileManager.default.copyItem(
151+
at: coronaSourceFolder,
152+
to: product.buildProductPath
153+
)
154+
return .success(Void())
155+
} catch {
156+
return .failure(error)
157+
}
158+
}
159+
160+
141161
#if DEBUG
142162
var isDestroyed = false
143163
#endif

src/Solar2D/Sources/Solar2DRunner.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,23 @@ import AppMakerCore
88
#elseif COMPANION
99
import AppMakerCompanionCore
1010
#endif
11+
import SwiftUI
1112

1213
final class Solar2DRunner: AppMakerBuildProductRunnerImplementation {
1314
let logger: RunnerLogger
14-
let buildProduct: SimpleOfflineBuildProduct
15+
let _buildProduct: GeneratedHiddenFolderOfflineBuildProduct
16+
var buildProduct: AnyBuildProduct { _buildProduct }
1517
let sendAction: (BuildProductRunnerAction) -> Void
18+
var canRender: Bool {
19+
true
20+
}
1621
init(
1722
logger: RunnerLogger,
18-
buildProduct: SimpleOfflineBuildProduct,
23+
buildProduct: AnyBuildProduct,
1924
sendAction: @escaping (BuildProductRunnerAction) -> Void
2025
) {
2126
self.logger = logger
22-
self.buildProduct = buildProduct
27+
self._buildProduct = buildProduct as! GeneratedHiddenFolderOfflineBuildProduct
2328
self.sendAction = sendAction
2429
}
2530
private func log(_ msg: String, addNewLine: Bool = true) {
@@ -30,7 +35,11 @@ final class Solar2DRunner: AppMakerBuildProductRunnerImplementation {
3035
}
3136
}
3237
func resume() {
33-
self.sendAction(.finished(success: true))
38+
self.sendAction(.render(AnyView(
39+
SafeSolar2DSwiftUIView(
40+
coronaSdkFilePath: self._buildProduct.buildProductPath.path
41+
)
42+
)))
3443
}
3544
func suspend() {
3645

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
//
2+
// Solar2DSwiftUIView.swift
3+
//
4+
5+
import Foundation
6+
import SwiftUI
7+
8+
9+
struct SafeSolar2DSwiftUIView: View {
10+
let coronaSdkFilePath: String
11+
init(coronaSdkFilePath: String) {
12+
self.coronaSdkFilePath = coronaSdkFilePath
13+
}
14+
15+
var body: some View {
16+
Solar2DSwiftUIViewBody(delegate: Solar2DSwiftUIViewDelegate(
17+
coronaSdkFilePath: coronaSdkFilePath
18+
))
19+
}
20+
}
21+
22+
fileprivate struct Solar2DSwiftUIViewBody: View {
23+
@ObservedObject var delegate: Solar2DSwiftUIViewDelegate
24+
25+
init(delegate: Solar2DSwiftUIViewDelegate) {
26+
self._delegate = .init(wrappedValue: delegate)
27+
}
28+
29+
var body: some View {
30+
GeometryReader { geo in
31+
delegate.view.onChange(of: geo.size) { (newSize: CGSize) in
32+
delegate.width = newSize.width
33+
delegate.height = newSize.height
34+
}.onAppear {
35+
delegate.width = geo.size.width
36+
delegate.height = geo.size.height
37+
}
38+
}
39+
}
40+
}
41+
fileprivate final class Solar2DSwiftUIViewDelegate: NSObject, ObservableObject, CoronaViewDelegate {
42+
let id = UUID().uuidString
43+
func coronaViewDidResume(_ view: CoronaView!) {}
44+
func coronaViewWillSuspend(_ view: CoronaView!) {}
45+
func coronaView(_ view: CoronaView!, receiveEvent event: [AnyHashable : Any]!) -> Any! {
46+
return true
47+
}
48+
49+
let coronaSdkFilePath: String
50+
@Published private var isRunning = true
51+
@Published var width: CGFloat = 200
52+
@Published var height: CGFloat = 200
53+
54+
init(coronaSdkFilePath: String) {
55+
self.coronaSdkFilePath = coronaSdkFilePath
56+
}
57+
58+
59+
func start() {
60+
guard !isRunning else { return }
61+
isRunning = true
62+
}
63+
func kill() {
64+
guard isRunning else { return }
65+
isRunning = false
66+
}
67+
68+
var view: LiveSolar2DView {
69+
.init(delegate: self)
70+
}
71+
72+
struct LiveSolar2DView: View {
73+
@ObservedObject fileprivate var delegate: Solar2DSwiftUIViewDelegate
74+
75+
var body: some View {
76+
if delegate.isRunning {
77+
Solar2DSwiftUIView(delegate: delegate)
78+
.frame(width: delegate.width, height: delegate.height)
79+
.animation(nil, value: delegate.width)
80+
.animation(nil, value: delegate.height)
81+
}
82+
}
83+
}
84+
}
85+
86+
87+
fileprivate struct Solar2DSwiftUIView: UIViewControllerRepresentable {
88+
let delegate: Solar2DSwiftUIViewDelegate
89+
func makeUIViewController(context: Context) -> CoronaViewController {
90+
let coronaController = CoronaViewController()
91+
let coronaView = (coronaController.view as! CoronaView)
92+
coronaView.backgroundColor = .clear
93+
coronaView.isOpaque = false
94+
// coronaView.frame = .init(x: 0, y: 0, width: sW, height: sH)
95+
coronaView.coronaViewDelegate = delegate
96+
coronaView.run(withPath: delegate.coronaSdkFilePath, parameters: [
97+
:
98+
// "contentWidth":sW,
99+
// "contentHeight":sH
100+
])
101+
102+
return coronaController
103+
}
104+
105+
func updateUIViewController(_ uiViewController: CoronaViewController, context: Context) {}
106+
107+
typealias UIViewControllerType = CoronaViewController
108+
}

src/Solar2D/plugin_manifest.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ manifest =
6060
dependencies = {},
6161
supportedTargets = {
6262
"iOS",
63-
"iOSSim",
6463
},
6564
supportedRuntimes = {
6665
"mainApp",
@@ -182,4 +181,4 @@ manifest =
182181
--
183182
bridgingHeaderImport = "\"CoronaCards/CoronaCards.h\"",
184183
},
185-
}
184+
}

0 commit comments

Comments
 (0)