вторник, 10 сентября 2024 г.

Godot Extension (GDExtension) with Swift language

 

 

 

 

 

 

 

 

 

 

 

Swift 5.10.1 Windows toolchain. (www.swift.org)

1. Run:
>>swift package init
(In folder "C:\my_GD_Extensions\myShip")

Edit file: Package.swift

// swift-tools-version: 5.10
import PackageDescription

let package = Package(
    name: "myShip",
    products: [
        .library(
            name: "myShip",
            type: .dynamic,
            targets: ["myShip"]),
    ],
    dependencies: [
        .package(url: "https://github.com/migueldeicaza/SwiftGodot", branch: "main")
    ],
    targets: [
        .target(
            name: "myShip",
            dependencies: [
                "SwiftGodot",
            ]
        ),
        .testTarget(
            name: "myShipTests",
            dependencies: ["myShip"]
        ),
    ]
)

2. Run and wait):
>>swift build

Edit file: C:\my_GD_Extensions\myShip\Sources\myShip.swift

import SwiftGodot
#initSwiftExtension(cdecl: "swift_entry_point", types: [ShipController.self])

Edit file: C:\my_GD_Extensions\myShip\Sources\ShipController.swift

import SwiftGodot
@Godot(.tool)
class ShipController: Node3D {
    public override func _ready () {
        let meshRender = MeshInstance3D()
        meshRender.mesh = BoxMesh()
        addChild(node: meshRender)
    }

    public override func _process(delta: Double) {
        rotateY(angle: delta * 5)
    }
}

3. Compile and copy files to Godot project
>>swift build

Make file: res://bin/myShip.gdextensions:

[configuration]
entry_symbol = "swift_entry_point"
compatibility_minimum = 4.2

[icons]
ShipController = "res://bin/my_extension.svg"

[libraries]
windows.debug.x86_64 = "res://bin/myShip.dll"

[dependencies]
windows.debug.x86_64 = "res://bin/SwiftGodot.dll"

Attention!

Copy files from "C:\Swift\Runtimes\5.10.1\usr\bin"
to folder with your extension ("res://bin")
(and copy to game Export folder).

Комментариев нет:

Отправить комментарий