Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
EstevanBR committed Jul 16, 2024
1 parent 892ea38 commit 599ad29
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,104 @@ $ swift run CreateProject
```

and follow the prompts.

For example.

When it asks which directory, this is the directory that your project folder will be created in, so it's asking for the parent directory of your project. I may change this later. for example `swift package init` will put the `Package.swift` file in the current working directory, this tool will create a folder first.

### Example output
```shell
$ swift run
Building for debugging...

Please enter where you would like the project directory to be created: ../
Please enter the name of the project: MySwiftGodotKickProject
Created /home/user/Documents/Code/MySwiftGodotKickProject/Package.swift
Created /home/user/Documents/Code/MySwiftGodotKickProject/README.md
Created /home/user/Documents/Code/MySwiftGodotKickProject/.gitignore
Created /home/user/Documents/Code/MySwiftGodotKickProject/.env
Created /home/user/Documents/Code/MySwiftGodotKickProject/Sources
Created /home/user/Documents/Code/MySwiftGodotKickProject/Sources/MySwiftGodotKickProject/MySwiftGodotKickProject.swift
Created /home/user/Documents/Code/MySwiftGodotKickProject/Sources/MySwiftGodotKickProjectGame/main.swift
Created /home/user/Documents/Code/MySwiftGodotKickProject/GDD.md
Created /home/user/Documents/Code/MySwiftGodotKickProject/godot
Created /home/user/Documents/Code/MySwiftGodotKickProject/godot/project.godot
Created /home/user/Documents/Code/MySwiftGodotKickProject/godot/MySwiftGodotKickProject.gdextension
Created /home/user/Documents/Code/MySwiftGodotKickProject/godot/export_presets.cfg
Created /home/user/Documents/Code/MySwiftGodotKickProject/Makefile
run the following command:

cd /home/user/Documents/Code/MySwiftGodotKickProject && make all
```

This will create a project with this structure:
```
├── .env
├── GDD.md
├── godot
│ ├── bin
│ │ └── .gdignore
│ ├── export_presets.cfg
│ ├── exports
│ │ └── .gdignore
│ ├── .gitignore
│ ├── icon.svg
│ ├── MySwiftGodotKickProject.gdextension
│ └── project.godot
├── Makefile
├── Package.resolved
├── Package.swift
├── README.md
└── Sources
├── MySwiftGodotKickProject
│ └── MySwiftGodotKickProject.swift
└── MySwiftGodotKickProjectGame
├── main.swift
└── Resources
└── MySwiftGodotKickProject.pck
```

### Using resources:
As long as we import all our resources into Godot, we can reference them in `Swift` using the same `res://` paths as you would in `GDScript` by exporting the Resource .pck file, and passing it to Godot when we start the project using `SwiftGodotKit`.

The `godot/export_presets.cfg` file is used by `make pack` to create the `Sources/MySwiftGodotKickProjectGame/Resources/MySwiftGodotKickProject.pck` resource pack.

This allows both `.gdscript` and swift code to access `icon.svg` by using `res://icon.svg` (check out `main.swift`).

By putting the `MySwiftGodotKickProject.pck` resource file in the `Resources/` folder of the Swift Package target, and declaring that Resource as a resource in the Package.swift manifest like so:
```swift
let package = Package(
...
targets: [
.executableTarget(
name: "MySwiftGodotKickProjectGame",
dependencies: [
"MySwiftGodotKickProject",
.product(name: "SwiftGodotKit", package: "SwiftGodotKit")
],
resources: [
.copy("Resources") // <-- here, MySwiftGodotKickProject.pck lives in this folder
]),
```
We are able to access the resource pack, and pass it to `runGodot`:
```swift
// Sources/MySwiftGodotKickProjectGame/main.swift

let packPath = Bundle.module.path(forResource: "MySwiftGodotKickProject", ofType: "pck")! // <-- here

runGodot(
args: [
"--main-pack", packPath // <-- and here
],
initHook: registerTypes,
loadScene: loadScene,
loadProjectSettings: { settings in }
)
```

So we can do something like this:
```swift
// Icon2D.swift

let image = GD.load(path: "res://icon.svg") as! Texture2D
```

0 comments on commit 599ad29

Please sign in to comment.