Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/full rewrite #1

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf
17 changes: 17 additions & 0 deletions .github/workflows/godot-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: "godot gut test"
on: push

jobs:
execute-gut:
name: Run GUT tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Docker test
uses: croconut/godot-tester@master
with:
version: "3.4"
release_type: "stable"
test-dir: "res://tests"
1 change: 1 addition & 0 deletions .godot/.gdignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

26 changes: 26 additions & 0 deletions .godot/editor/editor_layout.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[docks]

dock_3="Scene,Import"
dock_4="FileSystem"
dock_5="Inspector,Node"
dock_filesystem_split=0
dock_filesystem_display_mode=0
dock_filesystem_file_sort=0
dock_filesystem_file_list_display_mode=1
dock_split_2=0
dock_split_3=0
dock_hsplit_1=0
dock_hsplit_2=105
dock_hsplit_3=-105
dock_hsplit_4=0

[EditorNode]

open_scenes=[]

[ScriptEditor]

open_scripts=[]
open_help=[]
script_split_offset=105
list_split_offset=0
4 changes: 4 additions & 0 deletions .godot/editor/filesystem_cache7
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
102b54792f6b2ef812636a2bdaeb9d34
::res://::1649102512
icon.png::CompressedTexture2D::5224012065250401995::1649102509::1649102513::1::::<><>::
README.md::TextFile::-1::1633027302::0::1::::<><>::
8 changes: 8 additions & 0 deletions .godot/editor/project_metadata.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[editor_metadata]

executable_path="C:/Users/theaz/dev/godot/bin/godot.windows.opt.tools.64.exe"

[debug_options]

run_live_debug=true
run_reload_scripts=true
Empty file.
Binary file not shown.
3 changes: 3 additions & 0 deletions .godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source_md5="87721a0b8405586e9aed05eed415e298"
dest_md5="3c396ec36a47c721f2d866cd4b5d7667"

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .godot/uid_cache.bin
Binary file not shown.
33 changes: 33 additions & 0 deletions .gut_editor_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"background_color": "ff262626",
"config_file": "res://.gutconfig.json",
"dirs": [
"res://tests"
],
"disable_colors": false,
"double_strategy": "partial",
"font_color": "ffcccccc",
"font_name": "Default",
"font_size": 16,
"hide_orphans": false,
"ignore_pause": false,
"include_subdirs": true,
"inner_class": null,
"junit_xml_file": "",
"junit_xml_timestamp": false,
"log_level": 1,
"opacity": 100,
"post_run_script": "",
"pre_run_script": "",
"prefix": "test_",
"selected": null,
"should_exit": false,
"should_exit_on_success": true,
"should_maximize": true,
"show_help": false,
"suffix": ".gd",
"tests": [

],
"unit_test_name": null
}
231 changes: 231 additions & 0 deletions addons/advanced-expression/advanced_expression.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
extends Reference

class AbstractCode:
var _cache := []

func _to_string() -> String:
return "%s\n%s" % [_get_name(), output()]

func _get_name() -> String:
return "AbstractCode"

static func _build_string(list: Array) -> String:
return PoolStringArray(list).join("")

func tab(times: int = 1) -> AbstractCode:
for i in times:
_cache.append("\t")
return self

func newline() -> AbstractCode:
_cache.append("\n")
return self

func add(text) -> AbstractCode:
match typeof(text):
TYPE_STRING:
tab()
_cache.append(text)
newline()
TYPE_ARRAY:
_cache.append_array(text)
_:
push_error("Invalid type for add: %s" % str(text))

return self

func clear_cache() -> AbstractCode:
_cache.clear()
return self

#endregion

#region Finish

func output() -> String:
return _build_string(_cache)

func raw_data() -> Array:
return _cache

#region

class Variable extends AbstractCode:
func _init(var_name: String, var_value: String = "") -> void:
_cache.append("var %s = " % var_name)
if not var_value.empty():
_cache.append(var_value)

func _get_name() -> String:
return "Variable"

func add(text) -> AbstractCode:
_cache.append(str(text))

return self

func output() -> String:
return "%s\n" % .output()

class AbstractFunction extends AbstractCode:
var _function_def := ""
var _params := []

func _get_name() -> String:
return "AbstractFunction"

func _construct_params() -> String:
var params := []
params.append("(")

for i in _params:
params.append(i)
params.append(",")

# Remove the last comma
if params.size() > 1:
params.pop_back()

params.append(")")

return PoolStringArray(params).join("") if not params.empty() else ""

func add_param(text: String) -> AbstractFunction:
if _params.has(text):
push_error("Tried to add duplicate param %s" % text)
else:
_params.append(text)

return self

func output() -> String:
var params = _construct_params()
var the_rest = _build_string(_cache)
return "%s%s" % [_function_def % _construct_params(), _build_string(_cache)]

class Function extends AbstractFunction:
func _init(text: String) -> void:
_function_def = "func %s%s:" % [text, "%s"]
# Always add a newline into the cache
newline()

func _get_name() -> String:
return "Function"

class Runner extends AbstractFunction:
func _init() -> void:
_function_def = "func %s%s:" % [RUN_FUNC, "%s"]
# Always add a newline into the cache
newline()

func _get_name() -> String:
return "Runner"

const RUN_FUNC := "__runner__"

var variables := []
var functions := []
var runner := Runner.new()

var gdscript: GDScript

###############################################################################
# Builtin functions #
###############################################################################

func _to_string() -> String:
return _build_source(variables, functions, runner)

###############################################################################
# Connections #
###############################################################################

###############################################################################
# Private functions #
###############################################################################

static func _build_source(v: Array, f: Array, r: Runner) -> String:
var source := ""

for i in v:
source += i.output()

for i in f:
source += i.output()

source += r.output()

return source

static func _create_script(v: Array, f: Array, r: Runner) -> GDScript:
var s := GDScript.new()

var source := ""

for i in v:
source += i.output()

for i in f:
source += i.output()

source += r.output()

s.source_code = source

return s

###############################################################################
# Public functions #
###############################################################################

func add_variable(variable_name: String, variable_value: String = "") -> Variable:
var variable := Variable.new(variable_name, variable_value)

variables.append(variable)

return variable

func add_function(function_name: String) -> Function:
var function := Function.new(function_name)

functions.append(function)

return function

func add(text: String = "") -> Runner:
if not text.empty():
runner.add(text)

return runner

func add_raw(text: String) -> Runner:
var split := text.split(";")
for i in split:
runner.add(i)

return runner

func tab(amount: int = 1) -> Runner:
runner.tab(amount)

return runner

func newline() -> Runner:
runner.newline()

return runner

func compile() -> int:
gdscript = _create_script(variables, functions, runner)

return gdscript.reload()

func execute(params: Array = []):
return gdscript.new().callv(RUN_FUNC, params)

func clear() -> void:
gdscript = null

variables.clear()
functions.clear()
runner = Runner.new()
Loading