Skip to content

Commit 49d0752

Browse files
committed
fix vgui and color overrides (file case)
1 parent e23dd5d commit 49d0752

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

__tests__/api-writer/glua-api-writer.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('GLua API Writer', () => {
7373

7474
const api = writer.writePages([<WikiPage>hookJson]);
7575

76-
expect(api).toEqual(override);
76+
expect(api).toEqual(`${override}\n\n`);
7777
});
7878

7979
it('should allow overriding specific class declarations', () => {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
---@param g number An integer from `0-255` describing the green value of the color.
77
---@param b number An integer from `0-255` describing the blue value of the color.
88
---@param a number An integer from `0-255` describing the alpha (transparency) of the color.
9-
---@return Color #The created Color (is returned as a table without the Color metatable, [(See GitHub issue)](https://github.com/Facepunch/garrysmod-issues/issues/2407)).
9+
---@return Color #The created Color. Is returned as a table without the Color metatable, [(See GitHub issue)](https://github.com/Facepunch/garrysmod-issues/issues/2407).
1010
function _G.Color(r, g, b, a) end

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

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,18 @@ export class GluaApiWriter {
6666
}
6767

6868
public writePage(page: WikiPage) {
69-
if (this.pageOverrides.has(page.address))
70-
return this.pageOverrides.get(page.address);
71-
else if (isClassFunction(page))
69+
if (this.pageOverrides.has(page.address)) {
70+
let api = '';
71+
72+
if (isClassFunction(page))
73+
api += this.writeClass(page.parent);
74+
else if (isLibraryFunction(page))
75+
api += this.writeLibraryGlobal(page);
76+
77+
api += this.pageOverrides.get(page.address);
78+
79+
return `${api}\n\n`;
80+
} else if (isClassFunction(page))
7281
return this.writeClassFunction(page);
7382
else if (isLibraryFunction(page))
7483
return this.writeLibraryFunction(page);
@@ -107,6 +116,18 @@ export class GluaApiWriter {
107116
return api;
108117
}
109118

119+
private writeLibraryGlobal(func: LibraryFunction) {
120+
if (!func.dontDefineParent && !this.writtenLibraryGlobals.has(func.parent)) {
121+
const global = `${func.parent} = {}\n\n`;
122+
123+
this.writtenLibraryGlobals.add(func.parent);
124+
125+
return global;
126+
}
127+
128+
return '';
129+
}
130+
110131
private writeClassFunction(func: ClassFunction) {
111132
let api: string = this.writeClass(func.parent);
112133

@@ -117,13 +138,7 @@ export class GluaApiWriter {
117138
}
118139

119140
private writeLibraryFunction(func: LibraryFunction) {
120-
let api: string = '';
121-
122-
if (!func.dontDefineParent && !this.writtenLibraryGlobals.has(func.parent)) {
123-
api += `${func.parent} = {}\n\n`;
124-
125-
this.writtenLibraryGlobals.add(func.parent);
126-
}
141+
let api: string = this.writeLibraryGlobal(func);
127142

128143
api += this.writeFunctionLuaDocComment(func, func.realm);
129144
api += this.writeFunctionDeclaration(func, func.realm);

0 commit comments

Comments
 (0)