Commit 92272ac2 authored by Tt's avatar Tt

init

parent affb7c45
This diff is collapsed.
...@@ -28,11 +28,12 @@ ...@@ -28,11 +28,12 @@
"ali-oss": "^6.5.1", "ali-oss": "^6.5.1",
"compressing": "^1.5.0", "compressing": "^1.5.0",
"ng-zorro-antd": "^8.5.2", "ng-zorro-antd": "^8.5.2",
"node-sass": "^4.0.0",
"pinyin": "^4.0.0",
"rxjs": "~6.5.4", "rxjs": "~6.5.4",
"spark-md5": "^3.0.0", "spark-md5": "^3.0.0",
"tslib": "^1.10.0", "tslib": "^1.10.0",
"zone.js": "~0.10.2", "zone.js": "~0.10.2"
"node-sass": "^4.0.0"
}, },
"devDependencies": { "devDependencies": {
"@angular-devkit/build-angular": "~0.900.3", "@angular-devkit/build-angular": "~0.900.3",
......
/**
* 本地图片资源映射 - CommonJS版本
* 用于Node.js脚本中导入使用
*/
// 从原始resources.js文件中复制的内容
const localImages = {
'bg_green_small': 'assets/game/bg_green_small.png',
'bg_green_small_line': 'assets/game/bg_green_small_line.png',
'bg': 'assets/game/bg.jpg',
'bg_green': 'assets/game/bg_green.png',
'bg_green_line': 'assets/game/bg_greenline.png',
'bg_title': 'assets/game/bg_title.png',
'bg_white': 'assets/game/bg_white.png',
'bg_white_line': 'assets/game/bg_whiteline.png',
'bg_yellow': 'assets/game/bg_yellow.png',
'bg_yellow_small': 'assets/game/bg_yellow_small.png',
'bg_yellow_small_line': 'assets/game/bg_yellow_small_line.png',
'bg_yellow_line': 'assets/game/bg_yellowline.png',
'btn_return': 'assets/game/btn_return.png',
'bg_1280_720_Ruler': "assets/default/images/1280_720_Ruler.png",
'bg-240-180': 'assets/default/images/bg-240-180.png',
'bg-453-251': 'assets/default/images/bg-453-251.png',
'bg_500_600': "assets/default/images/bg_500_600.png",
'bg_1280_222': "assets/default/images/bg_1280_222.png",
'bg_1280_720': "assets/default/images/bg_1280_222.png",
'petal_1': "assets/default/images/scrap-pic-1.png",
'petal_2': "assets/default/images/scrap-pic-2.png",
'petal_3': "assets/default/images/scrap-pic-3.png",
'star': "assets/default/images/star.png",
'flag': "assets/default/images/flag.png",
'1': "assets/play/1.png",
'1-2': "assets/play/1-2.png",
'1-3': "assets/play/1-3.png",
'background': "assets/play/background.png",
'grass-left': "assets/play/grass-left.png",
'grass-right': "assets/play/grass-right.png",
'grass-mid-1': "assets/play/grass-mid-1.png",
'grass-mid-2': "assets/play/grass-mid-2.png",
'grass-mid-3': "assets/play/grass-mid-3.png",
'6-10': "assets/play/6-10.png",
'mike-1-2': "assets/play/mike-1-2.png",
'card-background': "assets/play/2.png",
'1-4': "assets/play/1-4.png",
'shadow-1': "assets/play/shadow-1.png",
'shadow-2': "assets/play/shadow-2.png",
'shadow-3': "assets/play/shadow-3.png",
'shadow-4': "assets/play/shadow-4.png"
};
const localAudios = {
'ssiwb_btn': 'assets/audio/ssiwb_btn.mp3',
'sm-back': "assets/default/audio/sm-back.mp3",
'sm-display': "assets/default/audio/sm-display.mp3",
'sm-wrong': "assets/default/audio/sm-wrong.mp3",
'sm-win': "assets/default/audio/sm-win.mp3",
'sm-in': "assets/default/audio/sm-in.mp3",
'sm-out': "assets/default/audio/sm-out.mp3",
'sm-click': "assets/default/audio/sm-click.mp3",
'sm-start': "assets/default/audio/sm-start.mp3",
'sm-correct': 'assets/default/audio/sm-correct.mp3',
'star': "assets/default/audio/star.mp3",
'tupiantanchu': 'assets/audio/tupiantanchu.mp3',
'houzitiaodong': 'assets/audio/houzitiaodong.mp3',
'houzitiaodongsahua': 'assets/audio/houzitiaodongsahua.mp3',
'huoziluodi': 'assets/audio/huoziluodi.wav'
};
// 图片尺寸信息对象,存储每个图片的宽度和高度
const localImagesSize = {
'1': { width: 197, height: 147 },
'bg_green_small': { width: 125, height: 119 },
'bg_green_small_line': { width: 130, height: 119 },
'bg': { width: 1280, height: 720 },
'bg_green': { width: 179, height: 171 },
'bg_green_line': { width: 182, height: 169 },
'bg_title': { width: 322, height: 85 },
'bg_white': { width: 180, height: 172 },
'bg_white_line': { width: 183, height: 169 },
'bg_yellow': { width: 303, height: 152 },
'bg_yellow_small': { width: 216, height: 107 },
'bg_yellow_small_line': { width: 217, height: 111 },
'bg_yellow_line': { width: 305, height: 155 },
'btn_return': { width: 63, height: 65 },
'bg_1280_720_Ruler': { width: 1280, height: 720 },
'bg-240-180': { width: 240, height: 180 },
'bg-453-251': { width: 453, height: 251 },
'bg_500_600': { width: 500, height: 600 },
'bg_1280_222': { width: 1280, height: 222 },
'bg_1280_720': { width: 1280, height: 222 },
'petal_1': { width: 35, height: 42 },
'petal_2': { width: 39, height: 47 },
'petal_3': { width: 36, height: 42 },
'star': { width: 62, height: 59 },
'flag': { width: 1, height: 720 },
'1-2': { width: 197, height: 147 },
'1-3': { width: 231, height: 235 },
'background': { width: 1280, height: 720 },
'grass-left': { width: 249, height: 169 },
'grass-right': { width: 257, height: 181 },
'grass-mid-1': { width: 255, height: 112 },
'grass-mid-2': { width: 161, height: 94 },
'grass-mid-3': { width: 313, height: 95 },
'6-10': { width: 44, height: 16 },
'mike-1-2': { width: 528, height: 750 },
'card-background': { width: 216, height: 251 },
'1-4': { width: 197, height: 147 },
'shadow-1': { width: 41, height: 22 },
'shadow-2': { width: 49, height: 22 },
'shadow-3': { width: 38, height: 19 },
'shadow-4': { width: 47, height: 18 },
};
// 使用CommonJS模块导出
module.exports = { localImages, localAudios, localImagesSize };
\ No newline at end of file
...@@ -72,46 +72,46 @@ const localAudios = { ...@@ -72,46 +72,46 @@ const localAudios = {
// 图片尺寸信息对象,存储每个图片的宽度和高度 // 图片尺寸信息对象,存储每个图片的宽度和高度
const localImagesSize = { const localImagesSize = {
'1': { width: 197, height: 147 }, '1': { width: 197, height: 147 },
'bg_green_small': { width: 130, height: 119 }, '1-2': { width: 197, height: 147 },
'bg_green_small_line': { width: 130, height: 119 }, '1-3': { width: 231, height: 235 },
'1-4': { width: 197, height: 147 },
'6-10': { width: 44, height: 16 },
'background': { width: 1280, height: 720 },
'bg': { width: 1280, height: 720 }, 'bg': { width: 1280, height: 720 },
'bg-240-180': { width: 240, height: 180 },
'bg-453-251': { width: 453, height: 251 },
'bg_1280_222': { width: 1280, height: 222 },
'bg_1280_720': { width: 1280, height: 222 },
'bg_1280_720_Ruler': { width: 1280, height: 720 },
'bg_500_600': { width: 500, height: 600 },
'bg_green': { width: 182, height: 171 }, 'bg_green': { width: 182, height: 171 },
'bg_green_line': { width: 182, height: 169 }, 'bg_green_line': { width: 182, height: 169 },
'bg_green_small': { width: 130, height: 119 },
'bg_green_small_line': { width: 130, height: 119 },
'bg_title': { width: 322, height: 85 }, 'bg_title': { width: 322, height: 85 },
'bg_white': { width: 183, height: 172 }, 'bg_white': { width: 183, height: 172 },
'bg_white_line': { width: 183, height: 169 }, 'bg_white_line': { width: 183, height: 169 },
'bg_yellow': { width: 305, height: 152 }, 'bg_yellow': { width: 305, height: 152 },
'bg_yellow_line': { width: 305, height: 155 },
'bg_yellow_small': { width: 217, height: 107 }, 'bg_yellow_small': { width: 217, height: 107 },
'bg_yellow_small_line': { width: 217, height: 111 }, 'bg_yellow_small_line': { width: 217, height: 111 },
'bg_yellow_line': { width: 305, height: 155 },
'btn_return': { width: 63, height: 65 }, 'btn_return': { width: 63, height: 65 },
'bg_1280_720_Ruler': { width: 1280, height: 720 }, 'card-background': { width: 216, height: 251 },
'bg-240-180': { width: 240, height: 180 },
'bg-453-251': { width: 453, height: 251 },
'bg_500_600': { width: 500, height: 600 },
'bg_1280_222': { width: 1280, height: 222 },
'bg_1280_720': { width: 1280, height: 222 },
'petal_1': { width: 35, height: 42 },
'petal_2': { width: 39, height: 47 },
'petal_3': { width: 36, height: 42 },
'star': { width: 62, height: 59 },
'flag': { width: 1, height: 720 }, 'flag': { width: 1, height: 720 },
'1-2': { width: 197, height: 147 },
'1-3': { width: 231, height: 235 },
'background': { width: 1280, height: 720 },
'grass-left': { width: 249, height: 169 }, 'grass-left': { width: 249, height: 169 },
'grass-right': { width: 257, height: 181 },
'grass-mid-1': { width: 255, height: 112 }, 'grass-mid-1': { width: 255, height: 112 },
'grass-mid-2': { width: 161, height: 94 }, 'grass-mid-2': { width: 161, height: 94 },
'grass-mid-3': { width: 313, height: 95 }, 'grass-mid-3': { width: 313, height: 95 },
'6-10': { width: 44, height: 16 }, 'grass-right': { width: 257, height: 181 },
'mike-1-2': { width: 528, height: 750 }, 'mike-1-2': { width: 528, height: 750 },
'card-background': { width: 216, height: 251 }, 'petal_1': { width: 35, height: 42 },
'1-4': { width: 197, height: 147 }, 'petal_2': { width: 39, height: 47 },
'petal_3': { width: 36, height: 42 },
'shadow-1': { width: 41, height: 22 }, 'shadow-1': { width: 41, height: 22 },
'shadow-2': { width: 49, height: 22 }, 'shadow-2': { width: 49, height: 22 },
'shadow-3': { width: 38, height: 19 }, 'shadow-3': { width: 38, height: 19 },
'shadow-4': { width: 47, height: 18 }, 'shadow-4': { width: 47, height: 18 },
'star': { width: 62, height: 59 },
}; };
export {localImages, localAudios, localImagesSize}; export {localImages, localAudios, localImagesSize};
/**
* 图片尺寸更新脚本
* 用于读取assets/game目录下的图片尺寸并更新resources.js文件中的localImagesSize对象
*/
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
// 项目根目录路径
const rootDir = path.resolve(__dirname, '../..');
// 从CommonJS版本的resources.cjs.js导入图片路径映射
const { localImages } = require('./resources.cjs.js');
// 创建一个新的localImagesSize对象
const localImagesSize = {};
// 使用sips命令读取图片尺寸(macOS系统专用)
function getImageDimensions(imagePath) {
try {
const fullPath = path.join(rootDir, imagePath);
if (!fs.existsSync(fullPath)) {
console.warn(`图片不存在: ${fullPath}`);
return null;
}
// 使用macOS的sips命令获取图片尺寸
const output = execSync(`sips -g pixelWidth -g pixelHeight "${fullPath}" | grep pixel`).toString();
const widthMatch = output.match(/pixelWidth: (\d+)/);
const heightMatch = output.match(/pixelHeight: (\d+)/);
if (widthMatch && heightMatch) {
return {
width: parseInt(widthMatch[1], 10),
height: parseInt(heightMatch[1], 10)
};
}
return null;
} catch (error) {
console.error(`读取图片尺寸失败: ${imagePath}`, error);
return null;
}
}
// 更新resources.js文件的函数
function updateResourcesFile(imageSizes) {
// 更新ES模块版本的resources.js
updateESModuleFile(imageSizes);
// 更新CommonJS版本的resources.cjs.js
updateCommonJSFile(imageSizes);
console.log('所有资源文件已更新');
}
// 更新ES模块版本的resources.js
function updateESModuleFile(imageSizes) {
const resourcesFilePath = path.join(__dirname, 'resources.js');
let content = fs.readFileSync(resourcesFilePath, 'utf8');
// 构建localImagesSize对象字符串
let sizeObjectStr = 'const localImagesSize = {\n';
Object.keys(imageSizes).forEach(key => {
const size = imageSizes[key];
if (size) {
sizeObjectStr += ` '${key}': { width: ${size.width}, height: ${size.height} },\n`;
} else {
// 如果无法获取尺寸,使用默认值或保留现有值
sizeObjectStr += ` '${key}': { width: 0, height: 0 }, // 无法获取尺寸\n`;
}
});
sizeObjectStr += '};';
// 替换或添加localImagesSize对象
const sizeRegex = /const localImagesSize = \{[\s\S]*?\};/;
if (content.match(sizeRegex)) {
content = content.replace(sizeRegex, sizeObjectStr);
console.log('已更新resources.js中现有的localImagesSize对象');
} else {
// 在文件末尾添加localImagesSize对象,但在export语句之前
const exportMatch = content.match(/export \{([^}]*)\};/);
if (exportMatch) {
// 提取导出的变量列表
const exportedVars = exportMatch[1].split(',').map(v => v.trim());
// 添加localImagesSize到导出列表
if (!exportedVars.includes('localImagesSize')) {
exportedVars.push('localImagesSize');
}
// 构建新的导出语句
const newExport = `export {${exportedVars.join(', ')}};`;
// 替换原有的导出语句
content = content.replace(/export \{[^}]*\};/, `\n${sizeObjectStr}\n\n${newExport}`);
console.log('已添加localImagesSize对象并更新resources.js的导出语句');
} else {
// 如果没有找到export语句,则在文件末尾添加
content += `\n${sizeObjectStr}\n\nexport {localImages, localAudios, localImagesSize};`;
console.log('已在resources.js文件末尾添加localImagesSize对象和ES模块导出');
}
}
fs.writeFileSync(resourcesFilePath, content, 'utf8');
console.log('resources.js文件已更新');
}
// 更新CommonJS版本的resources.cjs.js
function updateCommonJSFile(imageSizes) {
const resourcesFilePath = path.join(__dirname, 'resources.cjs.js');
let content = fs.readFileSync(resourcesFilePath, 'utf8');
// 构建localImagesSize对象字符串
let sizeObjectStr = 'const localImagesSize = {\n';
Object.keys(imageSizes).forEach(key => {
const size = imageSizes[key];
if (size) {
sizeObjectStr += ` '${key}': { width: ${size.width}, height: ${size.height} },\n`;
} else {
// 如果无法获取尺寸,使用默认值或保留现有值
sizeObjectStr += ` '${key}': { width: 0, height: 0 }, // 无法获取尺寸\n`;
}
});
sizeObjectStr += '};';
// 替换或添加localImagesSize对象
const sizeRegex = /const localImagesSize = \{[\s\S]*?\};/;
if (content.match(sizeRegex)) {
content = content.replace(sizeRegex, sizeObjectStr);
console.log('已更新resources.cjs.js中现有的localImagesSize对象');
} else {
// 在module.exports前添加localImagesSize对象
const exportMatch = content.match(/module\.exports = \{([^}]*)\};/);
if (exportMatch) {
// 提取导出的变量列表
const exportedVars = exportMatch[1].split(',').map(v => v.trim());
// 添加localImagesSize到导出列表(如果尚未添加)
if (!exportedVars.includes('localImagesSize')) {
exportedVars.push('localImagesSize');
}
// 构建新的导出语句
const newExport = `module.exports = {${exportedVars.join(', ')}};`;
// 替换原有的导出语句
content = content.replace(/module\.exports = \{[^}]*\};/, `${sizeObjectStr}\n\n${newExport}`);
console.log('已添加localImagesSize对象并更新resources.cjs.js的导出语句');
} else {
// 如果没有找到module.exports语句,则在文件末尾添加
content += `\n${sizeObjectStr}\n\nmodule.exports = { localImages, localAudios, localImagesSize };`;
console.log('已在resources.cjs.js文件末尾添加localImagesSize对象和CommonJS导出');
}
}
fs.writeFileSync(resourcesFilePath, content, 'utf8');
console.log('resources.cjs.js文件已更新');
}
// 主函数
function main() {
console.log('开始读取图片尺寸...');
// 处理所有图片
Object.entries(localImages).forEach(([key, imagePath]) => {
const dimensions = getImageDimensions(imagePath);
localImagesSize[key] = dimensions;
console.log(`读取图片 ${key}: ${dimensions ? `${dimensions.width}x${dimensions.height}` : '失败'}`);
});
// 更新resources.js文件
updateResourcesFile(localImagesSize);
console.log('所有图片尺寸已更新');
}
// 执行主函数
try {
main();
} catch (error) {
console.error('更新图片尺寸时发生错误:', error);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment