Skip to content

Commit

Permalink
Add custom icon to the Example class
Browse files Browse the repository at this point in the history
Fixes #58
  • Loading branch information
asmaloney committed Dec 28, 2023
1 parent 5ee9b33 commit b929b29
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
16 changes: 15 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ if( NOT DEFINED CMAKE_DEBUG_POSTFIX )
)
endif()

# Copy over additional files from the support_files directory
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_SOURCE_DIR}/support_files"
${BUILD_OUTPUT_DIR}
)

# Warnings
include( CompilerWarnings )

Expand All @@ -82,7 +90,7 @@ include( GitVersionInfo )

add_subdirectory( src )

# Install library and extension file in ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}
# Install library, extension file, and support files in ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}
set( INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/" )

message( STATUS "Install directory: ${INSTALL_DIR}")
Expand All @@ -94,6 +102,12 @@ install( TARGETS ${PROJECT_NAME}
DESTINATION ${INSTALL_DIR}/${LIB_DIR}
)

# Copy over support files
install( DIRECTORY "${CMAKE_SOURCE_DIR}/support_files/"
DESTINATION ${INSTALL_DIR}
PATTERN ".*" EXCLUDE
)

add_subdirectory( templates )

# ccache
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ This template project sets up a lot of the build details so you can get started

- includes **[godot-cpp](https://github.com/godotengine/godot-cpp) as a submodule** and links it statically to your shared library
- creates `<project>.gdextension` files based on your project name
- copies over any support files from the `support_files` directory into your extension directory
- includes example of adding custom icons to your classes/nodes ([see below](#custom-node-icons))
- automatically generates a _**Version.h**_ header file which:
- includes a preprocessor macro for conditional compilation
```cpp
Expand Down Expand Up @@ -73,6 +75,7 @@ To use this for your own project:
> **Note:** If you change the entry symbol (`GDExtensionInit`) in _RegisterExtension.cpp_, you will need to update your `templates/*.gdextension.in` files.
- replace `CHANGELOG.md` with your own (I would encourage adhering to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and the use of [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) )
- replace this `README.md` with your own
- replace custom node icon ([see below](#custom-node-icons))

Optional:

Expand All @@ -84,6 +87,22 @@ Optional:
- change the compiler warnings you want to enforce (see [CompilerWarnings.cmake](cmake/CompilerWarnings.cmake))
- change the LICENSE

### Custom Node Icons

I have included a custom icon for the `Example` node (icon is [CC0](https://creativecommons.org/public-domain/cc0/) from [SVGRepo](https://www.svgrepo.com/svg/207485/gardening-autumn)), so you will want to remove or modify it for your own classes/nodes.

The icon itself is in `support_files/icons` it is referenced in the `templates/*.gdextension.in` files.

To add an icon for your custom node:

- add the icon file to `support_files/icons` and name it after your node (e.g. `MyNode.svg`)
- in each of the `templates/*.gdextension.in` files add an entry for your node in the `[icons]` section:
```
MyNode = "icons/MyNode.svg"
```

Everything in the `support_files` directory is copied into your extension, so if you don't want to use icons, remove that directory and remove the `[icons]` section from the `templates/*.gdextension.in` files.

### Build & Install

Here's an example of how to build & install a release version (use the terminal to run the following commands in the parent directory of this repo):
Expand Down
1 change: 1 addition & 0 deletions support_files/icons/Example.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions templates/template.debug.gdextension.in
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[configuration]

entry_symbol = "GDExtensionInit"
compatibility_minimum = 4.1

[libraries]
[icons]
Example = "icons/Example.svg"

[libraries]
linux.debug.x86_64 = "lib/Linux-x86_64/lib${PROJECT_NAME}-d.so"
macos.debug = "lib/Darwin-Universal/lib${PROJECT_NAME}-d.dylib"
windows.debug.x86_64 = "lib/Windows-AMD64/${LIB_PREFIX}${PROJECT_NAME}-d.dll"
5 changes: 3 additions & 2 deletions templates/template.release.gdextension.in
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[configuration]

entry_symbol = "GDExtensionInit"
compatibility_minimum = 4.1

[libraries]
[icons]
Example = "icons/Example.svg"

[libraries]
linux.release.x86_64 = "lib/Linux-x86_64/lib${PROJECT_NAME}.so"
macos.release = "lib/Darwin-universal/lib${PROJECT_NAME}.dylib"
windows.release.x86_64 = "lib/Windows-AMD64/${LIB_PREFIX}${PROJECT_NAME}.dll"

0 comments on commit b929b29

Please sign in to comment.