Skip to content

Commit e23dd5d

Browse files
committed
Correct enumerations
1 parent 224d214 commit e23dd5d

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/api-writer/glua-api-writer.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,24 +146,40 @@ export class GluaApiWriter {
146146

147147
private writeEnum(_enum: Enum) {
148148
let api: string = '';
149+
const isContainedInTable = _enum.items[0]?.key.includes('.') ?? false;
149150

150151
api += `---@enum ${_enum.name}\n`;
151-
api += `local ${_enum.name} = {\n`;
152+
153+
if (isContainedInTable)
154+
api += `local ${_enum.name} = {\n`;
155+
156+
const writeItem = (key: string, item: typeof _enum.items[0]) => {
157+
if (isContainedInTable) {
158+
key = key.split('.')[1];
159+
api += ` ${key} = ${item.value}, ` + (item.description ? `--[[ ${item.description} ]]` : '') + '\n';
160+
} else {
161+
const comment = item.description ? `${putCommentBeforeEachLine(item.description, false)}\n` : '';
162+
api += `${comment}${key} = ${item.value}\n`;
163+
}
164+
};
152165

153166
for (const item of _enum.items) {
154-
const key = item.key.split('.')[1] ?? item.key; // Fixes ENUMNAME.KEY (ENUMNAME is redundant here)
155167
const keys = item.key.split(' or ');
156168

157169
if (keys.length > 1) {
170+
console.warn(`Enum item ${item.key} has multiple keys. This is not supported by the Glua API.`);
158171
for (const key of keys) {
159-
api += ` ${key} = ${item.value}, ` + (item.description ? `--[[ ${item.description} ]]` : '') + '\n';
172+
writeItem(key, item);
160173
}
161174
} else {
162-
api += ` ${key} = ${item.value}, ` + (item.description ? `--[[ ${item.description} ]]` : '') + '\n';
175+
writeItem(item.key, item);
163176
}
164177
}
165178

166-
api += '}\n\n';
179+
if (isContainedInTable)
180+
api += '}';
181+
182+
api += `\n\n`;
167183

168184
return api;
169185
}

0 commit comments

Comments
 (0)