-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
59 additions
and
117 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { BaseBuilder } from './baseBuilder'; | ||
import * as y3 from 'y3-helper'; | ||
|
||
const template = | ||
`---@alias py.%{NAME}KeyEnum integer | ||
%{KEYS} | ||
`; | ||
|
||
export class Objects extends BaseBuilder { | ||
constructor(path: string) { | ||
super(path); | ||
this.update(); | ||
y3.env.onDidChange(() => { | ||
this.update(); | ||
this.updateTables(); | ||
}); | ||
} | ||
|
||
private tables: Map<y3.consts.Table.NameCN, y3.table.EditorTable> = new Map(); | ||
private updateTables() { | ||
for (let key in y3.consts.Table.name.fromCN) { | ||
let name = key as y3.consts.Table.NameCN; | ||
let current = this.tables.get(name); | ||
if (!current) { | ||
let table = y3.table.openTable(name); | ||
this.tables.set(name, table); | ||
table.onDidChange(() => { | ||
this.update(); | ||
this.updateTables(); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
private async makeOne(table: y3.table.EditorTable) { | ||
let keyList = await table.getList(); | ||
let enName = y3.consts.Table.name.fromCN[table.name]; | ||
let text = template | ||
. replace('%{NAME}', enName[0].toUpperCase() + enName.slice(1)) | ||
. replace('%{KEYS}', keyList.map((key) => { | ||
return `---| ${key}`; | ||
}).join('\r\n')); | ||
return text; | ||
} | ||
|
||
async make() { | ||
let texts = await Promise.all( | ||
Array.from(this.tables.values()).map((table) => { | ||
return this.makeOne(table); | ||
}) | ||
); | ||
return texts.join('\r\n'); | ||
} | ||
|
||
} |