-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e89b81
commit 433a7af
Showing
1 changed file
with
15 additions
and
12 deletions.
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
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() |