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 scripting #12

Merged
merged 54 commits into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
ad82649
While compiling, find variable classes in `game_variables.py`
jeff5343 Apr 19, 2023
2d24430
Retrieve variable values of each variable class in `mapping.py`
jeff5343 Apr 24, 2023
9801d71
Create `VariableType` enum for `Variable` class
jeff5343 Apr 25, 2023
b76d3a3
Update generation to use `DataType` enum for variables
jeff5343 Apr 26, 2023
19f8301
Group variable types into `variable_types.py` and provide template da…
jeff5343 Apr 27, 2023
73a1c9f
Delete variable type classes in `functions.py`
jeff5343 Apr 28, 2023
2504565
Fix imports and `VariableType` `__init__` methods
jeff5343 Apr 29, 2023
16944d7
Add variables in `game_variables.py` to the compiled game output
jeff5343 Apr 30, 2023
9bf6082
Create `Region`, `ItemTypeGroup`, and `UnitTypeGroup` classes
jeff5343 Apr 30, 2023
d7be8f3
Update generation to use new variable type classes
jeff5343 Apr 30, 2023
bf816c5
Always import all variable type classes in `game_variables.py`
jeff5343 Apr 30, 2023
403db6c
Fix data type values of player and entity variables
jeff5343 May 1, 2023
2c1e837
Rename helper function in `game_variables_file.rs` for clarification
jeff5343 May 2, 2023
e7f9aff
Delete `ItemTypeGroup` and `UnitTypeGroup` class
jeff5343 May 3, 2023
e9cf898
Update generation for removed variable type group classes
jeff5343 May 3, 2023
5549f34
Change relative imports to absolute imports in pymodd
jeff5343 May 3, 2023
bb9e557
Add optional name parameter to variable types
jeff5343 May 4, 2023
626dc7c
Update generation to include names for game variables
jeff5343 May 4, 2023
a8a19b6
Remove data of variables no longer present in `game_variables.py`
jeff5343 May 4, 2023
b4e2626
Delete `Region` variable type class and update generation
jeff5343 May 4, 2023
09982c6
Fix variable ids generating multiple times during compilation
jeff5343 May 4, 2023
3dd0aab
Setup class to turn python code into modd.io data
jeff5343 May 5, 2023
7a6abcc
Fix `variable_categories.rs` tests
jeff5343 May 5, 2023
0cabfc6
Merge branch 'edit-variables-dynamicallty' into refactor-scripting
jeff5343 May 5, 2023
528f5d7
Fix circular import in `script.py`
jeff5343 May 5, 2023
a7573bf
Use global dicts when evaluating function calls
jeff5343 May 6, 2023
c1de1aa
Use local variables when evaluating function calls
jeff5343 May 6, 2023
3a8ddb0
Clean up `ScriptActionsCompiler`
jeff5343 May 6, 2023
05505ab
Add example for `flip_sprite_of_entity` action
jeff5343 May 6, 2023
b585140
Convert python for loops into modd.io data
jeff5343 May 6, 2023
4242c61
Implement iteration of variables of group data types
jeff5343 May 7, 2023
2083984
Provide clear error messages if an exception occurs while compiling
jeff5343 May 8, 2023
2c5484d
Fix multiline doc comments
jeff5343 May 8, 2023
80a914c
Rename functions for consistency
jeff5343 May 8, 2023
070a16a
Add docs for deprecated actions
jeff5343 May 8, 2023
2df86fb
Rename `EntityAttribute` and `PlayerAttribute` functions for clarity
jeff5343 May 8, 2023
edc7c85
Fix pymodd generator tests
jeff5343 May 8, 2023
d5c1317
Fix compiling scripts
jeff5343 May 8, 2023
f1ce2aa
Filter out null actions from compiled json
jeff5343 May 9, 2023
d5370c8
Remove commas from generated actions
jeff5343 May 9, 2023
a6adf82
Generate python if statements from if statement actions
jeff5343 May 9, 2023
6cadd80
Generate Script classes without lists of actions
jeff5343 May 9, 2023
346cb67
Generate python for loops from variable for loop actions
jeff5343 May 10, 2023
8f9e45a
Generate python for loops from repeat actions
jeff5343 May 10, 2023
4e497d2
Generate python for loops from for each type in function/variable act…
jeff5343 May 10, 2023
9a6681f
Generate python while loops from while actions
jeff5343 May 10, 2023
9af8d03
Generate python keywords from break, continue, and return actions
jeff5343 May 10, 2023
5b3b085
Replace `SelectedType` functions with variables defined in for loops
jeff5343 May 11, 2023
7cc9f49
Handle errors cleanly when converting arguments of special actions
jeff5343 May 11, 2023
eab3644
Evaluate conditions using AST
jeff5343 May 11, 2023
86fd0f2
Update generation to use `and` and `or` keywords for comparisons
jeff5343 May 11, 2023
69a169a
Update generation to surround inner `and` `or` conditions with parent…
jeff5343 May 11, 2023
f0d24f8
Update example project
jeff5343 May 11, 2023
79d4462
Update README.rst
jeff5343 May 11, 2023
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
25 changes: 9 additions & 16 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,12 @@ view the ``examples/froge directory`` for a generated pymodd project
@script(triggers=[Trigger.EVERY_SECOND])
class EverySecond():
def _build(self):
self.actions = [
if_else((NumberOfUnitsOfUnitType(UnitTypes.FROG) < 5), [
create_unit_for_player_at_position_with_rotation(UnitTypes.FROG, Variables.AI, RandomPositionInRegion(EntireMapRegion()), 0),
], [
if_else((NumberOfUnitsOfUnitType(UnitTypes.FROG_BOSS) == 0), [
if_else((Variables.BOSS_TIMER <= 0), [
create_unit_for_player_at_position_with_rotation(UnitTypes.FROG_BOSS, Variables.AI, RandomPositionInRegion(EntireMapRegion()), 0),
update_ui_target_for_player_for_miliseconds(UiTarget.CENTER, 'BOSS SPAWNED', Undefined(), 5000),
set_variable(Variables.BOSS_TIMER, 200),
], [
]),
decrease_variable_by_number(Variables.BOSS_TIMER, 1),
], [
]),
]),
]
if NumberOfUnitsOfUnitType(UnitTypes.FROG) < 5:
create_unit_for_player_at_position_with_rotation(UnitTypes.FROG, Variables.AI, RandomPositionInRegion(EntireMapRegion()), 0)
else:
if NumberOfUnitsOfUnitType(UnitTypes.FROG_BOSS) == 0:
if Variables.BOSS_TIMER <= 0:
create_unit_for_player_at_position_with_rotation(UnitTypes.FROG_BOSS, Variables.AI, RandomPositionInRegion(EntireMapRegion()), 0)
update_ui_target_for_player_for_miliseconds(UiTarget.CENTER, 'BOSS SPAWNED', Undefined(), 5000)
decrease_variable_by_number(Variables.BOSS_TIMER, 1)

