zhnkc9 / skin-generator

饥荒皮肤生成器
Apache License 2.0
46 stars 17 forks source link

关于新版本普通箱与龙鳞箱升级丢失贴图的想法以及两个bug修复方案(待修复与完善) #9

Open MoranOrz opened 7 months ago

MoranOrz commented 7 months ago

一、弹性空间制造器升级的问题

在普通箱与龙鳞箱中,有对 skin_name 进行 string 拼接的操作。 由于本 MOD 是有作者标记 ms_zhnkc9_gmail_com_ 为开头的 skin_name,因此会导致拼接后无法对应上 skin_name 而消失贴图。

local function DoUpgradeVisuals(inst)
    local skin_name = (inst.AnimState:GetSkinBuild() or ""):gsub("dragonflychest_", "")
    inst.AnimState:SetBank("dragonfly_chest_upgraded")
    inst.AnimState:SetBuild("dragonfly_chest_upgraded")
    if skin_name ~= "" then
        skin_name = "dragonflychest_upgraded_" .. skin_name
        inst.AnimState:SetSkin(skin_name, "dragonfly_chest_upgraded")
    end
end

目前有两个想法可能解决此问题:

  1. 作者能协助修改生成器,把 ms_zhnkc9_gmail_com_ 后挪至尾部,可能能解决。(作者已退游,不一定能帮这个忙,希望有个大佬能看懂项目源码帮忙解决一下。)
  2. AnimState:SetSkin 函数进行拦截加判断,特殊处理箱子这个问题。(仅为个人猜想)

    二、无视升级的时候消失贴图的问题,仅对扫皮肤进行修复

    已确定是因为字符拼接问题导致的贴图消失,因此可以在 init.lua 中重写 treasurechest_init_fndragonflychest_init_fn 函数,对拼接字符进行正确的处理。 以下为本人的修复方案,水平有限,只能保证扫皮肤不会空了:

    -- init.lua
    function treasurechest_init_fn (inst, build_name)
    if inst.components.placer then
        basic_init_fn(inst, build_name, "treasure_chest") -- NOTES(JBK): Chests can not be built as upgraded form.
        return
    elseif not TheWorld.ismastersim then
        return
    end
    
    if inst._chestupgrade_stacksize then
        if build_name:find("treasurechest_upgraded_", 21, true) then
            basic_init_fn(inst, build_name, "treasure_chest_upgraded")
        else
            basic_init_fn(inst, build_name:gsub("treasurechest_", "treasurechest_upgraded_"), "treasure_chest_upgraded")
        end
    else
        if build_name:find("treasurechest_upgraded_", 21, true) then
            basic_init_fn(inst, build_name:gsub("treasurechest_upgraded_", "treasurechest_"), "treasure_chest")
        else
            basic_init_fn(inst, build_name, "treasure_chest")
        end
    end
    
    AddSkinSounds(inst)
    end

    记得把 AddSkinSounds 方法拷贝过来 龙鳞箱也是如此修复

    后记:

    使用方法二修复后,依旧存在的问题(本人水平低,希望有大佬能给个建议/解决方案)

  3. 制作栏普通箱子能预览到 upgraded 升级后的皮肤,当然造出来是矮的皮肤,即使建造投影是高的。(不知道怎么让这些升级后的皮肤不在制作栏预览)
  4. 龙鳞箱没有上面制作栏能预览到升级后皮肤的问题。 反正目前我的水平只能这么修复着勉强使用,希望有大佬看到 issues 能帮忙解决一下。

    附加修复另外两个致命性 Bug 的方案

    1、在开启 “能力勋章” 模组时,捆绑包装的 skin 会变成 number 类型,导致本模组 SpawnPrefab 函数使用错误的数据而引起崩溃。 以下为解决方案(在作者 issues 前修好了):

    -- skinloader.lua
    function SpawnPrefab(name, skin, ...)
    local ent = _SpawnPrefab(name, skin, ...)
    if ent and skin and type(skin) == "string" and skin:start_with_that_prefix() then    -- 此处新增类型判断
        name = name:gsub("_placer", "")
        ApplySkin(ent, name, skin)
    end
    return ent
    end

    2、阿比盖尔的花扫皮肤引起的崩溃。 以下为解决方案(作者 issues 的方案):

    -- init.lua
    function abigail_flower_init_fn (inst, build_name)
    if not TheWorld.ismastersim then
        return
    end
    if inst.flower_skin_id and inst.skin_id then    -- 此处新增条件
        inst.flower_skin_id:set(inst.skin_id)
    end
    inst.AnimState:SetSkin(build_name, "abigail_flower_rework")
    inst.components.inventoryitem:ChangeImageName(inst:GetSkinName())
    inst.linked_skinname = string.gsub(build_name, "_flower", "")
    end
