config.uts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. let emptyValue : UTSJSONObject = {
  2. // 主题颜色
  3. themeColor: "#296BEF",
  4. // 头发颜色
  5. hairColor: '#483029',
  6. // 衣服颜色
  7. clothesColor: "#EDA20C",
  8. // 裤子颜色
  9. trousersColor: "#296BEF",
  10. // 鞋子颜色
  11. shoesColor: "#296BEF",
  12. // 物品颜色
  13. itemColor: "#483029",
  14. // 人物肤色
  15. skinColor: "#ffcda5",
  16. // 元素颜色
  17. elementColor: "#ffffff"
  18. };
  19. /**
  20. * 参数合并
  21. */
  22. function initEmptyConfig(config : UTSJSONObject) : UTSJSONObject {
  23. // 当主题色不为空时,将裤子和鞋子的颜色同步
  24. if (config.getString("themeColor") !== null) {
  25. // 当裤子颜色为空时,默认主题色
  26. if (config.getString("trousersColor") == null) {config.set("trousersColor", config.getString("themeColor"));};
  27. // 当鞋子颜色为空时,默认主题色
  28. if (config.getString("shoesColor") == null) {config.set("shoesColor", config.getString("themeColor"));};
  29. };
  30. emptyValue = Object.assign(emptyValue, config);
  31. return emptyValue;
  32. };
  33. /**
  34. * 颜色解析
  35. */
  36. /**
  37. * 主题色渐变混色
  38. * @param c1 混色1
  39. * @param c2 混色2
  40. * @param weight 权重 0~1 之间
  41. * @returns hex规定颜色值为十六进制值颜色
  42. */
  43. function generateMixedColor(c1 : string, c2 : string, weight : number) : string {
  44. weight = Math.max(Math.min(weight, 1), 0);
  45. const r1 = parseInt(c1.substring(1, 3), 16);
  46. const g1 = parseInt(c1.substring(3, 5), 16);
  47. const b1 = parseInt(c1.substring(5, 7), 16);
  48. const r2 = parseInt(c2.substring(1, 3), 16);
  49. const g2 = parseInt(c2.substring(3, 5), 16);
  50. const b2 = parseInt(c2.substring(5, 7), 16);
  51. const r = Math.round(r1 * (1 - weight) + r2 * weight);
  52. const g = Math.round(g1 * (1 - weight) + g2 * weight);
  53. const b = Math.round(b1 * (1 - weight) + b2 * weight);
  54. return `rgb(${r}, ${g}, ${b})`;
  55. };
  56. /**
  57. * 主题颜色
  58. */
  59. function funThemeColor(coefficient : number = 1) : string {
  60. return generateMixedColor("#ffffff", `${emptyValue.getString("themeColor")}`, coefficient);
  61. };
  62. /**
  63. * 头发颜色
  64. */
  65. function funHairColor() : string {
  66. return `${emptyValue.getString("hairColor")}`;
  67. };
  68. /**
  69. * 衣服颜色
  70. */
  71. function funClothesColor(coefficient : number = 1) : string {
  72. return generateMixedColor("#ffffff", `${emptyValue.getString("clothesColor")}`, coefficient);
  73. };
  74. /**
  75. * 裤子颜色
  76. */
  77. function funTrousersColor(coefficient : number = 1) : string {
  78. return generateMixedColor("#ffffff", `${emptyValue.getString("trousersColor")}`, coefficient);
  79. };
  80. /**
  81. * 鞋子颜色
  82. */
  83. function funShoesColor(coefficient : number = 1) : string {
  84. return generateMixedColor("#ffffff", `${emptyValue.getString("shoesColor")}`, coefficient);
  85. };
  86. /**
  87. * 人物肤色
  88. */
  89. function funSkinColor(coefficient : number = 1) : string {
  90. return generateMixedColor("#ffffff", `${emptyValue.getString("skinColor")}`, coefficient);
  91. };
  92. /**
  93. * 元素颜色
  94. */
  95. function funElementColor() : string {
  96. return `${emptyValue.getString("elementColor")}`;
  97. };
  98. /**
  99. * 元素颜色
  100. */
  101. function funItemColor() : string {
  102. return `${emptyValue.getString("itemColor")}`;
  103. };
  104. export {
  105. funThemeColor, funHairColor, funClothesColor, funTrousersColor, funShoesColor, funSkinColor, funItemColor, funElementColor, initEmptyConfig
  106. }