65 lines
1.4 KiB
JavaScript
65 lines
1.4 KiB
JavaScript
const fs = require('fs')
|
|
|
|
const mgcbFile = process.argv[2]
|
|
if (!mgcbFile) {
|
|
return 1
|
|
}
|
|
|
|
const fileContents = fs.readFileSync(mgcbFile, 'utf8')
|
|
/** @type string[] */
|
|
const lines = fileContents.split('\n')
|
|
|
|
/** @type {Object.<string, string[]>} */
|
|
const types = {}
|
|
|
|
lines.forEach(line => {
|
|
const prefix = '#begin '
|
|
if (!line.startsWith(prefix)) {
|
|
return
|
|
}
|
|
line = line.substring(prefix.length)
|
|
const [type, name] = line.split('/')
|
|
types[type] ??= []
|
|
types[type].push(name)
|
|
})
|
|
|
|
let imageIdTextureLoads = ''
|
|
let imageIdEnumString = ''
|
|
|
|
types['Images'].forEach(image => {
|
|
const [name, ext] = image.split('.')
|
|
imageIdTextureLoads += '\n '
|
|
imageIdTextureLoads += `content.Load<Texture2D>("Images/${name}"),`
|
|
|
|
imageIdEnumString += '\n '
|
|
imageIdEnumString += name[0].toUpperCase() + name.substring(1)
|
|
})
|
|
|
|
console.log(`
|
|
using System;
|
|
using Microsoft.Xna.Framework.Content;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
namespace MonoGameBlank2dStartKit.Core.Content;
|
|
|
|
public class Assets
|
|
{
|
|
private readonly Texture2D[] _images;
|
|
|
|
public Assets(ContentManager content)
|
|
{
|
|
var allImageIds = Enum.GetValues<ImageId>();
|
|
_images =
|
|
[${imageIdTextureLoads}
|
|
];
|
|
}
|
|
|
|
public Texture2D GetTexture2D(ImageId imageId)
|
|
{
|
|
return _images[(int)imageId];
|
|
}
|
|
}
|
|
|
|
public enum ImageId
|
|
{${imageIdEnumString}
|
|
}`) |