Skip to content
Merged
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: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ permissions:
contents: read

env:
GODOT_VERSION: "4.6"
GODOT_VERSION: "4.7"

jobs:
ci:
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![CI](https://github.com/JavierIslas/Card-Combat-System/actions/workflows/ci.yml/badge.svg)](https://github.com/JavierIslas/Card-Combat-System/actions/workflows/ci.yml)

A turn-based **card combat engine** for Godot 4.6 / GDScript. It handles the
A turn-based **card combat engine** for Godot 4.7 / GDScript. It handles the
*logic* of a card battle — turn FSM, mana, draw, attack/defense/block, damage
resolution and pluggable AI — and stays **completely domain-agnostic**: it knows
nothing about your GDD, rarities, abilities or loaders. Everything
Expand Down Expand Up @@ -77,22 +77,24 @@ pattern live in the addon README:

## Testing

Tests run under [GUT](https://github.com/bitwes/Gut) 9.6 in `test/`:
Tests run under [GUT](https://github.com/bitwes/Gut) 9.7.1 in `test/`:

```bash
godot --headless -s addons/gut/gut_cmdln.gd -gdir=res://test -ginclude_subdirs -gexit
```

### Continuous integration

Every push to `main` and every pull request runs three gates on Godot 4.6
Every push to `main` and every pull request runs four gates on Godot 4.7
headless (see [`.github/workflows/ci.yml`](.github/workflows/ci.yml)):

- **Compile gate** — `--check-only` over every engine script, so a parse/type
error never merges even in files no test imports.
- **Unit tests** — the full GUT suite above.
- **Leak gate** — the benchmark's portable ObjectDB-leak detector (fails on a
reference cycle). Its µs figures are hardware-specific and not asserted in CI.
- **Lint gate** — `gdlint` over the engine (naming/correctness smells the
compile gate cannot see; config in `.gdlintrc`).

## Showcase

Expand Down
4 changes: 2 additions & 2 deletions addons/card_combat/docs/integration_guide.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Card Combat Engine — Integration Guide

A step-by-step guide to integrating the engine into your Godot 4.6 card game.
A step-by-step guide to integrating the engine into your Godot 4.7 card game.

---

Expand Down Expand Up @@ -482,7 +482,7 @@ var session := TickCombatSession.new()

# Recovery: the game defines what it means; the engine enforces the wait.
session.recovery_fn = func(card: CardData, _owner: int) -> int:
return int(card.metadata.get("recovery", 0))
return int(card.metadata.get("recovery", 0))

# Optional per-tick economy (defaults mirror the per-turn one).
session.cards_drawn_per_tick = 1
Expand Down
2 changes: 1 addition & 1 deletion addons/card_combat/docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ If the [Integration Guide](integration_guide.md) is the reference manual, this i
the guided first project. Read it top to bottom; every snippet builds on the
previous one.

> **Prerequisites:** Godot 4.6, with the `card_combat` addon present under
> **Prerequisites:** Godot 4.7, with the `card_combat` addon present under
> `res://addons/card_combat/`. The classes register by `class_name`, so no plugin
> needs to be enabled in Project Settings to follow along.

Expand Down
8 changes: 4 additions & 4 deletions addons/gut/awaiter.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extends Node

class AwaitLogger:
class GutAwaiterLogger:
var _time_waited = 0.0
var logger = GutUtils.get_logger()
var waiting_on = "nothing"
Expand Down Expand Up @@ -31,7 +31,7 @@ class AwaitLogger:
signal timeout
signal wait_started

var await_logger = AwaitLogger.new()
var await_logger = GutAwaiterLogger.new()
var _wait_time := 0.0
var _wait_process_frames := 0
var _wait_physics_frames := 0
Expand Down Expand Up @@ -196,6 +196,6 @@ func wait_while(predicate_function: Callable, max_time, time_between_calls:=0.0,


func is_waiting():
return _wait_time != 0.0 || \
_wait_physics_frames != 0 || \
return _wait_time != 0.0 or \
_wait_physics_frames != 0 or \
_wait_process_frames != 0
17 changes: 15 additions & 2 deletions addons/gut/cli/gut_cli.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var GutRunner = load('res://addons/gut/gui/GutRunner.tscn')
# hash with null values for the other types of values. Lower precedented hashes
# will punch through null values of higher precedented hashes.
# ------------------------------------------------------------------------------
class OptionResolver:
class GutCliOptionResolver:
var base_opts = {}
var cmd_opts = {}
var config_opts = {}
Expand Down Expand Up @@ -154,6 +154,7 @@ an immediate "=":
opts.add('-gh', false, 'Print this help. You did this to see this, so you probably understand.')
opts.add('-gpo', false, 'Print option values from all sources and the value used.')
opts.add('-gprint_gutconfig_sample', false, 'Print out json that can be used to make a gutconfig file.')
opts.add("-gcheck_update", false, "Check for update")

# run as in editor, for shelling out purposes through Editor.
var o = opts.add('-graie', false, 'do not use')
Expand Down Expand Up @@ -238,9 +239,18 @@ func _run_tests(opt_resolver):
runner.run_tests()


var update_detector = null
func _check_for_update():
print(str("Checking for update for GUT ", GutUtils.version_numbers.gut_version))
update_detector = GutUtils.UpdateDetector.new()
add_child(update_detector)
await update_detector.check_for_update_with_fetch()
print(update_detector.get_update_string())


# parse options and run Gut
func main():
var opt_resolver = OptionResolver.new()
var opt_resolver = GutCliOptionResolver.new()
opt_resolver.set_base_opts(_gut_config.default_options)

var cli_opts = setup_options(_gut_config.default_options, _gut_config.valid_fonts)
Expand Down Expand Up @@ -280,6 +290,9 @@ func main():
elif(cli_opts.get_value('-gprint_gutconfig_sample')):
_print_gutconfigs(opt_resolver.get_resolved_values())
get_tree().quit(0)
elif(cli_opts.get_value('-gcheck_update')):
await _check_for_update()
get_tree().quit(0)
else:
_run_tests(opt_resolver)

Expand Down
32 changes: 16 additions & 16 deletions addons/gut/cli/optparse.gd
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
#
# value will return the default when it has not been set.
#-------------------------------------------------------------------------------
class Option:
class OptParseOption:
var _has_been_set = false
var _value = null
# REMEMBER that when this option is an array, you have to set the value
Expand Down Expand Up @@ -221,7 +221,7 @@ class Option:
#-------------------------------------------------------------------------------
# A struct for organizing options by a heading
#-------------------------------------------------------------------------------
class OptionHeading:
class OptParseOptionHeading:
var options = []
var display = 'default'

Expand All @@ -232,19 +232,19 @@ class OptionHeading:
# Organizes options by order, heading, position. Also responsible for all
# help related text generation.
#-------------------------------------------------------------------------------
class Options:
class OptParseOptions:
var options = []
var positional = []
var default_heading = OptionHeading.new()
var script_option = Option.new('-s', '?', 'script option provided by Godot')
var default_heading = OptParseOptionHeading.new()
var script_option = OptParseOption.new('-s', '?', 'script option provided by Godot')

var _options_by_name = {"--script": script_option, "-s": script_option}
var _options_by_heading = [default_heading]
var _cur_heading = default_heading


func add_heading(display):
var heading = OptionHeading.new()
var heading = OptParseOptionHeading.new()
heading.display = display
_cur_heading = heading
_options_by_heading.append(heading)
Expand Down Expand Up @@ -347,7 +347,7 @@ class Options:
#
#-------------------------------------------------------------------------------
## @ignore
var options := Options.new()
var options := OptParseOptions.new()
## Set the banner property to any text you want to appear before the usage and
## options sections when printing the options help.
var banner := ''
Expand Down Expand Up @@ -474,10 +474,10 @@ func is_option(arg) -> bool:
## If the option is not successfully added (e.g. a name collision with another
## option occurs), an error message will be printed and [code]null[/code]
## will be returned.
func add(op_names, default, desc: String) -> Option:
func add(op_names, default, desc: String) -> OptParseOption:
var op_name: String
var aliases: Array[String] = []
var new_op: Option = null
var new_op: OptParseOption = null

if(typeof(op_names) == TYPE_STRING):
op_name = op_names
Expand All @@ -494,7 +494,7 @@ func add(op_names, default, desc: String) -> Option:
elif bad_alias != -1:
push_error(str('Option [', aliases[bad_alias], '] already exists.'))
else:
new_op = Option.new(op_name, default, desc)
new_op = OptParseOption.new(op_name, default, desc)
options.add(new_op, aliases)

return new_op
Expand All @@ -514,7 +514,7 @@ func add(op_names, default, desc: String) -> Option:
## If the option is not successfully added (e.g. a name collision with another
## option occurs), an error message will be printed and [code]null[/code]
## will be returned.
func add_required(op_names, default, desc: String) -> Option:
func add_required(op_names, default, desc: String) -> OptParseOption:
var op := add(op_names, default, desc)
if(op != null):
op.required = true
Expand All @@ -535,12 +535,12 @@ func add_required(op_names, default, desc: String) -> Option:
## If the option is not successfully added (e.g. a name collision with another
## option occurs), an error message will be printed and [code]null[/code]
## will be returned.
func add_positional(op_name, default, desc: String) -> Option:
func add_positional(op_name, default, desc: String) -> OptParseOption:
var new_op = null
if(options.get_by_name(op_name) != null):
push_error(str('Positional option [', op_name, '] already exists.'))
else:
new_op = Option.new(op_name, default, desc)
new_op = OptParseOption.new(op_name, default, desc)
options.add_positional(new_op)
return new_op

Expand All @@ -561,7 +561,7 @@ func add_positional(op_name, default, desc: String) -> Option:
## If the option is not successfully added (e.g. a name collision with another
## option occurs), an error message will be printed and [code]null[/code]
## will be returned.
func add_positional_required(op_name, default, desc: String) -> Option:
func add_positional_required(op_name, default, desc: String) -> OptParseOption:
var op = add_positional(op_name, default, desc)
if(op != null):
op.required = true
Expand All @@ -582,7 +582,7 @@ func add_heading(display_text: String) -> void:
## If the option exists, the value assigned to it during parsing is returned.
## Otherwise, an error message is printed and [code]null[/code] is returned.
func get_value(name: String):
var found_param: Option = options.get_by_name(name)
var found_param: OptParseOption = options.get_by_name(name)

if(found_param != null):
return found_param.value
Expand All @@ -602,7 +602,7 @@ func get_value(name: String):
## then you do not want to get the default value for a command line option or
## it will overwrite the value in a config file.
func get_value_or_null(name: String):
var found_param: Option = options.get_by_name(name)
var found_param: OptParseOption = options.get_by_name(name)

if(found_param != null and found_param.has_been_set()):
return found_param.value
Expand Down
10 changes: 5 additions & 5 deletions addons/gut/double_templates/function_template.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{func_decleration}
if(__gutdbl == null):
return

__gutdbl.spy_on('{method_name}', {param_array})
if(__gutdbl.is_stubbed_to_call_super('{method_name}', {param_array})):
{super_call}
else:
return await __gutdbl.handle_other_stubs('{method_name}', {param_array})
__gutdbl.spy_on('{method_name}', {param_array})
if(__gutdbl.is_stubbed_to_call_super('{method_name}', {param_array})):
{super_call}
else:
{return_it}await __gutdbl.handle_other_stubs('{method_name}', {param_array})
14 changes: 5 additions & 9 deletions addons/gut/doubler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var _singleton_parser = GutUtils.SingletonParser.new()

# used by tests for debugging purposes.
var print_source = false
var inner_class_registry = GutUtils.InnerClassRegistry.new()
var inner_class_registry = GutUtils.inner_class_registry

# ###############
# Properties
Expand Down Expand Up @@ -195,14 +195,14 @@ func _create_double(parsed, strategy, override_path, partial):
for method in parsed.get_local_methods():
if(_is_method_eligible_for_doubling(parsed, method)):
included_methods.append(method.meta.name)
dbl_src += _get_func_text(method.meta)
dbl_src += _method_maker.get_function_text(method)

if(strategy == GutUtils.DOUBLE_STRATEGY.INCLUDE_NATIVE):
for method in parsed.get_super_methods():
if(_is_method_eligible_for_doubling(parsed, method)):
included_methods.append(method.meta.name)
_stub_to_call_super(parsed, method.meta.name)
dbl_src += _get_func_text(method.meta)
dbl_src += _method_maker.get_function_text(method)

var base_script = _get_base_script_text(parsed, override_path, partial, included_methods)
dbl_src = base_script + "\n\n" + dbl_src
Expand Down Expand Up @@ -238,7 +238,7 @@ func _create_singleton_double(singleton, is_partial):
var DblClass = GutUtils.create_script_from_source(dbl_src)
if(_stubber != null):
for key in parsed.methods_by_name:
var meta = parsed.methods_by_name[key]
var meta = parsed.methods_by_name[key].meta
if(meta != {} and !meta.flags & METHOD_FLAG_VARARG):
_stubber.stub_defaults_from_meta(singleton, meta)

Expand All @@ -248,7 +248,7 @@ func _create_singleton_double(singleton, is_partial):
func _stub_method_default_values(parsed):
for method in parsed.get_local_methods():
if(method.is_eligible_for_doubling() and !_ignored_methods.has(parsed.resource, method.meta.name)):
_stubber.stub_defaults_from_meta(parsed.script_path, method.meta)
_stubber.stub_defaults_from_meta(parsed.resource, method.meta)


func _double_scene_and_script(scene, strategy, partial):
Expand Down Expand Up @@ -281,10 +281,6 @@ func _get_inst_id_ref_str(inst):
return ref_str


func _get_func_text(method_hash):
return _method_maker.get_function_text(method_hash) + "\n"


func _parse_script(obj):
var parsed = null

Expand Down
18 changes: 16 additions & 2 deletions addons/gut/error_tracker.gd
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func _get_stack_data(current_test_name):
stackTrace.remove_at(0)

return {
"test_entry" = test_entry,
"full_stack" = stackTrace
"test_entry": test_entry,
"full_stack": stackTrace
}


Expand All @@ -75,6 +75,17 @@ func _is_error_failable(error : GutTrackedError):
is_it = treat_engine_errors_as == GutUtils.TREAT_AS.FAILURE
return is_it


# Marks any errors that GUT should not fail a test for based on internal,
# non-alterable rules. This is idealogically differnet than _is_error_failable.
func _auto_handle_error(err : GutTrackedError):
# Issue 842, when the source has an await and a declared return type this
# error can occur when doubling. It does not appear to affect anything.
if(err.file == 'modules/gdscript/gdscript_byte_codegen.cpp' and err.function == 'write_return'):
err.handled = true
print("[GUT] \"Unresolved return\" has been ignored. See https://github.com/bitwes/Gut/issues/842 for details.")


# ----------------
#endregion
#region Godot's Logger Overrides
Expand Down Expand Up @@ -186,7 +197,10 @@ func add_error(function: String, file: String, line: int,
err.line = line

errors.add(_current_test_id, err)
_auto_handle_error(err)

_mutex.unlock()

return err


Loading
Loading