frontend: support input + refactoring
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
export { Input } from './input-event/input.js';
|
||||
export { InputEvent } from './input-event/input-event.js';
|
||||
export { KeyAction } from './input-event/key-action.js';
|
||||
export { KeyboardInput } from './input-event/keyboard-input.js';
|
||||
export { ModifierState } from './input-event/modifier-state.js';
|
||||
export { MouseButton } from './input-event/mouse-button.js';
|
||||
export { MouseInput } from './input-event/mouse-input.js';
|
||||
export { MouseMovement } from './input-event/mouse-movement.js';
|
||||
@@ -0,0 +1,69 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { Input, unionToInput, unionListToInput } from '../input-event/input.js';
|
||||
|
||||
|
||||
export class InputEvent {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):InputEvent {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsInputEvent(bb:flatbuffers.ByteBuffer, obj?:InputEvent):InputEvent {
|
||||
return (obj || new InputEvent()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsInputEvent(bb:flatbuffers.ByteBuffer, obj?:InputEvent):InputEvent {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new InputEvent()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
inputType():Input {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.readUint8(this.bb_pos + offset) : Input.NONE;
|
||||
}
|
||||
|
||||
input<T extends flatbuffers.Table>(obj:any):any|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.__union(obj, this.bb_pos + offset) : null;
|
||||
}
|
||||
|
||||
static startInputEvent(builder:flatbuffers.Builder) {
|
||||
builder.startObject(2);
|
||||
}
|
||||
|
||||
static addInputType(builder:flatbuffers.Builder, inputType:Input) {
|
||||
builder.addFieldInt8(0, inputType, Input.NONE);
|
||||
}
|
||||
|
||||
static addInput(builder:flatbuffers.Builder, inputOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(1, inputOffset, 0);
|
||||
}
|
||||
|
||||
static endInputEvent(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
static finishInputEventBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) {
|
||||
builder.finish(offset);
|
||||
}
|
||||
|
||||
static finishSizePrefixedInputEventBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) {
|
||||
builder.finish(offset, undefined, true);
|
||||
}
|
||||
|
||||
static createInputEvent(builder:flatbuffers.Builder, inputType:Input, inputOffset:flatbuffers.Offset):flatbuffers.Offset {
|
||||
InputEvent.startInputEvent(builder);
|
||||
InputEvent.addInputType(builder, inputType);
|
||||
InputEvent.addInput(builder, inputOffset);
|
||||
return InputEvent.endInputEvent(builder);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
import { KeyboardInput } from '../input-event/keyboard-input.js';
|
||||
import { MouseInput } from '../input-event/mouse-input.js';
|
||||
import { MouseMovement } from '../input-event/mouse-movement.js';
|
||||
|
||||
|
||||
export enum Input {
|
||||
NONE = 0,
|
||||
Keyboard = 1,
|
||||
MouseMovement = 2,
|
||||
MouseInput = 3
|
||||
}
|
||||
|
||||
export function unionToInput(
|
||||
type: Input,
|
||||
accessor: (obj:KeyboardInput|MouseInput|MouseMovement) => KeyboardInput|MouseInput|MouseMovement|null
|
||||
): KeyboardInput|MouseInput|MouseMovement|null {
|
||||
switch(Input[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'Keyboard': return accessor(new KeyboardInput())! as KeyboardInput;
|
||||
case 'MouseMovement': return accessor(new MouseMovement())! as MouseMovement;
|
||||
case 'MouseInput': return accessor(new MouseInput())! as MouseInput;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function unionListToInput(
|
||||
type: Input,
|
||||
accessor: (index: number, obj:KeyboardInput|MouseInput|MouseMovement) => KeyboardInput|MouseInput|MouseMovement|null,
|
||||
index: number
|
||||
): KeyboardInput|MouseInput|MouseMovement|null {
|
||||
switch(Input[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'Keyboard': return accessor(index, new KeyboardInput())! as KeyboardInput;
|
||||
case 'MouseMovement': return accessor(index, new MouseMovement())! as MouseMovement;
|
||||
case 'MouseInput': return accessor(index, new MouseInput())! as MouseInput;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
export enum KeyAction {
|
||||
DOWN = 0,
|
||||
UP = 1
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { KeyAction } from '../input-event/key-action.js';
|
||||
import { ModifierState } from '../input-event/modifier-state.js';
|
||||
|
||||
|
||||
export class KeyboardInput {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):KeyboardInput {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsKeyboardInput(bb:flatbuffers.ByteBuffer, obj?:KeyboardInput):KeyboardInput {
|
||||
return (obj || new KeyboardInput()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsKeyboardInput(bb:flatbuffers.ByteBuffer, obj?:KeyboardInput):KeyboardInput {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new KeyboardInput()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
keyCode():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.readInt16(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
keyAction():KeyAction {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.readInt8(this.bb_pos + offset) : KeyAction.DOWN;
|
||||
}
|
||||
|
||||
modifiers(obj?:ModifierState):ModifierState|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 8);
|
||||
return offset ? (obj || new ModifierState()).__init(this.bb_pos + offset, this.bb!) : null;
|
||||
}
|
||||
|
||||
static startKeyboardInput(builder:flatbuffers.Builder) {
|
||||
builder.startObject(3);
|
||||
}
|
||||
|
||||
static addKeyCode(builder:flatbuffers.Builder, keyCode:number) {
|
||||
builder.addFieldInt16(0, keyCode, 0);
|
||||
}
|
||||
|
||||
static addKeyAction(builder:flatbuffers.Builder, keyAction:KeyAction) {
|
||||
builder.addFieldInt8(1, keyAction, KeyAction.DOWN);
|
||||
}
|
||||
|
||||
static addModifiers(builder:flatbuffers.Builder, modifiersOffset:flatbuffers.Offset) {
|
||||
builder.addFieldStruct(2, modifiersOffset, 0);
|
||||
}
|
||||
|
||||
static endKeyboardInput(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
export class ModifierState {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):ModifierState {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
shift():boolean {
|
||||
return !!this.bb!.readInt8(this.bb_pos);
|
||||
}
|
||||
|
||||
ctrl():boolean {
|
||||
return !!this.bb!.readInt8(this.bb_pos + 1);
|
||||
}
|
||||
|
||||
alt():boolean {
|
||||
return !!this.bb!.readInt8(this.bb_pos + 2);
|
||||
}
|
||||
|
||||
meta():boolean {
|
||||
return !!this.bb!.readInt8(this.bb_pos + 3);
|
||||
}
|
||||
|
||||
static sizeOf():number {
|
||||
return 4;
|
||||
}
|
||||
|
||||
static createModifierState(builder:flatbuffers.Builder, shift: boolean, ctrl: boolean, alt: boolean, meta: boolean):flatbuffers.Offset {
|
||||
builder.prep(1, 4);
|
||||
builder.writeInt8(Number(Boolean(meta)));
|
||||
builder.writeInt8(Number(Boolean(alt)));
|
||||
builder.writeInt8(Number(Boolean(ctrl)));
|
||||
builder.writeInt8(Number(Boolean(shift)));
|
||||
return builder.offset();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
export enum MouseButton {
|
||||
LEFT = 0,
|
||||
MIDDLE = 1,
|
||||
RIGHT = 2,
|
||||
X1 = 3,
|
||||
X2 = 4
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { KeyAction } from '../input-event/key-action.js';
|
||||
import { MouseButton } from '../input-event/mouse-button.js';
|
||||
|
||||
|
||||
export class MouseInput {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):MouseInput {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsMouseInput(bb:flatbuffers.ByteBuffer, obj?:MouseInput):MouseInput {
|
||||
return (obj || new MouseInput()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsMouseInput(bb:flatbuffers.ByteBuffer, obj?:MouseInput):MouseInput {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new MouseInput()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
button():MouseButton {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.readInt8(this.bb_pos + offset) : MouseButton.LEFT;
|
||||
}
|
||||
|
||||
buttonAction():KeyAction {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.readInt8(this.bb_pos + offset) : KeyAction.DOWN;
|
||||
}
|
||||
|
||||
static startMouseInput(builder:flatbuffers.Builder) {
|
||||
builder.startObject(2);
|
||||
}
|
||||
|
||||
static addButton(builder:flatbuffers.Builder, button:MouseButton) {
|
||||
builder.addFieldInt8(0, button, MouseButton.LEFT);
|
||||
}
|
||||
|
||||
static addButtonAction(builder:flatbuffers.Builder, buttonAction:KeyAction) {
|
||||
builder.addFieldInt8(1, buttonAction, KeyAction.DOWN);
|
||||
}
|
||||
|
||||
static endMouseInput(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
static createMouseInput(builder:flatbuffers.Builder, button:MouseButton, buttonAction:KeyAction):flatbuffers.Offset {
|
||||
MouseInput.startMouseInput(builder);
|
||||
MouseInput.addButton(builder, button);
|
||||
MouseInput.addButtonAction(builder, buttonAction);
|
||||
return MouseInput.endMouseInput(builder);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
export class MouseMovement {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):MouseMovement {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsMouseMovement(bb:flatbuffers.ByteBuffer, obj?:MouseMovement):MouseMovement {
|
||||
return (obj || new MouseMovement()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsMouseMovement(bb:flatbuffers.ByteBuffer, obj?:MouseMovement):MouseMovement {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new MouseMovement()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
movementX():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.readInt16(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
movementY():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.readInt16(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
static startMouseMovement(builder:flatbuffers.Builder) {
|
||||
builder.startObject(2);
|
||||
}
|
||||
|
||||
static addMovementX(builder:flatbuffers.Builder, movementX:number) {
|
||||
builder.addFieldInt16(0, movementX, 0);
|
||||
}
|
||||
|
||||
static addMovementY(builder:flatbuffers.Builder, movementY:number) {
|
||||
builder.addFieldInt16(1, movementY, 0);
|
||||
}
|
||||
|
||||
static endMouseMovement(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
static createMouseMovement(builder:flatbuffers.Builder, movementX:number, movementY:number):flatbuffers.Offset {
|
||||
MouseMovement.startMouseMovement(builder);
|
||||
MouseMovement.addMovementX(builder, movementX);
|
||||
MouseMovement.addMovementY(builder, movementY);
|
||||
return MouseMovement.endMouseMovement(builder);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
export * as InputEvent from './input-event.js';
|
||||
Reference in New Issue
Block a user