-
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
8cb7920
commit 86c8836
Showing
7 changed files
with
85 additions
and
9 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
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 |
---|---|---|
@@ -1,8 +1,33 @@ | ||
/*declare module "yoni-mcscripts-lib" { | ||
interface EventOptions extends InnerEventOptions { | ||
} | ||
import Minecraft from "../../minecraft.js"; | ||
import { Equals, UnionToTuple, DumpTupleRecordEntriesToUnion } from "../../lib/types"; | ||
|
||
export interface EventOptionDefinitions extends MinecraftEventsOptions, InnerEventsOptions { | ||
} | ||
|
||
interface MinecraftEventsOptions { | ||
"Minecraft.EntityRemovedAfterEvent": [Minecraft.EntityRemovedAfterEvent, Minecraft.EntityEventOptions] | ||
"Minecraft.EntityHurtAfterEvent": [Minecraft.EntityHurtAfterEvent, Minecraft.EntityEventOptions] | ||
"Minecraft.EntityHitEntityAfterEvent": [Minecraft.EntityHitEntityAfterEvent, Minecraft.EntityEventOptions] | ||
"Minecraft.EntityHitBlockAfterEvent": [Minecraft.EntityHitBlockAfterEvent, Minecraft.EntityEventOptions] | ||
"Minecraft.EntityHealthChangedAfterEvent": [Minecraft.EntityHealthChangedAfterEvent, Minecraft.EntityEventOptions] | ||
"Minecraft.EntityDieAfterEvent": [Minecraft.EntityDieAfterEvent, Minecraft.EntityEventOptions] | ||
"Minecraft.EffectAddAfterEvent": [Minecraft.EffectAddAfterEvent, Minecraft.EntityEventOptions] | ||
"Minecraft.DataDrivenEntityTriggerAfterEvent": [Minecraft.DataDrivenEntityTriggerAfterEvent, Minecraft.EntityDataDrivenTriggerEventOptions] | ||
"Minecraft.DataDrivenEntityTriggerBeforeEvent": [Minecraft.DataDrivenEntityTriggerBeforeEvent, Minecraft.EntityDataDrivenTriggerEventOptions] | ||
} | ||
|
||
interface InnerEventOptions { | ||
interface InnerEventsOptions { | ||
} | ||
*/ | ||
|
||
type AllEventOptionsEntries = UnionToTuple<DumpTupleRecordEntriesToUnion<EventOptionDefinitions>>; | ||
|
||
type _GetEventOptionsOfEvent<Event, EventOptionsEntries> = | ||
EventOptionsEntries extends [infer FirstSelection, ...infer LessSelections] | ||
? FirstSelection extends [infer SelectedEvent, infer SelectedOptions] | ||
? Equals<SelectedEvent, Event> extends true | ||
? SelectedOptions | ||
: _GetEventOptionsOfEvent<Event, LessSelections> | ||
: _GetEventOptionsOfEvent<Event, LessSelections> | ||
: any | ||
|
||
export type EventOptionType<Event> = _GetEventOptionsOfEvent<Event, AllEventOptionsEntries>; |
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,36 @@ | ||
//根据 https://github.com/type-challenges/type-challenges/issues/9814 改写 | ||
export type DumpTupleRecordEntriesToUnion<T> = { | ||
[id in keyof T]-?: T[id] extends [infer Event, infer EventOpt] ? T[id] : never | ||
}[keyof T] | ||
|
||
//来源:https://segmentfault.com/q/1010000042243980 | ||
//展开只是想知道这个东西干了什么 | ||
type UnionToIntersection<U> = | ||
(U extends any | ||
? (a: (k: U) => void) => void | ||
: never | ||
) extends (a: infer I) => void | ||
? I | ||
: never; | ||
|
||
type UnionLast<U> = | ||
UnionToIntersection<U> extends (a: infer I) => void | ||
? I | ||
: never; | ||
|
||
export type UnionToTuple<U> = | ||
[U] extends [never] | ||
? [] | ||
: [...UnionToTuple< | ||
Exclude< | ||
U, | ||
UnionLast<U> | ||
> | ||
>, | ||
UnionLast<U> | ||
]; | ||
|
||
//来源:https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650 | ||
export type Equals<X, Y> = | ||
(<T>() => T extends X ? 1 : 2) extends | ||
(<T>() => T extends Y ? 1 : 2) ? true : false; |
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