phantasmal-world/src/ui/quest_editor/QuestEditorComponent.tsx

45 lines
1.7 KiB
TypeScript
Raw Normal View History

import { observer } from "mobx-react";
import React, { Component, ReactNode } from "react";
import { get_quest_renderer } from "../../rendering/QuestRenderer";
import { application_store } from "../../stores/ApplicationStore";
import { quest_editor_store } from "../../stores/QuestEditorStore";
import { RendererComponent } from "../RendererComponent";
import { EntityInfoComponent } from "./EntityInfoComponent";
import "./QuestEditorComponent.css";
import { QuestInfoComponent } from "./QuestInfoComponent";
import { Toolbar } from "./Toolbar";
@observer
export class QuestEditorComponent extends Component<{}, { debug: boolean }> {
state = { debug: false };
2019-07-18 21:39:23 +08:00
componentDidMount(): void {
application_store.on_global_keyup("quest_editor", this.keyup);
}
2019-07-03 02:56:33 +08:00
render(): ReactNode {
const quest = quest_editor_store.current_quest;
return (
<div className="qe-QuestEditorComponent">
<Toolbar />
<div className="qe-QuestEditorComponent-main">
<QuestInfoComponent quest={quest} />
<RendererComponent renderer={get_quest_renderer()} debug={this.state.debug} />
<EntityInfoComponent entity={quest_editor_store.selected_entity} />
</div>
</div>
);
}
2019-07-18 21:39:23 +08:00
private keyup = (e: KeyboardEvent) => {
if (e.ctrlKey && e.key === "z" && !e.altKey) {
quest_editor_store.undo_stack.undo();
} else if (e.ctrlKey && e.key === "Z" && !e.altKey) {
quest_editor_store.undo_stack.redo();
} else if (e.ctrlKey && e.altKey && e.key === "d") {
this.setState(state => ({ debug: !state.debug }));
2019-07-18 21:39:23 +08:00
}
};
}