cao2580 commented 6 months ago

大佬还是没懂,那个扫皮肤代码怎么添加,能详细说说吗

lhe33 commented 6 months ago

大佬,你能扛起这个mod的大旗嘛,穷学生就看你了

tx6548 commented 6 months ago

看不懂,在init里面加了也没有作用,依然还是会出现透明箱子

roundRekt commented 5 months ago

给不懂的说一下哈 打开游戏文件夹/mods/Local Collection Skins/scripts/init.lua 在最后添加代码

SKIN_SOUND_FX = {}

local function AddSkinSounds(inst)
    -- NOTES(JBK): Do not do fancy shorthand loops these should be easily searchable.
    -- FIXME(JBK): These variable names for them being stored on the inst are not consistent.
    local sounds = SKIN_SOUND_FX[inst:GetSkinName()]
    if sounds then
        -- Weapon
        inst.hit_skin_sound = sounds.hit
        -- Whip
        inst.skin_sound_small = sounds.small
        inst.skin_sound_large = sounds.large
        -- Equipment
        inst.skin_equip_sound = sounds.equip
        -- Chest
        inst.skin_place_sound = sounds.place
        inst.skin_open_sound = sounds.open
        inst.skin_close_sound = sounds.close
        -- Bundle Wrap
        inst.skin_wrap_sound = sounds.wrap
        -- Bug Net
        inst.overridebugnetsound = sounds.net
        -- Glomling, reviver, staff
        inst.skin_sound = sounds.genericuse -- FIXME(JBK): This variable name on both sides and split the objects out.
        -- Staff
        inst.skin_castsound = sounds.cast
        -- Orange Staff
        if inst.components.blinkstaff and (sounds.preteleport or sounds.postteleport) then
            inst.components.blinkstaff:SetSoundFX(sounds.preteleport, sounds.postteleport)
        end
    end
end

function treasurechest_init_fn (inst, build_name)
    if inst.components.placer then
        basic_init_fn(inst, build_name, "treasure_chest") -- NOTES(JBK): Chests can not be built as upgraded form.
        return
    elseif not TheWorld.ismastersim then
        return
    end

    if inst._chestupgrade_stacksize then
        if build_name:find("treasurechest_upgraded_", 21, true) then
            basic_init_fn(inst, build_name, "treasure_chest_upgraded")
        else
            basic_init_fn(inst, build_name:gsub("treasurechest_", "treasurechest_upgraded_"), "treasure_chest_upgraded")
        end
    else
        if build_name:find("treasurechest_upgraded_", 21, true) then
            basic_init_fn(inst, build_name:gsub("treasurechest_upgraded_", "treasurechest_"), "treasure_chest")
        else
            basic_init_fn(inst, build_name, "treasure_chest")
        end
    end

    AddSkinSounds(inst)
end

function dragonflychest_init_fn (inst, build_name)
    if inst.components.placer then
        basic_init_fn(inst, build_name, "dragonfly_chest") -- NOTES(JBK): Chests can not be built as upgraded form.
        return
    elseif not TheWorld.ismastersim then
        return
    end

    if inst._chestupgrade_stacksize then
        if build_name:find("dragonflychest_upgraded_", 21, true) then
            basic_init_fn(inst, build_name, "dragonfly_chest_upgraded")
        else
            basic_init_fn(inst, build_name:gsub("dragonflychest_", "dragonflychest_upgraded_"), "dragonfly_chest_upgraded")
        end
    else
        if build_name:find("dragonflychest_upgraded_", 21, true) then
            basic_init_fn(inst, build_name:gsub("dragonflychest_upgraded_", "dragonflychest_"), "dragonfly_chest")
        else
            basic_init_fn(inst, build_name, "dragonfly_chest")
        end
    end

    AddSkinSounds(inst)
end

保存重新加载游戏就可以了 但是用这个方法扫出来的皮肤只要不是原皮重新进游戏还是会变空 要用黑化行为学shift+右键框选重新扫 所以就是 用处不大 解决这个问题需要有人大改一下整个mod 解决之前如果一定要升级箱子建议一直用原皮吧

xhhejn commented 4 months ago

提供一种 “掩耳盗铃” 式的解决方案,在创意工坊里有个mod叫做 “宝箱升级贴图不变”,链接是https://steamcommunity.com/sharedfiles/filedetails/?id=3275185052 启用了这个mod后,升级的高箱子外形保持为矮箱子,因此就避免了高箱子贴图丢失的问题,矮箱子的皮肤就随便扫吧。

我不懂mod代码,看modmain大概是通过把 "_upgraded" 给替换掉来实现的,不知道能不能给修复箱子贴图丢失的bug一些启发。