Initial flame_lua_runtime package
This commit is contained in:
490
lib/runtime/protocol/runtime_protocol.dart
Normal file
490
lib/runtime/protocol/runtime_protocol.dart
Normal file
@@ -0,0 +1,490 @@
|
||||
class RuntimeNodeType {
|
||||
const RuntimeNodeType._();
|
||||
|
||||
static const panel = 'panel';
|
||||
static const button = 'button';
|
||||
static const text = 'text';
|
||||
static const circle = 'circle';
|
||||
static const rect = 'rect';
|
||||
static const line = 'line';
|
||||
static const progress = 'progress';
|
||||
static const listView = 'listView';
|
||||
static const sprite = 'sprite';
|
||||
static const image = 'image';
|
||||
static const spine = 'spine';
|
||||
static const particle = 'particle';
|
||||
|
||||
static const all = {
|
||||
panel,
|
||||
button,
|
||||
text,
|
||||
circle,
|
||||
rect,
|
||||
line,
|
||||
progress,
|
||||
listView,
|
||||
sprite,
|
||||
image,
|
||||
spine,
|
||||
particle,
|
||||
};
|
||||
|
||||
static bool isSupported(String value) => all.contains(value);
|
||||
}
|
||||
|
||||
class RuntimeAnchorValue {
|
||||
const RuntimeAnchorValue._();
|
||||
|
||||
static const center = 'center';
|
||||
static const topLeft = 'topLeft';
|
||||
static const topRight = 'topRight';
|
||||
static const bottomLeft = 'bottomLeft';
|
||||
static const bottomRight = 'bottomRight';
|
||||
|
||||
static const all = {center, topLeft, topRight, bottomLeft, bottomRight};
|
||||
|
||||
static bool isSupported(String value) => all.contains(value);
|
||||
}
|
||||
|
||||
class RuntimeTextAlignValue {
|
||||
const RuntimeTextAlignValue._();
|
||||
|
||||
static const left = 'left';
|
||||
static const center = 'center';
|
||||
static const right = 'right';
|
||||
|
||||
static const all = {left, center, right};
|
||||
|
||||
static bool isSupported(String value) => all.contains(value);
|
||||
}
|
||||
|
||||
class RuntimeParticlePresetValue {
|
||||
const RuntimeParticlePresetValue._();
|
||||
|
||||
static const burst = 'burst';
|
||||
static const trail = 'trail';
|
||||
static const snow = 'snow';
|
||||
static const confetti = 'confetti';
|
||||
|
||||
static const all = {burst, trail, snow, confetti};
|
||||
|
||||
static bool isSupported(String value) => all.contains(value);
|
||||
}
|
||||
|
||||
class RuntimeEventType {
|
||||
const RuntimeEventType._();
|
||||
|
||||
static const tap = 'tap';
|
||||
static const animationDone = 'animation_done';
|
||||
static const resize = 'resize';
|
||||
static const scroll = 'scroll';
|
||||
}
|
||||
|
||||
class RuntimeCommandType {
|
||||
const RuntimeCommandType._();
|
||||
|
||||
static const movePath = 'move_path';
|
||||
static const moveTo = 'move_to';
|
||||
static const fadeTo = 'fade_to';
|
||||
static const scaleTo = 'scale_to';
|
||||
static const rotateTo = 'rotate_to';
|
||||
static const removeNode = 'remove_node';
|
||||
static const sequence = 'sequence';
|
||||
static const parallel = 'parallel';
|
||||
static const delay = 'delay';
|
||||
static const toast = 'toast';
|
||||
static const playSound = 'play_sound';
|
||||
static const playBgm = 'play_bgm';
|
||||
static const pauseBgm = 'pause_bgm';
|
||||
static const resumeBgm = 'resume_bgm';
|
||||
static const stopBgm = 'stop_bgm';
|
||||
static const preloadResources = 'preload_resources';
|
||||
static const evictResources = 'evict_resources';
|
||||
static const cancelCommands = 'cancel_commands';
|
||||
static const playSpineAnimation = 'play_spine_animation';
|
||||
static const copyText = 'copy_text';
|
||||
|
||||
static const all = {
|
||||
movePath,
|
||||
moveTo,
|
||||
fadeTo,
|
||||
scaleTo,
|
||||
rotateTo,
|
||||
removeNode,
|
||||
sequence,
|
||||
parallel,
|
||||
delay,
|
||||
toast,
|
||||
playSound,
|
||||
playBgm,
|
||||
pauseBgm,
|
||||
resumeBgm,
|
||||
stopBgm,
|
||||
preloadResources,
|
||||
evictResources,
|
||||
cancelCommands,
|
||||
playSpineAnimation,
|
||||
copyText,
|
||||
};
|
||||
|
||||
static bool isSupported(String value) => all.contains(value);
|
||||
}
|
||||
|
||||
class RuntimeProtocolField {
|
||||
const RuntimeProtocolField._();
|
||||
|
||||
static const id = 'id';
|
||||
static const type = 'type';
|
||||
static const target = 'target';
|
||||
static const parent = 'parent';
|
||||
static const asset = 'asset';
|
||||
static const pressedAsset = 'pressedAsset';
|
||||
static const disabledAsset = 'disabledAsset';
|
||||
static const animation = 'animation';
|
||||
static const skin = 'skin';
|
||||
static const loop = 'loop';
|
||||
static const text = 'text';
|
||||
static const x = 'x';
|
||||
static const y = 'y';
|
||||
static const width = 'width';
|
||||
static const height = 'height';
|
||||
static const paddingLeft = 'paddingLeft';
|
||||
static const paddingTop = 'paddingTop';
|
||||
static const paddingRight = 'paddingRight';
|
||||
static const paddingBottom = 'paddingBottom';
|
||||
static const anchor = 'anchor';
|
||||
static const layer = 'layer';
|
||||
static const visible = 'visible';
|
||||
static const alpha = 'alpha';
|
||||
static const scale = 'scale';
|
||||
static const rotation = 'rotation';
|
||||
static const color = 'color';
|
||||
static const fontSize = 'fontSize';
|
||||
static const textAlign = 'textAlign';
|
||||
static const radius = 'radius';
|
||||
static const strokeWidth = 'strokeWidth';
|
||||
static const value = 'value';
|
||||
static const scrollX = 'scrollX';
|
||||
static const scrollY = 'scrollY';
|
||||
static const contentWidth = 'contentWidth';
|
||||
static const contentHeight = 'contentHeight';
|
||||
static const virtualized = 'virtualized';
|
||||
static const cacheExtent = 'cacheExtent';
|
||||
static const inertia = 'inertia';
|
||||
static const scrollbarThumbColor = 'scrollbarThumbColor';
|
||||
static const scrollbarTrackColor = 'scrollbarTrackColor';
|
||||
static const scrollbarThickness = 'scrollbarThickness';
|
||||
static const scrollbarVisible = 'scrollbarVisible';
|
||||
static const interactive = 'interactive';
|
||||
static const onTap = 'onTap';
|
||||
static const onScroll = 'onScroll';
|
||||
static const props = 'props';
|
||||
static const creates = 'creates';
|
||||
static const updates = 'updates';
|
||||
static const removes = 'removes';
|
||||
static const render = 'render';
|
||||
static const ui = 'ui';
|
||||
static const commands = 'commands';
|
||||
static const path = 'path';
|
||||
static const duration = 'duration';
|
||||
static const angle = 'angle';
|
||||
static const message = 'message';
|
||||
static const name = 'name';
|
||||
static const volume = 'volume';
|
||||
static const channel = 'channel';
|
||||
static const group = 'group';
|
||||
static const commandGroup = 'commandGroup';
|
||||
static const scope = 'scope';
|
||||
static const onComplete = 'onComplete';
|
||||
static const failOnError = 'failOnError';
|
||||
static const track = 'track';
|
||||
static const queue = 'queue';
|
||||
static const delay = 'delay';
|
||||
static const preset = 'preset';
|
||||
static const count = 'count';
|
||||
static const speedMin = 'speedMin';
|
||||
static const speedMax = 'speedMax';
|
||||
static const gravityX = 'gravityX';
|
||||
static const gravityY = 'gravityY';
|
||||
static const spread = 'spread';
|
||||
static const colorTo = 'colorTo';
|
||||
static const radiusTo = 'radiusTo';
|
||||
static const autoRemove = 'autoRemove';
|
||||
static const fadeOut = 'fadeOut';
|
||||
}
|
||||
|
||||
class RuntimeProtocolSchema {
|
||||
const RuntimeProtocolSchema._();
|
||||
|
||||
static const nodeFields = {
|
||||
RuntimeProtocolField.id,
|
||||
RuntimeProtocolField.type,
|
||||
RuntimeProtocolField.parent,
|
||||
RuntimeProtocolField.asset,
|
||||
RuntimeProtocolField.pressedAsset,
|
||||
RuntimeProtocolField.disabledAsset,
|
||||
RuntimeProtocolField.animation,
|
||||
RuntimeProtocolField.skin,
|
||||
RuntimeProtocolField.loop,
|
||||
RuntimeProtocolField.text,
|
||||
RuntimeProtocolField.x,
|
||||
RuntimeProtocolField.y,
|
||||
RuntimeProtocolField.width,
|
||||
RuntimeProtocolField.height,
|
||||
RuntimeProtocolField.paddingLeft,
|
||||
RuntimeProtocolField.paddingTop,
|
||||
RuntimeProtocolField.paddingRight,
|
||||
RuntimeProtocolField.paddingBottom,
|
||||
RuntimeProtocolField.anchor,
|
||||
RuntimeProtocolField.layer,
|
||||
RuntimeProtocolField.visible,
|
||||
RuntimeProtocolField.alpha,
|
||||
RuntimeProtocolField.scale,
|
||||
RuntimeProtocolField.rotation,
|
||||
RuntimeProtocolField.color,
|
||||
RuntimeProtocolField.fontSize,
|
||||
RuntimeProtocolField.textAlign,
|
||||
RuntimeProtocolField.radius,
|
||||
RuntimeProtocolField.strokeWidth,
|
||||
RuntimeProtocolField.value,
|
||||
RuntimeProtocolField.scrollX,
|
||||
RuntimeProtocolField.scrollY,
|
||||
RuntimeProtocolField.contentWidth,
|
||||
RuntimeProtocolField.contentHeight,
|
||||
RuntimeProtocolField.virtualized,
|
||||
RuntimeProtocolField.cacheExtent,
|
||||
RuntimeProtocolField.inertia,
|
||||
RuntimeProtocolField.scrollbarThumbColor,
|
||||
RuntimeProtocolField.scrollbarTrackColor,
|
||||
RuntimeProtocolField.scrollbarThickness,
|
||||
RuntimeProtocolField.scrollbarVisible,
|
||||
RuntimeProtocolField.interactive,
|
||||
RuntimeProtocolField.onTap,
|
||||
RuntimeProtocolField.onScroll,
|
||||
RuntimeProtocolField.preset,
|
||||
RuntimeProtocolField.count,
|
||||
RuntimeProtocolField.duration,
|
||||
RuntimeProtocolField.speedMin,
|
||||
RuntimeProtocolField.speedMax,
|
||||
RuntimeProtocolField.gravityX,
|
||||
RuntimeProtocolField.gravityY,
|
||||
RuntimeProtocolField.spread,
|
||||
RuntimeProtocolField.colorTo,
|
||||
RuntimeProtocolField.radiusTo,
|
||||
RuntimeProtocolField.autoRemove,
|
||||
RuntimeProtocolField.fadeOut,
|
||||
};
|
||||
|
||||
static const nodeUpdateFields = {
|
||||
RuntimeProtocolField.id,
|
||||
RuntimeProtocolField.props,
|
||||
};
|
||||
|
||||
static const nodeRemoveFields = {RuntimeProtocolField.id};
|
||||
|
||||
static const nodePropsFields = {
|
||||
RuntimeProtocolField.type,
|
||||
RuntimeProtocolField.parent,
|
||||
RuntimeProtocolField.asset,
|
||||
RuntimeProtocolField.pressedAsset,
|
||||
RuntimeProtocolField.disabledAsset,
|
||||
RuntimeProtocolField.animation,
|
||||
RuntimeProtocolField.skin,
|
||||
RuntimeProtocolField.loop,
|
||||
RuntimeProtocolField.text,
|
||||
RuntimeProtocolField.x,
|
||||
RuntimeProtocolField.y,
|
||||
RuntimeProtocolField.width,
|
||||
RuntimeProtocolField.height,
|
||||
RuntimeProtocolField.paddingLeft,
|
||||
RuntimeProtocolField.paddingTop,
|
||||
RuntimeProtocolField.paddingRight,
|
||||
RuntimeProtocolField.paddingBottom,
|
||||
RuntimeProtocolField.anchor,
|
||||
RuntimeProtocolField.layer,
|
||||
RuntimeProtocolField.visible,
|
||||
RuntimeProtocolField.alpha,
|
||||
RuntimeProtocolField.scale,
|
||||
RuntimeProtocolField.rotation,
|
||||
RuntimeProtocolField.color,
|
||||
RuntimeProtocolField.fontSize,
|
||||
RuntimeProtocolField.textAlign,
|
||||
RuntimeProtocolField.radius,
|
||||
RuntimeProtocolField.strokeWidth,
|
||||
RuntimeProtocolField.value,
|
||||
RuntimeProtocolField.scrollX,
|
||||
RuntimeProtocolField.scrollY,
|
||||
RuntimeProtocolField.contentWidth,
|
||||
RuntimeProtocolField.contentHeight,
|
||||
RuntimeProtocolField.virtualized,
|
||||
RuntimeProtocolField.cacheExtent,
|
||||
RuntimeProtocolField.inertia,
|
||||
RuntimeProtocolField.scrollbarThumbColor,
|
||||
RuntimeProtocolField.scrollbarTrackColor,
|
||||
RuntimeProtocolField.scrollbarThickness,
|
||||
RuntimeProtocolField.scrollbarVisible,
|
||||
RuntimeProtocolField.interactive,
|
||||
RuntimeProtocolField.onTap,
|
||||
RuntimeProtocolField.onScroll,
|
||||
RuntimeProtocolField.preset,
|
||||
RuntimeProtocolField.count,
|
||||
RuntimeProtocolField.duration,
|
||||
RuntimeProtocolField.speedMin,
|
||||
RuntimeProtocolField.speedMax,
|
||||
RuntimeProtocolField.gravityX,
|
||||
RuntimeProtocolField.gravityY,
|
||||
RuntimeProtocolField.spread,
|
||||
RuntimeProtocolField.colorTo,
|
||||
RuntimeProtocolField.radiusTo,
|
||||
RuntimeProtocolField.autoRemove,
|
||||
RuntimeProtocolField.fadeOut,
|
||||
};
|
||||
|
||||
static const nodeDiffFields = {
|
||||
RuntimeProtocolField.creates,
|
||||
RuntimeProtocolField.updates,
|
||||
RuntimeProtocolField.removes,
|
||||
};
|
||||
|
||||
static const gameDiffFields = {
|
||||
RuntimeProtocolField.render,
|
||||
RuntimeProtocolField.ui,
|
||||
RuntimeProtocolField.commands,
|
||||
};
|
||||
|
||||
static const commandEnvelopeFields = {
|
||||
RuntimeProtocolField.type,
|
||||
RuntimeProtocolField.target,
|
||||
};
|
||||
|
||||
static const commandCommonPayloadFields = {
|
||||
RuntimeProtocolField.id,
|
||||
RuntimeProtocolField.group,
|
||||
RuntimeProtocolField.commandGroup,
|
||||
RuntimeProtocolField.scope,
|
||||
RuntimeProtocolField.onComplete,
|
||||
};
|
||||
|
||||
static const commandPayloadFieldsByType = {
|
||||
RuntimeCommandType.movePath: {
|
||||
...commandCommonPayloadFields,
|
||||
RuntimeProtocolField.path,
|
||||
RuntimeProtocolField.duration,
|
||||
},
|
||||
RuntimeCommandType.moveTo: {
|
||||
...commandCommonPayloadFields,
|
||||
RuntimeProtocolField.x,
|
||||
RuntimeProtocolField.y,
|
||||
RuntimeProtocolField.duration,
|
||||
},
|
||||
RuntimeCommandType.fadeTo: {
|
||||
...commandCommonPayloadFields,
|
||||
RuntimeProtocolField.alpha,
|
||||
RuntimeProtocolField.duration,
|
||||
},
|
||||
RuntimeCommandType.scaleTo: {
|
||||
...commandCommonPayloadFields,
|
||||
RuntimeProtocolField.scale,
|
||||
RuntimeProtocolField.duration,
|
||||
},
|
||||
RuntimeCommandType.rotateTo: {
|
||||
...commandCommonPayloadFields,
|
||||
RuntimeProtocolField.angle,
|
||||
RuntimeProtocolField.duration,
|
||||
},
|
||||
RuntimeCommandType.removeNode: commandCommonPayloadFields,
|
||||
RuntimeCommandType.sequence: {
|
||||
...commandCommonPayloadFields,
|
||||
RuntimeProtocolField.commands,
|
||||
},
|
||||
RuntimeCommandType.parallel: {
|
||||
...commandCommonPayloadFields,
|
||||
RuntimeProtocolField.commands,
|
||||
},
|
||||
RuntimeCommandType.delay: {
|
||||
...commandCommonPayloadFields,
|
||||
RuntimeProtocolField.duration,
|
||||
},
|
||||
RuntimeCommandType.toast: {
|
||||
...commandCommonPayloadFields,
|
||||
RuntimeProtocolField.text,
|
||||
RuntimeProtocolField.message,
|
||||
RuntimeProtocolField.duration,
|
||||
},
|
||||
RuntimeCommandType.playSound: {
|
||||
...commandCommonPayloadFields,
|
||||
RuntimeProtocolField.asset,
|
||||
RuntimeProtocolField.name,
|
||||
RuntimeProtocolField.volume,
|
||||
},
|
||||
RuntimeCommandType.playBgm: {
|
||||
...commandCommonPayloadFields,
|
||||
RuntimeProtocolField.asset,
|
||||
RuntimeProtocolField.name,
|
||||
RuntimeProtocolField.volume,
|
||||
RuntimeProtocolField.channel,
|
||||
RuntimeProtocolField.loop,
|
||||
},
|
||||
RuntimeCommandType.pauseBgm: {
|
||||
...commandCommonPayloadFields,
|
||||
RuntimeProtocolField.channel,
|
||||
},
|
||||
RuntimeCommandType.resumeBgm: {
|
||||
...commandCommonPayloadFields,
|
||||
RuntimeProtocolField.channel,
|
||||
},
|
||||
RuntimeCommandType.stopBgm: {
|
||||
...commandCommonPayloadFields,
|
||||
RuntimeProtocolField.channel,
|
||||
},
|
||||
RuntimeCommandType.preloadResources: {
|
||||
...commandCommonPayloadFields,
|
||||
RuntimeProtocolField.failOnError,
|
||||
},
|
||||
RuntimeCommandType.evictResources: commandCommonPayloadFields,
|
||||
RuntimeCommandType.cancelCommands: commandCommonPayloadFields,
|
||||
RuntimeCommandType.playSpineAnimation: {
|
||||
...commandCommonPayloadFields,
|
||||
RuntimeProtocolField.animation,
|
||||
RuntimeProtocolField.track,
|
||||
RuntimeProtocolField.loop,
|
||||
RuntimeProtocolField.queue,
|
||||
RuntimeProtocolField.delay,
|
||||
},
|
||||
RuntimeCommandType.copyText: {
|
||||
...commandCommonPayloadFields,
|
||||
RuntimeProtocolField.text,
|
||||
},
|
||||
};
|
||||
|
||||
static void ensureKnownKeys(
|
||||
Map<Object?, Object?> map, {
|
||||
required Set<String> allowed,
|
||||
required String context,
|
||||
}) {
|
||||
for (final key in map.keys) {
|
||||
if (key is! String) {
|
||||
throw FormatException('$context field key must be a string: $key');
|
||||
}
|
||||
if (!allowed.contains(key)) {
|
||||
throw FormatException('$context has unsupported field: $key');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Set<String> allowedCommandFields(String commandType) {
|
||||
final payloadFields = commandPayloadFieldsByType[commandType];
|
||||
if (payloadFields == null) {
|
||||
throw UnsupportedError('Unsupported runtime command: $commandType');
|
||||
}
|
||||
return {...commandEnvelopeFields, ...payloadFields};
|
||||
}
|
||||
|
||||
static Set<String> allowedCommandPayloadFields(String commandType) {
|
||||
final payloadFields = commandPayloadFieldsByType[commandType];
|
||||
if (payloadFields == null) {
|
||||
throw UnsupportedError('Unsupported runtime command: $commandType');
|
||||
}
|
||||
return payloadFields;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user