15 changes: 3 additions & 12 deletions examples/froge/entity_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,12 @@ def _build(self):
@script(triggers=[])
class UseItem():
def _build(self):
self.actions = [
use_item_continuously_until_stopped(ItemCurrentlyHeldByUnit(ThisEntity())),

]
use_item_continuously_until_stopped(ItemCurrentlyHeldByUnit(ThisEntity()))

@script(triggers=[])
class StopUsingItem():
def _build(self):
self.actions = [
stop_using_item(ItemCurrentlyHeldByUnit(ThisEntity())),

]
stop_using_item(ItemCurrentlyHeldByUnit(ThisEntity()))


class Frog(EntityScripts):
Expand All @@ -42,9 +36,6 @@ def _build(self):
@script(triggers=[])
class NewScript():
def _build(self):
self.actions = [
comment('wdwadawd'),

]
comment('wdwadawd')


106 changes: 53 additions & 53 deletions examples/froge/game_variables.py
Original file line number Diff line number Diff line change
@@ -1,92 +1,92 @@
from pymodd.functions import UnitType, PlayerType, ItemType, Variable, EntityVariable, AnimationType, AttributeType, State, Shop, Music


class UnitTypes:
FROG_BOSS = UnitType("TyaKyQzgKc")
POOPER = UnitType("fighter")
FROG = UnitType("oTDQ3jlcMa")


class PlayerTypes:
AI = PlayerType("eA9ZwoweVz")
PLAYER = PlayerType("humanPlayer")
from pymodd.variable_types import ItemType, ProjectileType, UnitType, PlayerType, Variable, Variable, Variable, EntityVariable, PlayerVariable, Variable, Shop, Dialogue, Music, Sound, State, AnimationType, AttributeType, DataType


