feat: migrate to turbo (#22)
* feat: migrate top turbo * ci: ci test * fix: fix codeql issues * feat: ci test * chore: lint * chore: misc changes * feat: rename vite helpers * feat: use fetch to handle assets * feat: update directory * feat: fetch charword table * feat: migrate download game data and detect missing voice files * feat: symlink relative path * feat: finish wrangler upload * feat: migrate wrangler download * feat: finish * chore: auto update * ci: update ci * ci: update ci --------- Co-authored-by: Halyul <Halyul@users.noreply.github.com>
This commit is contained in:
68
packages/project-json/libs/content_processor.js
Normal file
68
packages/project-json/libs/content_processor.js
Normal file
@@ -0,0 +1,68 @@
|
||||
export default class Matcher {
|
||||
#start
|
||||
#end
|
||||
#reExp
|
||||
#config
|
||||
#assets
|
||||
|
||||
constructor(start, end, config, assets) {
|
||||
this.#start = start
|
||||
this.#end = end
|
||||
this.#reExp = new RegExp(`${start}.+?${end}`, 'g')
|
||||
this.#config = config
|
||||
this.#assets = assets
|
||||
}
|
||||
|
||||
get result() {
|
||||
const matches = this.content.match(this.#reExp)
|
||||
if (matches !== null) {
|
||||
matches.forEach((match) => {
|
||||
const name = match
|
||||
.replace(this.#start, '')
|
||||
.replace(this.#end, '')
|
||||
const result = new Function(
|
||||
'Evalable',
|
||||
'config',
|
||||
'assets',
|
||||
`return new Evalable(config, assets).${name}`
|
||||
)(Evalable, this.#config, this.#assets)
|
||||
this.content =
|
||||
matches.length > 1
|
||||
? this.content.replace(match, result)
|
||||
: result
|
||||
})
|
||||
}
|
||||
return this.content
|
||||
}
|
||||
}
|
||||
|
||||
class Evalable {
|
||||
#config
|
||||
#assets
|
||||
|
||||
constructor(config, assets) {
|
||||
this.#config = config
|
||||
this.#assets = assets
|
||||
}
|
||||
|
||||
split(location, varName, separator) {
|
||||
return this.#step(location, varName).split(separator)
|
||||
}
|
||||
|
||||
var(location, varName) {
|
||||
return this.#step(location, varName)
|
||||
}
|
||||
|
||||
#step(location, varName) {
|
||||
let content = this.#config
|
||||
if (location === 'assets') content = this.#assets
|
||||
varName.split('->').forEach((item) => {
|
||||
try {
|
||||
content = content[item]
|
||||
} catch (e) {
|
||||
throw new Error(`Cannot step ${varName}.`, e)
|
||||
}
|
||||
})
|
||||
return content
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user