Skip to content

Commit

Permalink
0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt authored Nov 21, 2021
1 parent 0e89b81 commit 433a7af
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions dev_tools/decorator.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,46 @@
import asyncio
from arclet.letoderea import EventSystem
from arclet.letoderea.entities.event import TemplateEvent
from arclet.letoderea.entities.decorator import TemplateDecorator
from arclet.letoderea.entities.decorator import EventDecorator
from arclet.letoderea.utils import ArgumentPackage

loop = asyncio.get_event_loop()
test_stack = [0]
es = EventSystem(loop=loop)


class TestDecorator(TemplateDecorator):
def before_parser(self, target_argument: ArgumentPackage) -> str:
if target_argument.annotation == self.target_type:
return 4 * target_argument.value
class TestEventDecorator(EventDecorator):

def after_parser(self, target_argument: ArgumentPackage) -> str:
if target_argument.annotation == self.supplement_type:
return 2 * target_argument.value
def supply(self, target_argument: ArgumentPackage):
if target_argument.annotation == str:
return target_argument.value * 2
if target_argument.annotation == int:
return target_argument.value * 3


class ExampleEvent(TemplateEvent):
type: str = "ExampleEvent"
num: int
msg: str

def get_params(self):
return self.param_export(
str=self.msg
str=self.msg,
int=self.num
)


@es.register(ExampleEvent, decorators=[TestDecorator(str, str)])
async def test(m: str):
@es.register(ExampleEvent, decorators=[TestEventDecorator()])
async def test(m: int, a: str):
for i in range(5):
await asyncio.sleep(0.1)
print(m, type(m))
print(m, type(m), end=' ')
print(a, type(a))
loop.stop()


a = ExampleEvent()
a.msg = 'a'
a.num = 1
es.event_spread(a)
loop.run_forever()

0 comments on commit 433a7af

Please sign in to comment.