class ItemTypes:
BOSS_FROG_TONGUE = ItemType("AqrGZUYBdS")
FROG_TONGUE = ItemType("BBCDO38dr7")
KNIFE = ItemType("bMDJQyFACm")
FROG_SWORD = ItemType("tmAlzggQX4")
BOSS_FROG_TONGUE = ItemType('AqrGZUYBdS', name='Boss Frog Tongue')
FROG_TONGUE = ItemType('BBCDO38dr7', name='Frog Tongue')
KNIFE = ItemType('bMDJQyFACm', name='Knife')
FROG_SWORD = ItemType('tmAlzggQX4', name='Frog Sword')


class ProjectileTypes:
pass


class Regions:
pass


class Variables:
AI = Variable("AI", variable_type='player')
BOSS_TIMER = Variable("bossTimer", variable_type='number')
DWADAWD = Variable("dwadawd", variable_type='unitGroup')
TEMP_UNIT = Variable("tempUnit", variable_type='unit')
TIMER = Variable("timer", variable_type='number')
class UnitTypes:
FROG_BOSS = UnitType('TyaKyQzgKc', name='Frog Boss')
POOPER = UnitType('fighter', name='Pooper')
FROG = UnitType('oTDQ3jlcMa', name='Frog')


class EntityVariables:
SENSOR_RADIUS = EntityVariable("sensorRadius", variable_type='number')
TARGET_UNIT = EntityVariable("targetUnit", variable_type='unit')
class PlayerTypes:
AI = PlayerType('eA9ZwoweVz', name='ai')
PLAYER = PlayerType('humanPlayer', name='Player')


class PlayerVariables:
pass
class ItemTypeGroups:
RANDOMGROUP = Variable('randomgroup', DataType.ITEM_TYPE_GROUP)


class AnimationTypes:
TONGUE_OUT = AnimationType("B1cWOYKvNL")
DEFAULT = AnimationType("default")
DROPPED = AnimationType("dropped")
USE = AnimationType("use")
class UnitTypeGroups:
UNITTYPEGROUP = Variable('unittypegroup', DataType.UNIT_TYPE_GROUP)


class AttributeTypes:
MOVE = AttributeType("G3adwzJecn")
HEALTH = AttributeType("health")
SPEED = AttributeType("speed")
FROG_KILLS = AttributeType("yjdyHZbWpA")
class Variables:
AI = Variable('AI', DataType.PLAYER)
BOSS_TIMER = Variable('bossTimer', DataType.NUMBER)
DWADAWD = Variable('dwadawd', DataType.UNIT_GROUP)
TEMP_UNIT = Variable('tempUnit', DataType.UNIT)
TIMER = Variable('timer', DataType.NUMBER)


class ItemTypeGroups:
RANDOMGROUP = Variable("randomgroup", variable_type='itemTypeGroup')
class EntityVariables:
SENSOR_RADIUS = EntityVariable('sensorRadius', DataType.NUMBER)
TARGET_UNIT = EntityVariable('targetUnit', DataType.UNIT)


class UnitTypeGroups:
UNITTYPEGROUP = Variable("unittypegroup", variable_type='unitTypeGroup')
class PlayerVariables:
TARGET_UNIT = PlayerVariable('targetUnit', DataType.UNIT)


class States:
DEFAULT = State("default")
DROPPED = State("dropped")
TONGUE_OUT = State("r60qiEIvyt")
SELECTED = State("selected")
UNSELECTED = State("unselected")
class Regions:
pass


class Shops:
FROGE_SHOP = Shop("OJbEQyc7is")
FROGE_SHOP = Shop('OJbEQyc7is', name='Froge Shop')


class Dialogues:
pass


class Musics:
D = Music("iJ8RoRfyeu")
D = Music('iJ8RoRfyeu', name='d')


class Sounds:
pass


class States:
DEFAULT = State('default', name='default')
DROPPED = State('dropped', name='dropped')
TONGUE_OUT = State('r60qiEIvyt', name='tongue out')
SELECTED = State('selected', name='selected')
UNSELECTED = State('unselected', name='unselected')


class AnimationTypes:
TONGUE_OUT = AnimationType('B1cWOYKvNL', name='tongue out')
DEFAULT = AnimationType('default', name='default')
DROPPED = AnimationType('dropped', name='dropped')
USE = AnimationType('use', name='use')


class AttributeTypes:
MOVE = AttributeType('G3adwzJecn', name='move')
HEALTH = AttributeType('health', name='health ')
SPEED = AttributeType('speed', name='speed')
FROG_KILLS = AttributeType('yjdyHZbWpA', name='frog kills')


Loading