From 24f83c028454ba9dd8679d0d4a40759566256f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <12574910+72wo@users.noreply.github.com> Date: Sat, 28 Feb 2026 22:31:33 +0800 Subject: [PATCH] =?UTF-8?q?```=20feat(data):=20=E6=B7=BB=E5=8A=A0=E9=9A=8F?= =?UTF-8?q?=E6=9C=BA=E9=A2=9C=E8=89=B2=E7=94=9F=E6=88=90=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=B9=B6=E9=87=8D=E6=9E=84=E5=8F=91=E5=85=89=E6=BB=A4=E9=95=9C?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 引入 grand 包用于生成随机数 - 将 GlowFilterDefault 常量改为 GetDef() 函数,实现动态配置 - 修改默认发光滤镜参数:Alpha从0.8改为0.1,BlurX/BlurY从10改为8, Quality从2改为1,Level从1改为2 - 新增 RandomRGBToUint32() 函数生成随机RGB颜色并转换为uint32格式 - 在GetDef()函数中使用随机颜色替代固定颜色值 refactor(config): 优化闪光效果服务中的矩阵生成逻辑 - 移除不必要的变量声明,直接在赋值时调用GenerateRandomOffspringMatrix --- common/data/color.go | 40 +++++++++++++++++++++------------ modules/config/service/shiny.go | 4 ++-- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/common/data/color.go b/common/data/color.go index db86d2d8b..5e73a9da4 100644 --- a/common/data/color.go +++ b/common/data/color.go @@ -1,5 +1,7 @@ package data +import "github.com/gogf/gf/v2/util/grand" + // 1. 质量枚举常量(保持不变) const ( BitmapFilterQualityLow = 1 // LOW:应用1次滤镜 @@ -20,23 +22,33 @@ const ( colorMax = 0xFFFFFF // 颜色值最大值(0xRRGGBB) ) -// GlowFilterDefault 默认值:与目标JSON完全匹配的常量 -var GlowFilterDefault = GlowFilter{ - Color: 16777215, // 0xFFFFFF(对应JSON的color:16777215) - Alpha: 0.8, // 对应JSON的alpha:0.8 - BlurX: 10, // 对应JSON的blurX:10 - BlurY: 10, // 对应JSON的blurY:10 - Strength: 8, // 对应JSON的strength:8 - Quality: 2, // 对应JSON的quality:2 - Inner: true, // 对应JSON的inner:true - Knockout: false, // 无JSON值,默认false - ColorMatrixFilter: [20]float32{1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0}, // 对应JSON的matrix数组 - Level: 1, // 对应JSON的level:"1"(转uint8) +func GetDef() GlowFilter { + + ret := GlowFilter{ + // Color: 16777215, // 0xFFFFFF(对应JSON的color:16777215) + Alpha: 0.1, // 光圈大小,透明度 + BlurX: 8, // 局外光圈大小 + BlurY: 8, // 局外光圈大小 + Strength: 8, // 颜色对比度 + Quality: 1, // 背包内光圈大小 + Inner: true, // 对应JSON的inner:true + Knockout: false, // 无JSON值,默认false + ColorMatrixFilter: [20]float32{1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0}, // 对应JSON的matrix数组 + Level: 2, // 对应JSON的level:"1"(转uint8) + } + ret.Color = RandomRGBToUint32() + return ret } -func GetDef() GlowFilter { - return GlowFilterDefault +// RandomRGBToUint32 生成随机RGB颜色并转为uint32(格式:0x00RRGGBB,最高8位留空) +func RandomRGBToUint32() uint32 { + // 生成0-255的随机R/G/B分量 + r := uint32(grand.Intn(256)) + g := uint32(grand.Intn(256)) + b := uint32(grand.Intn(256)) + // 位拼接:R左移16位,G左移8位,B不位移,组合成uint32 + return (r << 16) | (g << 8) | b } // 精灵加shinylen字段 diff --git a/modules/config/service/shiny.go b/modules/config/service/shiny.go index c344aaa23..bafde121f 100644 --- a/modules/config/service/shiny.go +++ b/modules/config/service/shiny.go @@ -71,10 +71,10 @@ func (s *ShinyService) RandShiny(id uint32) *data.GlowFilter { if len(ret) == 0 { return nil } - r := model.GenerateRandomOffspringMatrix() + var t = data.GetDef() - t.ColorMatrixFilter = r.Get() + t.ColorMatrixFilter = model.GenerateRandomOffspringMatrix().Get() return &t }