mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-11 23:24:43 +02:00
ENiGMA 1/2 WILL USE SPACES FROM THIS POINT ON VS TABS
* Really just to make GitHub formatting happy. Arg.
This commit is contained in:
parent
5ddf04c882
commit
e9787cee3e
135 changed files with 27397 additions and 27397 deletions
138
core/asset.js
138
core/asset.js
|
@ -18,111 +18,111 @@ exports.resolveSystemStatAsset = resolveSystemStatAsset;
|
|||
exports.getViewPropertyAsset = getViewPropertyAsset;
|
||||
|
||||
const ALL_ASSETS = [
|
||||
'art',
|
||||
'menu',
|
||||
'method',
|
||||
'userModule',
|
||||
'systemMethod',
|
||||
'systemModule',
|
||||
'prompt',
|
||||
'config',
|
||||
'sysStat',
|
||||
'art',
|
||||
'menu',
|
||||
'method',
|
||||
'userModule',
|
||||
'systemMethod',
|
||||
'systemModule',
|
||||
'prompt',
|
||||
'config',
|
||||
'sysStat',
|
||||
];
|
||||
|
||||
const ASSET_RE = new RegExp('\\@(' + ALL_ASSETS.join('|') + ')\\:([\\w\\d\\.]*)(?:\\/([\\w\\d\\_]+))*');
|
||||
|
||||
function parseAsset(s) {
|
||||
const m = ASSET_RE.exec(s);
|
||||
const m = ASSET_RE.exec(s);
|
||||
|
||||
if(m) {
|
||||
let result = { type : m[1] };
|
||||
if(m) {
|
||||
let result = { type : m[1] };
|
||||
|
||||
if(m[3]) {
|
||||
result.location = m[2];
|
||||
result.asset = m[3];
|
||||
} else {
|
||||
result.asset = m[2];
|
||||
}
|
||||
if(m[3]) {
|
||||
result.location = m[2];
|
||||
result.asset = m[3];
|
||||
} else {
|
||||
result.asset = m[2];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
function getAssetWithShorthand(spec, defaultType) {
|
||||
if(!_.isString(spec)) {
|
||||
return null;
|
||||
}
|
||||
if(!_.isString(spec)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if('@' === spec[0]) {
|
||||
const asset = parseAsset(spec);
|
||||
assert(_.isString(asset.type));
|
||||
if('@' === spec[0]) {
|
||||
const asset = parseAsset(spec);
|
||||
assert(_.isString(asset.type));
|
||||
|
||||
return asset;
|
||||
}
|
||||
return asset;
|
||||
}
|
||||
|
||||
return {
|
||||
type : defaultType,
|
||||
asset : spec,
|
||||
};
|
||||
return {
|
||||
type : defaultType,
|
||||
asset : spec,
|
||||
};
|
||||
}
|
||||
|
||||
function getArtAsset(spec) {
|
||||
const asset = getAssetWithShorthand(spec, 'art');
|
||||
const asset = getAssetWithShorthand(spec, 'art');
|
||||
|
||||
if(!asset) {
|
||||
return null;
|
||||
}
|
||||
if(!asset) {
|
||||
return null;
|
||||
}
|
||||
|
||||
assert( ['art', 'method' ].indexOf(asset.type) > -1);
|
||||
return asset;
|
||||
assert( ['art', 'method' ].indexOf(asset.type) > -1);
|
||||
return asset;
|
||||
}
|
||||
|
||||
function getModuleAsset(spec) {
|
||||
const asset = getAssetWithShorthand(spec, 'systemModule');
|
||||
const asset = getAssetWithShorthand(spec, 'systemModule');
|
||||
|
||||
if(!asset) {
|
||||
return null;
|
||||
}
|
||||
if(!asset) {
|
||||
return null;
|
||||
}
|
||||
|
||||
assert( ['userModule', 'systemModule' ].includes(asset.type) );
|
||||
assert( ['userModule', 'systemModule' ].includes(asset.type) );
|
||||
|
||||
return asset;
|
||||
return asset;
|
||||
}
|
||||
|
||||
function resolveConfigAsset(spec) {
|
||||
const asset = parseAsset(spec);
|
||||
if(asset) {
|
||||
assert('config' === asset.type);
|
||||
const asset = parseAsset(spec);
|
||||
if(asset) {
|
||||
assert('config' === asset.type);
|
||||
|
||||
const path = asset.asset.split('.');
|
||||
let conf = Config();
|
||||
for(let i = 0; i < path.length; ++i) {
|
||||
if(_.isUndefined(conf[path[i]])) {
|
||||
return spec;
|
||||
}
|
||||
conf = conf[path[i]];
|
||||
}
|
||||
return conf;
|
||||
} else {
|
||||
return spec;
|
||||
}
|
||||
const path = asset.asset.split('.');
|
||||
let conf = Config();
|
||||
for(let i = 0; i < path.length; ++i) {
|
||||
if(_.isUndefined(conf[path[i]])) {
|
||||
return spec;
|
||||
}
|
||||
conf = conf[path[i]];
|
||||
}
|
||||
return conf;
|
||||
} else {
|
||||
return spec;
|
||||
}
|
||||
}
|
||||
|
||||
function resolveSystemStatAsset(spec) {
|
||||
const asset = parseAsset(spec);
|
||||
if(!asset) {
|
||||
return spec;
|
||||
}
|
||||
const asset = parseAsset(spec);
|
||||
if(!asset) {
|
||||
return spec;
|
||||
}
|
||||
|
||||
assert('sysStat' === asset.type);
|
||||
assert('sysStat' === asset.type);
|
||||
|
||||
return StatLog.getSystemStat(asset.asset) || spec;
|
||||
return StatLog.getSystemStat(asset.asset) || spec;
|
||||
}
|
||||
|
||||
function getViewPropertyAsset(src) {
|
||||
if(!_.isString(src) || '@' !== src.charAt(0)) {
|
||||
return null;
|
||||
}
|
||||
if(!_.isString(src) || '@' !== src.charAt(0)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return parseAsset(src);
|
||||
return parseAsset(src);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue