Skip to content

Commit

Permalink
ref: decouple callback to an npm-compatible package and add some simp…
Browse files Browse the repository at this point in the history
…le tests
  • Loading branch information
quentincaffeino committed Nov 13, 2022
1 parent 32932f9 commit 9d1f9d1
Show file tree
Hide file tree
Showing 28 changed files with 610 additions and 259 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,4 @@ $RECYCLE.BIN/
addons/*
addons/**/addons
!addons/quentincaffeino/
!addons/@quentincaffeino/
228 changes: 228 additions & 0 deletions addons/@quentincaffeino/godot-callback/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@

# Created by https://www.toptal.com/developers/gitignore/api/osx,linux,windows,godot,node
# Edit at https://www.toptal.com/developers/gitignore?templates=osx,linux,windows,godot,node

### Godot ###
# Godot-specific ignores
.import/
export.cfg
export_presets.cfg

# Imported translations (automatically generated from CSV files)
*.translation

# Mono-specific ignores
.mono/
data_*/

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

### Node Patch ###
# Serverless Webpack directories
.webpack/

# Optional stylelint cache

# SvelteKit build / generate output
.svelte-kit

### OSX ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/osx,linux,windows,godot,node
10 changes: 10 additions & 0 deletions addons/@quentincaffeino/godot-callback/.gutconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"dirs": [
"res://addons/@quentincaffeino/godot-callback/tests/"
],
"include_subdirs": true,
"ignore_pause": true,
"log_level": 2,
"should_exit": true,
"should_maximize": true
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The MIT License (MIT)

Copyright (c) 2019 - Sergei Zhuravlev
Copyright (c) 2022 - Sergei Zhuravlev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# godot-callback

Wrapper class to allow easy passing a reference to classes parameters/methods.
Wrapper class to allow easy passing a reference to class members.

Compatible with funcref. Funcref only works with functions so this pacakge is still usefull.

## Examples:

```gdscript
const CallbackBuilder = preload('res://addons/quentincaffeino/callback/src/CallbackBuilder.gd')
const CallbackBuilder = preload('res://addons/@quentincaffeino/godot-callback/src/CallbackBuilder.gd')
# @var Value
Expand All @@ -24,10 +26,10 @@ func _ready(): # void
print(prop_cb.call()) # Prints: Hello world!
print(func_cb.call(["Hello, sam!"])) # Prints: [Reference...]
func_cb.call(["Hello, sam!"])
print(prop_cb.call()) # Prints: Hello, sam!
print(funcref_cb.call(["Hello, peter!"])) # Prints: [Reference...]
funcref_cb.call(["Hello, peter!"])
print(prop_cb.call()) # Prints: Hello, peter!
```

Expand Down
15 changes: 15 additions & 0 deletions addons/@quentincaffeino/godot-callback/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@quentincaffeino/godot-callback",
"version": "0.1.0",
"description": "Wrapper class to allow easy passing a reference to class members.",
"scripts": {
"test": "godot --no-window -s addons/gut/gut_cmdln.gd -d --path ../../../demo/ -gconfig=res://addons/@quentincaffeino/godot-callback/.gutconfig.json"
},
"keywords": [
"godot",
"godot-engine",
"godot-engine-addon"
],
"author": "quentincaffeino <sergey95zu@gmail.com>",
"license": "MIT"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
extends Reference

const Utils = preload("./Utils.gd")
const errors = preload("../assets/translations/errors.en.gd").messages
const errors = preload("./messages.gd").errors


# @var Reference
Expand Down Expand Up @@ -33,23 +33,22 @@ func get_type():
return self._type


# @param Variant[] argv
# @returns self
func bind(argv = []):
assert(false, "Method not implemented")


# Ensure callback target exists
# @returns boolean
func ensure():
pass
assert(false, "Method not implemented")


# @param Variant[] argv
# @returns void
func bind(argv = []):
for _argv in argv:
self._bind_argv.append(_argv)


# @param Variant[] argv
# @param Variant[] argv
# @returns Variant
func call(argv = []):
pass
assert(false, "Method not implemented")


# @param Variant[] argv
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

extends Reference

const errors = preload("./messages.gd").errors


# @var Reference
var _target


# @param Reference target
func _init(target):
self._target = target


# @returns Reference
func get_target():
return self._target
Loading

0 comments on commit 9d1f9d1

Please sign in to comment.