-
-
Notifications
You must be signed in to change notification settings - Fork 991
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 the game event system to be based on Lua at the core #5663
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
30dec56
Events are now a Lua function instead of WML
CelticMinstrel eb2d93f
Enable setting an arbitrary Lua function as an event handler.
CelticMinstrel 34c2810
Add [event]filter_formula= for WFL event filtering
CelticMinstrel 2e13265
Support passing an arbitrary Lua function as the filter when the even…
CelticMinstrel 82ff54d
Move the event firing functions to wesnoth.game_events
CelticMinstrel 5c1558e
Improve the handling of event serialization when Lua code is attached
CelticMinstrel ee19d82
Adding an event handler via the positional call style now defaults to…
CelticMinstrel 4ac7611
Unit tests for each way of assigning an action to an event handler
CelticMinstrel 74f0b9e
Unit tests for the new filter options
CelticMinstrel c12959d
Update [remove_event] to use new API
CelticMinstrel 59ee644
Update schema for the new [event] options
CelticMinstrel 5f1d7dd
Fix dynamic filters behaviour change
CelticMinstrel 9eca255
Split wesnoth.game_events.add into multiple functions
CelticMinstrel 0eef9b8
Include non-serializable events in the gamestate inspector
CelticMinstrel e7579d6
Fix non-serializable events being serialized as an empty [event] tag
CelticMinstrel 3441e56
Add luadoc for the new event functions
CelticMinstrel b1e894d
Support primary_attack and secondary_attack in wesnoth.game_events.fire
CelticMinstrel 6a764c4
Replace deprecated usages of on_event()
CelticMinstrel c5098e1
Fix WML errors showing as Lua errors
CelticMinstrel 0ec27c2
Support "formula" in the filter table
CelticMinstrel d0d9b00
Support {filter_type = "variable_path"}
CelticMinstrel 1edd0cb
Some cleanup of the events API
CelticMinstrel File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
|
||
# This is kinda a duplicate of a basic unit test system sanity test, but... it seems to fit here as well... | ||
{GENERIC_UNIT_TEST "event_test_action_wml" ( | ||
[event] | ||
name=start | ||
{SUCCEED} | ||
[/event] | ||
)} | ||
|
||
# Test that dynamically adding an event from Lua works | ||
# There's two different ways of adding events, so test both | ||
{GENERIC_UNIT_TEST "event_test_lua" ( | ||
[event] | ||
name=preload | ||
[lua] | ||
code=<< | ||
wesnoth.game_events.add_repeating('new turn', function() | ||
unit_test.succeed() | ||
end) | ||
>> | ||
[/lua] | ||
[/event] | ||
)} | ||
{GENERIC_UNIT_TEST "event_test_lua_advanced" ( | ||
[event] | ||
name=preload | ||
[lua] | ||
code=<< | ||
wesnoth.game_events.add{ | ||
name = 'new turn', | ||
action = function() | ||
unit_test.succeed() | ||
end | ||
} | ||
>> | ||
[/lua] | ||
[/event] | ||
)} | ||
|
||
# Test that first_time_only works correctly in Lua events | ||
{GENERIC_UNIT_TEST "event_test_lua_repeat" ( | ||
[event] | ||
name=preload | ||
[lua] | ||
code=<< | ||
wml.variables.only_once = 0 | ||
wml.variables.should_repeat = 0 | ||
wesnoth.game_events.add{ | ||
name = 'new turn', | ||
first_time_only = true, | ||
action = function() | ||
wml.variables.only_once = wml.variables.only_once + 1 | ||
end | ||
} | ||
wesnoth.game_events.add{ | ||
name = 'new turn', | ||
first_time_only = false, | ||
action = function() | ||
wml.variables.should_repeat = wml.variables.should_repeat + 1 | ||
end | ||
} | ||
>> | ||
[/lua] | ||
[/event] | ||
[event] | ||
name=side 1 turn 1 | ||
[end_turn][/end_turn] | ||
[/event] | ||
[event] | ||
name=side 2 turn 1 | ||
[end_turn][/end_turn] | ||
[/event] | ||
[event] | ||
name=side 1 turn 2 | ||
[end_turn][/end_turn] | ||
[/event] | ||
[event] | ||
name=side 2 turn 2 | ||
{ASSERT ({VARIABLE_CONDITIONAL only_once equals 1})} | ||
{ASSERT ({VARIABLE_CONDITIONAL should_repeat equals 2})} | ||
{SUCCEED} | ||
[/event] | ||
)} | ||
|
||
# Verify that a warning is produced if adding an event that would break saved games | ||
{GENERIC_UNIT_TEST "event_test_lua_break_save" ( | ||
[event] | ||
name=start | ||
[lua] | ||
code=<< | ||
wesnoth.game_events.add{ | ||
name = 'new turn', | ||
action = function() end | ||
} | ||
unit_test.succeed() | ||
>> | ||
[/lua] | ||
[/event] | ||
)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I acknowledge these were written before @Pentarctagon's new style for test comments, but please update the test files to the
API(s) being tested:
style.A
# wmllint: no translatables
would be good too.