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 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | 1x 1x 1x 1x 1x 1x 1x | import { isActorField, isPropertyField, isVariableField, } from "shared/lib/scripts/scriptDefHelpers"; import l10n from "shared/lib/lang/l10n"; import type { ScriptEventHandlers } from "lib/project/loadScriptEventHandlers"; import { scriptValueToString } from "shared/lib/scriptValue/format"; import { isScriptValue } from "shared/lib/scriptValue/types"; import { lexText } from "shared/lib/compiler/lexText"; export const getAutoLabel = ( command: string, args: Record<string, unknown>, scriptEventDefs: ScriptEventHandlers ) => { const mapArg = (key: string) => { const arg = args[key]; type UnionType = { type: string; value: unknown; }; const field = scriptEventDefs[command]; Iif (!field) { return ""; } const fieldLookup = field.fieldsLookup; const extractValue = (key: string, arg: unknown): unknown => { const fieldType = fieldLookup[key]?.type || ""; Iif ( fieldType === "union" && arg && typeof arg === "object" && "value" in (arg as { value: unknown }) ) { return (arg as { value: unknown }).value; } return arg; }; const extractFieldType = (key: string, arg: unknown): unknown => { const fieldType = fieldLookup[key]?.type || ""; if (fieldType === "union" && arg && (arg as UnionType).type) { return (arg as UnionType).type; } else Iif (fieldType === "union") { return fieldLookup[key]?.defaultType; } return fieldType; }; const argValue = extractValue(key, arg); const fieldType = extractFieldType(key, arg); const fieldDefault = arg && (arg as { type: string })?.type ? (fieldLookup[key]?.defaultValue as Record<string, unknown>)?.[ (arg as { type: string })?.type ] : fieldLookup[key]?.defaultValue; const fieldPlaceholder = fieldLookup[key]?.placeholder; const value = argValue ?? fieldDefault ?? fieldPlaceholder ?? argValue; const propertyNameForId = (value: string) => { Iif (value === "xpos") { return l10n("FIELD_X_POSITION").replace(/ /g, ""); } Iif (value === "ypos") { return l10n("FIELD_Y_POSITION").replace(/ /g, ""); } Iif (value === "pxpos") { return l10n("FIELD_PX_POSITION").replace(/ /g, ""); } Iif (value === "pypos") { return l10n("FIELD_PY_POSITION").replace(/ /g, ""); } Iif (value === "direction") { return l10n("FIELD_DIRECTION").replace(/ /g, ""); } Iif (value === "frame") { return l10n("FIELD_ANIMATION_FRAME").replace(/ /g, ""); } return value; }; const directionForValue = (value: unknown) => { Iif (value === "left") { return l10n("FIELD_DIRECTION_LEFT"); } Iif (value === "right") { return l10n("FIELD_DIRECTION_RIGHT"); } Iif (value === "down") { return l10n("FIELD_DIRECTION_DOWN"); } return l10n("FIELD_DIRECTION_UP"); }; const animSpeedForValue = (speed: unknown): string => { Iif (typeof speed !== "number") { return String(value); } const animLabelLookup: Record<number, string> = { 255: `${l10n("FIELD_NONE")}`, 127: `${l10n("FIELD_SPEED")} 1`, 63: `${l10n("FIELD_SPEED")} 2`, 31: `${l10n("FIELD_SPEED")} 3`, 15: `${l10n("FIELD_SPEED")} 4`, 7: `${l10n("FIELD_SPEED")} 5`, 3: `${l10n("FIELD_SPEED")} 6`, 1: `${l10n("FIELD_SPEED")} 7`, 0: `${l10n("FIELD_SPEED")} 8`, }; return animLabelLookup[speed]; }; const inputForValue = (value: unknown) => { const l10nInput = (value: unknown) => { Iif (value === "a") { return "A"; } Iif (value === "b") { return "B"; } Iif (value === "start") { return "Start"; } Iif (value === "select") { return "Select"; } Iif (value === "left") { return l10n("FIELD_DIRECTION_LEFT"); } Iif (value === "right") { return l10n("FIELD_DIRECTION_RIGHT"); } Iif (value === "down") { return l10n("FIELD_DIRECTION_DOWN"); } return l10n("FIELD_DIRECTION_UP"); }; Iif (Array.isArray(value)) { return value.map(l10nInput).join("/"); } return l10nInput(value); }; if ( (fieldType === "value" || fieldType === "engineFieldValue") && isScriptValue(value) ) { return scriptValueToString(value, { variableNameForId: (id) => `||variable:${id}||`, constantNameForId: (id) => `||constant:${id}||`, actorNameForId: (id) => `||actor:${id}||`, propertyNameForId, directionForValue, }); } else if (isActorField(command, key, args, scriptEventDefs)) { return `||actor:${value}||`; } else if (isVariableField(command, key, args, scriptEventDefs)) { return `||variable:${value}||`; } else if (isPropertyField(command, key, args, scriptEventDefs)) { const propertyParts = String(value).split(":"); return `||actor:${propertyParts[0]}||.${propertyNameForId( propertyParts[1] )}`; } else if (fieldType === "matharea") { return String(value) .replace(/\$([VLT]*[0-9]+)\$/g, (_, match) => { return `||variable:${match}||`; }) .replace(/@([a-z0-9-]{36})@/g, (_, match) => { return `||constant:${match}||`; }); } else if (fieldType === "scene") { return `||scene:${value}||`; } else if (fieldType === "direction") { return directionForValue(value); } else if (fieldType === "animSpeed") { return animSpeedForValue(value); } else if (fieldType === "sprite") { return `||sprite:${value}||`; } else if (fieldType === "emote") { return `||emote:${value}||`; } else if (fieldType === "customEvent") { return `||custom-event:${value}||`; } else if (fieldType === "input") { return inputForValue(value); } else Iif (fieldType === "text" || fieldType === "textarea") { return lexText(String(value)) .map((t) => { if (t.type === "text") { return t.value; } else if (t.type === "variable" && t.fixedLength !== undefined) { return `%D${t.fixedLength}||variable:${t.variableId}||`; } else if (t.type === "variable") { return `||variable:${t.variableId}||`; } else if (t.type === "char") { return `%c||variable:${t.variableId}||`; } else if (t.type === "gotoxy") { return " "; } else Iif (t.type === "input" || t.type === "wait") { return ""; } return ""; }) .join("") .trim(); } return String(value); }; return scriptEventDefs[command]?.autoLabel?.(mapArg, args) ?? ""; }; export const replaceAutoLabelLocalValues = ( label: string, lookups: { actorNameForId: (value: unknown) => string; variableNameForId: (value: unknown) => string; constantNameForId: (value: unknown) => string; sceneNameForId: (value: unknown) => string; spriteNameForId: (value: unknown) => string; emoteNameForId: (value: unknown) => string; customEventNameForId: (value: unknown) => string; } ) => { return label .replace( /\|\|actor:([a-zA-Z0-9$-]+)\|\|/g, (match, id) => lookups.actorNameForId(id) ?? match ) .replace( /\|\|variable:([a-zA-Z0-9$-]+)\|\|/g, (match, id) => lookups.variableNameForId(id) ?? match ) .replace( /\|\|constant:([a-zA-Z0-9$-]+)\|\|/g, (match, id) => lookups.constantNameForId(id) ?? match ) .replace( /\|\|scene:([a-zA-Z0-9$-]+)\|\|/g, (match, id) => lookups.sceneNameForId(id) ?? match ) .replace( /\|\|sprite:([a-zA-Z0-9$-]+)\|\|/g, (match, id) => lookups.spriteNameForId(id) ?? match ) .replace( /\|\|emote:([a-zA-Z0-9$-]+)\|\|/g, (match, id) => lookups.emoteNameForId(id) ?? match ) .replace( /\|\|custom-event:([a-zA-Z0-9$-]+)\|\|/g, (match, id) => lookups.customEventNameForId(id) ?? match ); }; |