Skip to content

Commit aca63a2

Browse files
committed
Fix panel inheritance
1 parent 49d0752 commit aca63a2

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ClassFunction, Enum, Function, HookFunction, LibraryFunction, PanelFunction, Realm, Struct, WikiPage } from '../scrapers/wiki-page-markup-scraper.js';
1+
import { ClassFunction, Enum, Function, HookFunction, LibraryFunction, Panel, PanelFunction, Realm, Struct, WikiPage, isPanel } from '../scrapers/wiki-page-markup-scraper.js';
22
import { putCommentBeforeEachLine, removeNewlines, toLowerCamelCase } from '../utils/string.js';
33
import {
44
isClassFunction,
@@ -83,6 +83,8 @@ export class GluaApiWriter {
8383
return this.writeLibraryFunction(page);
8484
else if (isHookFunction(page))
8585
return this.writeHookFunction(page);
86+
else if (isPanel(page))
87+
return this.writePanel(page);
8688
else if (isPanelFunction(page))
8789
return this.writePanelFunction(page);
8890
else if (isEnum(page))
@@ -150,8 +152,12 @@ export class GluaApiWriter {
150152
return this.writeClassFunction(func);
151153
}
152154

155+
private writePanel(panel: Panel) {
156+
return this.writeClass(panel.name, panel.parent);
157+
}
158+
153159
private writePanelFunction(func: PanelFunction) {
154-
let api: string = this.writeClass(func.parent, 'Panel');
160+
let api: string = '';
155161

156162
api += this.writeFunctionLuaDocComment(func, func.realm);
157163
api += this.writeFunctionDeclaration(func, func.realm, ':');

src/scrapers/wiki-page-markup-scraper.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export type WikiFunctionType = 'panelfunc' | 'classfunc' | 'libraryfunc' | 'hook
55
export type Realm = 'Menu' | 'Client' | 'Server' | 'Shared' | 'Client and menu';
66

77
export type CommonWikiProperties = {
8-
type: WikiFunctionType | 'enum' | 'struct';
8+
type: WikiFunctionType | 'enum' | 'struct' | 'panel';
99
address: string;
1010
name: string;
1111
description: string;
@@ -43,7 +43,7 @@ export type HookFunction = Function & {
4343

4444
export type PanelFunction = Function & {
4545
type: 'panelfunc';
46-
isPanel: 'yes';
46+
isPanelFunction: 'yes';
4747
};
4848

4949
export type EnumValue = {
@@ -69,7 +69,12 @@ export type Struct = CommonWikiProperties & {
6969
fields: StructField[];
7070
};
7171

72-
export type WikiPage = ClassFunction | LibraryFunction | HookFunction | PanelFunction | Enum | Struct;
72+
export type Panel = CommonWikiProperties & {
73+
type: 'panel';
74+
parent: string;
75+
};
76+
77+
export type WikiPage = ClassFunction | LibraryFunction | HookFunction | PanelFunction | Panel | Enum | Struct;
7378

7479
/**
7580
* Guards
@@ -90,6 +95,10 @@ export function isPanelFunction(page: WikiPage): page is PanelFunction {
9095
return page.type === 'panelfunc';
9196
}
9297

98+
export function isPanel(page: WikiPage): page is Panel {
99+
return page.type === 'panel';
100+
}
101+
93102
export function isEnum(page: WikiPage): page is Enum {
94103
return page.type === 'enum';
95104
}
@@ -114,13 +123,14 @@ export class WikiPageMarkupScraper extends Scraper<WikiPage> {
114123
const isEnum = $('enum').length > 0;
115124
const isStruct = $('structure').length > 0;
116125
const isFunction = $('function').length > 0;
117-
const mainElement = $(isEnum ? 'enum' : isStruct ? 'struct' : 'function').first();
126+
const isPanel = $('panel').length > 0;
127+
const mainElement = $(isEnum ? 'enum' : isStruct ? 'struct' : isPanel ? 'panel' : 'function');
118128
const address = response.url.split('/').pop()!.split('?')[0];
119129

120130
if (isEnum) {
121-
const items = $('items item').map(function() {
131+
const items = $('items item').map(function () {
122132
const $el = $(this);
123-
return <EnumValue> {
133+
return <EnumValue>{
124134
key: $el.attr('key')!,
125135
value: $el.attr('value')!,
126136
description: $el.text()
@@ -136,9 +146,9 @@ export class WikiPageMarkupScraper extends Scraper<WikiPage> {
136146
items
137147
};
138148
} else if (isStruct) {
139-
const fields = $('fields item').map(function() {
149+
const fields = $('fields item').map(function () {
140150
const $el = $(this);
141-
return <StructField> {
151+
return <StructField>{
142152
name: $el.attr('name')!,
143153
type: $el.attr('type')!,
144154
default: $el.attr('default'),
@@ -154,6 +164,15 @@ export class WikiPageMarkupScraper extends Scraper<WikiPage> {
154164
realm: $('realm').text() as Realm,
155165
fields
156166
};
167+
} else if (isPanel) {
168+
return <Panel>{
169+
type: 'panel',
170+
name: address,
171+
address: address,
172+
description: $('description').text(),
173+
realm: $('realm').text() as Realm,
174+
parent: $('parent').text()
175+
};
157176
} else if (isFunction) {
158177
const isClassFunction = mainElement.attr('type') === 'classfunc';
159178
const isLibraryFunction = mainElement.attr('type') === 'libraryfunc';
@@ -219,7 +238,7 @@ export class WikiPageMarkupScraper extends Scraper<WikiPage> {
219238
return <PanelFunction> {
220239
...base,
221240
type: 'panelfunc',
222-
isPanel: 'yes'
241+
isPanelFunction: 'yes'
223242
};
224243
}
225244
}

0 commit comments

Comments
 (0)