WIP - add extractor, generate snippet_data

This commit is contained in:
Stefan Fejes
2019-08-20 15:52:05 +02:00
parent 88084d3d30
commit cc8f1d8a7a
37396 changed files with 4588842 additions and 133 deletions

56
node_modules/parse-bmfont-ascii/README.md generated vendored Normal file
View File

@ -0,0 +1,56 @@
# parse-bmfont-ascii
[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)
Parses ASCII (text) [BMFont files](http://www.angelcode.com/products/bmfont/).
Takes a string or Buffer:
```js
var fs = require('fs')
var parse = require('parse-bmfont-xml')
fs.readFileSync(__dirname+'/Arial.fnt', function(err, data) {
var result = parse(data)
console.log(result.info.face) // "Arial"
console.log(result.pages) // [ 'sheet0.png' ]
console.log(result.chars) // [ ... char data ... ]
console.log(result.kernings) // [ ... kernings data ... ]
})
```
The spec for the returned JSON object is [here](https://github.com/mattdesl/bmfont2json/wiki/JsonSpec). The input data should match the spec, see [test/Nexa Light-32.fnt](test/Nexa Light-32.fnt) for an example.
## See Also
See [text-modules](https://github.com/mattdesl/text-modules) for related modules.
## Usage
[![NPM](https://nodei.co/npm/parse-bmfont-ascii.png)](https://www.npmjs.com/package/parse-bmfont-ascii)
#### `result = parse(data)`
Parses `data`, a string or Buffer that represents ASCII (text) data of an AngelCode BMFont file. The returned `result` object looks like this:
```js
{
pages: [
"sheet_0.png",
"sheet_1.png"
],
chars: [
{ chnl, height, id, page, width, x, y, xoffset, yoffset, xadvance },
...
],
info: { ... },
common: { ... },
kernings: [
{ first, second, amount }
]
}
```
## License
MIT, see [LICENSE.md](http://github.com/mattdesl/parse-bmfont-ascii/blob/master/LICENSE.md) for details.

108
node_modules/parse-bmfont-ascii/index.js generated vendored Normal file
View File

@ -0,0 +1,108 @@
module.exports = function parseBMFontAscii(data) {
if (!data)
throw new Error('no data provided')
data = data.toString().trim()
var output = {
pages: [],
chars: [],
kernings: []
}
var lines = data.split(/\r\n?|\n/g)
if (lines.length === 0)
throw new Error('no data in BMFont file')
for (var i = 0; i < lines.length; i++) {
var lineData = splitLine(lines[i], i)
if (!lineData) //skip empty lines
continue
if (lineData.key === 'page') {
if (typeof lineData.data.id !== 'number')
throw new Error('malformed file at line ' + i + ' -- needs page id=N')
if (typeof lineData.data.file !== 'string')
throw new Error('malformed file at line ' + i + ' -- needs page file="path"')
output.pages[lineData.data.id] = lineData.data.file
} else if (lineData.key === 'chars' || lineData.key === 'kernings') {
//... do nothing for these two ...
} else if (lineData.key === 'char') {
output.chars.push(lineData.data)
} else if (lineData.key === 'kerning') {
output.kernings.push(lineData.data)
} else {
output[lineData.key] = lineData.data
}
}
return output
}
function splitLine(line, idx) {
line = line.replace(/\t+/g, ' ').trim()
if (!line)
return null
var space = line.indexOf(' ')
if (space === -1)
throw new Error("no named row at line " + idx)
var key = line.substring(0, space)
line = line.substring(space + 1)
//clear "letter" field as it is non-standard and
//requires additional complexity to parse " / = symbols
line = line.replace(/letter=[\'\"]\S+[\'\"]/gi, '')
line = line.split("=")
line = line.map(function(str) {
return str.trim().match((/(".*?"|[^"\s]+)+(?=\s*|\s*$)/g))
})
var data = []
for (var i = 0; i < line.length; i++) {
var dt = line[i]
if (i === 0) {
data.push({
key: dt[0],
data: ""
})
} else if (i === line.length - 1) {
data[data.length - 1].data = parseData(dt[0])
} else {
data[data.length - 1].data = parseData(dt[0])
data.push({
key: dt[1],
data: ""
})
}
}
var out = {
key: key,
data: {}
}
data.forEach(function(v) {
out.data[v.key] = v.data;
})
return out
}
function parseData(data) {
if (!data || data.length === 0)
return ""
if (data.indexOf('"') === 0 || data.indexOf("'") === 0)
return data.substring(1, data.length - 1)
if (data.indexOf(',') !== -1)
return parseIntList(data)
return parseInt(data, 10)
}
function parseIntList(data) {
return data.split(',').map(function(val) {
return parseInt(val, 10)
})
}

70
node_modules/parse-bmfont-ascii/package.json generated vendored Normal file
View File

@ -0,0 +1,70 @@
{
"_from": "parse-bmfont-ascii@^1.0.3",
"_id": "parse-bmfont-ascii@1.0.6",
"_inBundle": false,
"_integrity": "sha1-Eaw8P/WPfCAgqyJ2kHkQjU36AoU=",
"_location": "/parse-bmfont-ascii",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "parse-bmfont-ascii@^1.0.3",
"name": "parse-bmfont-ascii",
"escapedName": "parse-bmfont-ascii",
"rawSpec": "^1.0.3",
"saveSpec": null,
"fetchSpec": "^1.0.3"
},
"_requiredBy": [
"/load-bmfont"
],
"_resolved": "https://registry.npmjs.org/parse-bmfont-ascii/-/parse-bmfont-ascii-1.0.6.tgz",
"_shasum": "11ac3c3ff58f7c2020ab22769079108d4dfa0285",
"_spec": "parse-bmfont-ascii@^1.0.3",
"_where": "/Users/stefanfejes/Projects/30-seconds-of-python-code/node_modules/load-bmfont",
"author": {
"name": "Matt DesLauriers",
"email": "dave.des@gmail.com",
"url": "https://github.com/mattdesl"
},
"bugs": {
"url": "https://github.com/mattdesl/parse-bmfont-ascii/issues"
},
"bundleDependencies": false,
"dependencies": {},
"deprecated": false,
"description": "parses ASCII BMFont files to a JavaScript object",
"devDependencies": {
"tape": "^3.5.0"
},
"homepage": "https://github.com/mattdesl/parse-bmfont-ascii",
"keywords": [
"ascii",
"parse",
"convert",
"bmfont",
"bm",
"bitmap",
"font",
"bitmaps",
"angel",
"angelcode",
"code",
"text",
"gl",
"sprite",
"sprites",
"stackgl"
],
"license": "MIT",
"main": "index.js",
"name": "parse-bmfont-ascii",
"repository": {
"type": "git",
"url": "git://github.com/mattdesl/parse-bmfont-ascii.git"
},
"scripts": {
"test": "node test/test.js"
},
"version": "1.0.6"
}