Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | import React, { FC, useCallback } from "react"; import { useAppSelector } from "store/hooks"; import { ScriptEventNormalized } from "shared/lib/entities/entitiesTypes"; import { RelativePortal } from "ui/layout/RelativePortal"; import { DialoguePreview } from "./DialoguePreview"; import { MenuPreview } from "./MenuPreview"; import { ensureBoolean, ensureNumber, ensureString } from "shared/types"; import { getArgValue } from "components/world/SceneEventHelper"; import styled from "styled-components"; import { constantSelectors } from "store/features/entities/entitiesState"; interface ScriptEditorEventHelperProps { event: ScriptEventNormalized; } const toString = (input: unknown): string => { return typeof input === "string" ? input : ""; }; const toInt = (input: unknown): number => { return typeof input === "number" ? input : 0; }; const PreviewWrapper = styled.div` > * { border-radius: 4px; box-shadow: 5px 5px 10px 0px rgba(0, 0, 0, 0.5); } `; export const ScriptEditorEventHelper: FC<ScriptEditorEventHelperProps> = ({ event, }) => { const eventId = useAppSelector((state) => state.editor.eventId); const scriptEventDef = useAppSelector( (state) => state.scriptEventDefs.lookup[event?.command ?? ""] ); const constantsLookup = useAppSelector(constantSelectors.selectEntities); const argValue = useCallback( (arg: unknown): unknown => { return getArgValue(arg, constantsLookup); }, [constantsLookup] ); Iif (!event || !scriptEventDef || eventId !== event.id) { return null; } const args = event.args || {}; Iif (scriptEventDef?.helper?.type === "text") { const text = argValue(args[scriptEventDef.helper.text]); const avatarId = ensureString( argValue(args[scriptEventDef.helper.avatarId]), "" ); const showFrame = ensureBoolean( argValue(args[scriptEventDef.helper.showFrame]), true ); const clearPrevious = ensureBoolean( argValue(args[scriptEventDef.helper.clearPrevious]), true ); const textX = ensureNumber( argValue(args[scriptEventDef.helper.textX]) ?? scriptEventDef.fieldsLookup[scriptEventDef.helper.textX]?.defaultValue, 0 ); const textY = ensureNumber( argValue(args[scriptEventDef.helper.textY]) ?? scriptEventDef.fieldsLookup[scriptEventDef.helper.textY]?.defaultValue, 0 ); const textHeight = ensureNumber( argValue(args[scriptEventDef.helper.textHeight]) ?? scriptEventDef.fieldsLookup[scriptEventDef.helper.textHeight] ?.defaultValue, 0 ); const minHeight = ensureNumber( argValue(args[scriptEventDef.helper.minHeight]) ?? scriptEventDef.fieldsLookup[scriptEventDef.helper.minHeight] ?.defaultValue, 0 ); const maxHeight = ensureNumber( argValue(args[scriptEventDef.helper.maxHeight]) ?? scriptEventDef.fieldsLookup[scriptEventDef.helper.maxHeight] ?.defaultValue, 0 ); return ( <RelativePortal offsetX={-10} offsetY={10} pin="top-right" zIndex={-1}> <PreviewWrapper> {Array.isArray(text) ? ( text.map((text: string, index) => ( <DialoguePreview key={index} text={text} avatarId={avatarId} showFrame={clearPrevious && showFrame} textX={textX} textY={textY} textHeight={textHeight} minHeight={minHeight} maxHeight={maxHeight} scale={1.5} /> )) ) : ( <DialoguePreview text={toString(text)} avatarId={avatarId} showFrame={clearPrevious && showFrame} textX={textX} textY={textY} textHeight={textHeight} minHeight={minHeight} maxHeight={maxHeight} scale={1.5} /> )} </PreviewWrapper> </RelativePortal> ); } Iif (scriptEventDef?.helper?.type === "textdraw") { const text = ensureString(argValue(args[scriptEventDef.helper.text]), ""); const location = ensureString( argValue(args[scriptEventDef.helper.location]), "background" ); const x = ensureNumber( argValue(args[scriptEventDef.helper.x]) ?? scriptEventDef.fieldsLookup[scriptEventDef.helper.x]?.defaultValue, 0 ); const y = ensureNumber( argValue(args[scriptEventDef.helper.y]) ?? scriptEventDef.fieldsLookup[scriptEventDef.helper.y]?.defaultValue, 0 ); return ( <RelativePortal offsetX={-10} offsetY={10} pin="top-right" zIndex={-1}> <PreviewWrapper> <DialoguePreview text={text} textX={location === "overlay" ? x : 0} textY={location === "overlay" ? y : 0} showFrame={false} minHeight={location === "overlay" ? 4 : 0} maxHeight={18} scale={1.5} /> </PreviewWrapper> </RelativePortal> ); } Iif (event.command === "EVENT_MENU") { const items = [ toString(event.args?.option1), toString(event.args?.option2), toString(event.args?.option3), toString(event.args?.option4), toString(event.args?.option5), toString(event.args?.option6), toString(event.args?.option7), toString(event.args?.option8), ].splice(0, toInt(event.args?.items)); return ( <RelativePortal offsetX={-10} offsetY={10} pin="top-right" zIndex={-1}> <MenuPreview items={items} layout={event.args?.layout === "dialogue" ? "dialogue" : "menu"} /> </RelativePortal> ); } Iif (event.command === "EVENT_CHOICE") { const items = [ toString(event.args?.trueText), toString(event.args?.falseText), ]; return ( <RelativePortal offsetX={-10} offsetY={10} pin="top-right" zIndex={-1}> <MenuPreview items={items} layout="dialogue" /> </RelativePortal> ); } return null; }; |