Move the Hotkey Handling into livesplit-core

This commit is contained in:
Christopher Serr
2017-12-27 03:09:24 +01:00
parent 8cca1e955f
commit 730136643d
4 changed files with 64 additions and 104 deletions
+41 -27
View File
@@ -269,7 +269,7 @@ export interface RunEditorRowJson {
segment_time: string,
best_segment_time: string,
comparison_times: string[],
selected: "NotSelected" | "Selected" | "CurrentRow",
selected: "NotSelected" | "Selected" | "Active",
}
export type SemanticColor = "Default" |
@@ -364,6 +364,8 @@ liveSplitCoreNative.GraphComponentState_is_live_delta_active = emscriptenModule.
liveSplitCoreNative.GraphComponentState_is_flipped = emscriptenModule.cwrap('GraphComponentState_is_flipped', "number", ["number"]);
liveSplitCoreNative.HotkeySystem_new = emscriptenModule.cwrap('HotkeySystem_new', "number", ["number"]);
liveSplitCoreNative.HotkeySystem_drop = emscriptenModule.cwrap('HotkeySystem_drop', null, ["number"]);
liveSplitCoreNative.HotkeySystem_deactivate = emscriptenModule.cwrap('HotkeySystem_deactivate', null, ["number"]);
liveSplitCoreNative.HotkeySystem_activate = emscriptenModule.cwrap('HotkeySystem_activate', null, ["number"]);
liveSplitCoreNative.Layout_new = emscriptenModule.cwrap('Layout_new', "number", []);
liveSplitCoreNative.Layout_default_layout = emscriptenModule.cwrap('Layout_default_layout', "number", []);
liveSplitCoreNative.Layout_parse_json = emscriptenModule.cwrap('Layout_parse_json', "number", ["string"]);
@@ -454,13 +456,13 @@ liveSplitCoreNative.RunEditor_insert_segment_below = emscriptenModule.cwrap('Run
liveSplitCoreNative.RunEditor_remove_segments = emscriptenModule.cwrap('RunEditor_remove_segments', null, ["number"]);
liveSplitCoreNative.RunEditor_move_segments_up = emscriptenModule.cwrap('RunEditor_move_segments_up', null, ["number"]);
liveSplitCoreNative.RunEditor_move_segments_down = emscriptenModule.cwrap('RunEditor_move_segments_down', null, ["number"]);
liveSplitCoreNative.RunEditor_selected_set_icon = emscriptenModule.cwrap('RunEditor_selected_set_icon', null, ["number", "number", "number"]);
liveSplitCoreNative.RunEditor_selected_remove_icon = emscriptenModule.cwrap('RunEditor_selected_remove_icon', null, ["number"]);
liveSplitCoreNative.RunEditor_selected_set_name = emscriptenModule.cwrap('RunEditor_selected_set_name', null, ["number", "string"]);
liveSplitCoreNative.RunEditor_selected_parse_and_set_split_time = emscriptenModule.cwrap('RunEditor_selected_parse_and_set_split_time', "number", ["number", "string"]);
liveSplitCoreNative.RunEditor_selected_parse_and_set_segment_time = emscriptenModule.cwrap('RunEditor_selected_parse_and_set_segment_time', "number", ["number", "string"]);
liveSplitCoreNative.RunEditor_selected_parse_and_set_best_segment_time = emscriptenModule.cwrap('RunEditor_selected_parse_and_set_best_segment_time', "number", ["number", "string"]);
liveSplitCoreNative.RunEditor_selected_parse_and_set_comparison_time = emscriptenModule.cwrap('RunEditor_selected_parse_and_set_comparison_time', "number", ["number", "string", "string"]);
liveSplitCoreNative.RunEditor_active_set_icon = emscriptenModule.cwrap('RunEditor_active_set_icon', null, ["number", "number", "number"]);
liveSplitCoreNative.RunEditor_active_remove_icon = emscriptenModule.cwrap('RunEditor_active_remove_icon', null, ["number"]);
liveSplitCoreNative.RunEditor_active_set_name = emscriptenModule.cwrap('RunEditor_active_set_name', null, ["number", "string"]);
liveSplitCoreNative.RunEditor_active_parse_and_set_split_time = emscriptenModule.cwrap('RunEditor_active_parse_and_set_split_time', "number", ["number", "string"]);
liveSplitCoreNative.RunEditor_active_parse_and_set_segment_time = emscriptenModule.cwrap('RunEditor_active_parse_and_set_segment_time', "number", ["number", "string"]);
liveSplitCoreNative.RunEditor_active_parse_and_set_best_segment_time = emscriptenModule.cwrap('RunEditor_active_parse_and_set_best_segment_time', "number", ["number", "string"]);
liveSplitCoreNative.RunEditor_active_parse_and_set_comparison_time = emscriptenModule.cwrap('RunEditor_active_parse_and_set_comparison_time', "number", ["number", "string", "string"]);
liveSplitCoreNative.RunEditor_add_comparison = emscriptenModule.cwrap('RunEditor_add_comparison', "number", ["number", "string"]);
liveSplitCoreNative.RunEditor_import_comparison = emscriptenModule.cwrap('RunEditor_import_comparison', "number", ["number", "number", "string"]);
liveSplitCoreNative.RunEditor_remove_comparison = emscriptenModule.cwrap('RunEditor_remove_comparison', null, ["number", "string"]);
@@ -604,7 +606,7 @@ liveSplitCoreNative.Timer_switch_to_previous_comparison = emscriptenModule.cwrap
liveSplitCoreNative.Timer_initialize_game_time = emscriptenModule.cwrap('Timer_initialize_game_time', null, ["number"]);
liveSplitCoreNative.Timer_uninitialize_game_time = emscriptenModule.cwrap('Timer_uninitialize_game_time', null, ["number"]);
liveSplitCoreNative.Timer_pause_game_time = emscriptenModule.cwrap('Timer_pause_game_time', null, ["number"]);
liveSplitCoreNative.Timer_unpause_game_time = emscriptenModule.cwrap('Timer_unpause_game_time', null, ["number"]);
liveSplitCoreNative.Timer_resume_game_time = emscriptenModule.cwrap('Timer_resume_game_time', null, ["number"]);
liveSplitCoreNative.Timer_set_game_time = emscriptenModule.cwrap('Timer_set_game_time', null, ["number", "number"]);
liveSplitCoreNative.Timer_set_loading_times = emscriptenModule.cwrap('Timer_set_loading_times', null, ["number", "number"]);
liveSplitCoreNative.TimerComponent_new = emscriptenModule.cwrap('TimerComponent_new', "number", []);
@@ -1563,6 +1565,18 @@ export class GraphComponentState extends GraphComponentStateRefMut {
export class HotkeySystemRef {
ptr: number;
deactivate() {
if (this.ptr == 0) {
throw "this is disposed";
}
liveSplitCoreNative.HotkeySystem_deactivate(this.ptr);
}
activate() {
if (this.ptr == 0) {
throw "this is disposed";
}
liveSplitCoreNative.HotkeySystem_activate(this.ptr);
}
constructor(ptr: number) {
this.ptr = ptr;
}
@@ -2422,50 +2436,50 @@ export class RunEditorRefMut extends RunEditorRef {
}
liveSplitCoreNative.RunEditor_move_segments_down(this.ptr);
}
selectedSetIcon(data: number, length: number) {
activeSetIcon(data: number, length: number) {
if (this.ptr == 0) {
throw "this is disposed";
}
liveSplitCoreNative.RunEditor_selected_set_icon(this.ptr, data, length);
liveSplitCoreNative.RunEditor_active_set_icon(this.ptr, data, length);
}
selectedRemoveIcon() {
activeRemoveIcon() {
if (this.ptr == 0) {
throw "this is disposed";
}
liveSplitCoreNative.RunEditor_selected_remove_icon(this.ptr);
liveSplitCoreNative.RunEditor_active_remove_icon(this.ptr);
}
selectedSetName(name: string) {
activeSetName(name: string) {
if (this.ptr == 0) {
throw "this is disposed";
}
liveSplitCoreNative.RunEditor_selected_set_name(this.ptr, name);
liveSplitCoreNative.RunEditor_active_set_name(this.ptr, name);
}
selectedParseAndSetSplitTime(time: string): boolean {
activeParseAndSetSplitTime(time: string): boolean {
if (this.ptr == 0) {
throw "this is disposed";
}
const result = liveSplitCoreNative.RunEditor_selected_parse_and_set_split_time(this.ptr, time) != 0;
const result = liveSplitCoreNative.RunEditor_active_parse_and_set_split_time(this.ptr, time) != 0;
return result;
}
selectedParseAndSetSegmentTime(time: string): boolean {
activeParseAndSetSegmentTime(time: string): boolean {
if (this.ptr == 0) {
throw "this is disposed";
}
const result = liveSplitCoreNative.RunEditor_selected_parse_and_set_segment_time(this.ptr, time) != 0;
const result = liveSplitCoreNative.RunEditor_active_parse_and_set_segment_time(this.ptr, time) != 0;
return result;
}
selectedParseAndSetBestSegmentTime(time: string): boolean {
activeParseAndSetBestSegmentTime(time: string): boolean {
if (this.ptr == 0) {
throw "this is disposed";
}
const result = liveSplitCoreNative.RunEditor_selected_parse_and_set_best_segment_time(this.ptr, time) != 0;
const result = liveSplitCoreNative.RunEditor_active_parse_and_set_best_segment_time(this.ptr, time) != 0;
return result;
}
selectedParseAndSetComparisonTime(comparison: string, time: string): boolean {
activeParseAndSetComparisonTime(comparison: string, time: string): boolean {
if (this.ptr == 0) {
throw "this is disposed";
}
const result = liveSplitCoreNative.RunEditor_selected_parse_and_set_comparison_time(this.ptr, comparison, time) != 0;
const result = liveSplitCoreNative.RunEditor_active_parse_and_set_comparison_time(this.ptr, comparison, time) != 0;
return result;
}
addComparison(comparison: string): boolean {
@@ -2526,11 +2540,11 @@ export class RunEditorRefMut extends RunEditorRef {
emscriptenModule._free(buf);
}
}
selectedSetIconFromArray(data: Int8Array) {
activeSetIconFromArray(data: Int8Array) {
const buf = emscriptenModule._malloc(data.length);
try {
emscriptenModule.writeArrayToMemory(data, buf);
this.selectedSetIcon(buf, data.length);
this.activeSetIcon(buf, data.length);
} finally {
emscriptenModule._free(buf);
}
@@ -3868,11 +3882,11 @@ export class TimerRefMut extends TimerRef {
}
liveSplitCoreNative.Timer_pause_game_time(this.ptr);
}
unpauseGameTime() {
resumeGameTime() {
if (this.ptr == 0) {
throw "this is disposed";
}
liveSplitCoreNative.Timer_unpause_game_time(this.ptr);
liveSplitCoreNative.Timer_resume_game_time(this.ptr);
}
setGameTime(time: TimeSpanRef) {
if (this.ptr == 0) {
+14 -68
View File
@@ -22,7 +22,6 @@ export interface State {
}
export class LiveSplit extends React.Component<{}, State> {
private keyEvent: EventListenerObject;
private scrollEvent: EventListenerObject;
private rightClickEvent: EventListenerObject;
@@ -87,15 +86,12 @@ export class LiveSplit extends React.Component<{}, State> {
public componentWillMount() {
this.scrollEvent = { handleEvent: (e: MouseWheelEvent) => this.onScroll(e) };
window.addEventListener("wheel", this.scrollEvent);
this.keyEvent = { handleEvent: (e: KeyboardEvent) => this.onKeyPress(e) };
window.addEventListener("keypress", this.keyEvent);
this.rightClickEvent = { handleEvent: (e: any) => this.onRightClick(e) };
window.addEventListener("contextmenu", this.rightClickEvent, false);
}
public componentWillUnmount() {
window.removeEventListener("wheel", this.scrollEvent);
window.removeEventListener("keypress", this.keyEvent);
window.removeEventListener("contextmenu", this.rightClickEvent);
this.state.timer.dispose();
this.state.layout.dispose();
@@ -264,7 +260,7 @@ export class LiveSplit extends React.Component<{}, State> {
});
layout.remount();
return;
}
}
} catch (_) { /* Failed to load the layout */ }
alert("Error loading Layout. This may not be a LiveSplit One Layout.");
});
@@ -285,6 +281,9 @@ export class LiveSplit extends React.Component<{}, State> {
});
if (run != null) {
if (this.state.hotkeySystem != null) {
this.state.hotkeySystem.deactivate();
}
const editor = RunEditor.new(run);
this.setState({
...this.state,
@@ -321,9 +320,16 @@ export class LiveSplit extends React.Component<{}, State> {
});
}
this.state.layout.remount();
if (this.state.hotkeySystem != null) {
this.state.hotkeySystem.activate();
}
}
public openLayoutEditor() {
if (this.state.hotkeySystem != null) {
this.state.hotkeySystem.deactivate();
}
const layout = this.state.layout.clone();
const editor = LayoutEditor.new(layout);
this.setState({
@@ -357,6 +363,9 @@ export class LiveSplit extends React.Component<{}, State> {
});
this.state.layout.remount();
}
if (this.state.hotkeySystem != null) {
this.state.hotkeySystem.activate();
}
}
private loadFromSplitsIO(id: string) {
@@ -411,67 +420,4 @@ export class LiveSplit extends React.Component<{}, State> {
private onSkip() {
this.state.timer.writeWith((t) => t.skipSplit());
}
private onPrintDebug() {
this.state.timer.readWith((t) => t.printDebug());
}
private onKeyPress(e: KeyboardEvent) {
if (this.state.runEditor || this.state.layoutEditor) {
return;
}
switch (e.charCode) {
case 47: {
// NumPad Slash
this.onPrintDebug();
break;
}
case 49: {
// NumPad 1
this.onSplit();
break;
}
case 50: {
// NumPad 2
this.onSkip();
break;
}
case 51: {
// NumPad 3
this.onReset();
break;
}
case 52: {
// NumPad 4
this.switchToPreviousComparison();
break;
}
case 53: {
// NumPad 5
this.onPause();
break;
}
case 54: {
// NumPad 6
this.switchToNextComparison();
break;
}
case 55: {
// NumPad 7
this.importSplits();
break;
}
case 56: {
// NumPad 8
this.onUndo();
break;
}
case 57: {
// NumPad 9
this.exportSplits();
break;
}
}
}
}
+8 -8
View File
@@ -299,7 +299,7 @@ export class RunEditor extends React.Component<Props, State> {
<tr
key={segmentIndex.toString()}
className={
(s.selected === "Selected" || s.selected === "CurrentRow") ?
(s.selected === "Selected" || s.selected === "Active") ?
"selected" :
""
}
@@ -530,14 +530,14 @@ export class RunEditor extends React.Component<Props, State> {
private changeSegmentIcon(index: number) {
this.props.editor.selectOnly(index);
openFileAsArrayBuffer((file) => {
this.props.editor.selectedSetIconFromArray(new Int8Array(file));
this.props.editor.activeSetIconFromArray(new Int8Array(file));
this.update();
});
}
private removeSegmentIcon(index: number) {
this.props.editor.selectOnly(index);
this.props.editor.selectedRemoveIcon();
this.props.editor.activeRemoveIcon();
}
private getSegmentIconUrl(index: number): string {
@@ -640,12 +640,12 @@ export class RunEditor extends React.Component<Props, State> {
}
private handleSegmentNameChange(event: any) {
this.props.editor.selectedSetName(event.target.value);
this.props.editor.activeSetName(event.target.value);
this.update();
}
private handleSplitTimeChange(event: any) {
const valid = this.props.editor.selectedParseAndSetSplitTime(event.target.value);
const valid = this.props.editor.activeParseAndSetSplitTime(event.target.value);
const editor = {
...this.state.editor,
};
@@ -661,7 +661,7 @@ export class RunEditor extends React.Component<Props, State> {
}
private handleSegmentTimeChange(event: any) {
const valid = this.props.editor.selectedParseAndSetSegmentTime(event.target.value);
const valid = this.props.editor.activeParseAndSetSegmentTime(event.target.value);
const editor = {
...this.state.editor,
};
@@ -677,7 +677,7 @@ export class RunEditor extends React.Component<Props, State> {
}
private handleBestSegmentTimeChange(event: any) {
const valid = this.props.editor.selectedParseAndSetBestSegmentTime(event.target.value);
const valid = this.props.editor.activeParseAndSetBestSegmentTime(event.target.value);
const editor = {
...this.state.editor,
};
@@ -694,7 +694,7 @@ export class RunEditor extends React.Component<Props, State> {
private handleComparisonTimeChange(event: any, comparisonIndex: number) {
const comparisonName = this.state.editor.comparison_names[comparisonIndex];
const valid = this.props.editor.selectedParseAndSetComparisonTime(comparisonName, event.target.value);
const valid = this.props.editor.activeParseAndSetComparisonTime(comparisonName, event.target.value);
const editor = {
...this.state.editor,
};