stijnwop / hoseSystem

Hose system modification for Farming Simulator 2017
13 stars 4 forks source link

suggestion #25

Closed HeadyCS closed 6 years ago

HeadyCS commented 6 years ago

I have a suggestion to change the script HoseSystemRegister.lua:


function HoseSystemRegistrationHelper.loadVehicle(super, vehicleData, asyncCallbackFunction, asyncCallbackObject, asyncCallbackArguments)
    local customEnvironment, _ = Utils.getModNameAndBaseDirectory(vehicleData.filename)

    --if customEnvironment ~= nil then
        local typeDef = VehicleTypeUtil.vehicleTypes[vehicleData.typeName]
        local specializations = typeDef.specializations
        local specializationNames = typeDef.specializationNames

        for i = 1, #specializations do
            local specializationName = specializationNames[i]

            --if specializationName ~= nil and specializationName:lower() == string.format('%s.%s', customEnvironment, HoseSystemRegistrationHelper.HOSE_SYSTEM_SPEC_KEY):lower() then
                local specialization = specializations[i]

                if specialization.preLoadHoseSystem ~= nil then
                    super.xmlFile = loadXMLFile('TempConfig', vehicleData.filename)

                    local vehicleLoadState = specializations[i].preLoadHoseSystem(super, vehicleData.savegame)

                    if vehicleLoadState ~= nil and vehicleLoadState ~= BaseMission.VEHICLE_LOAD_OK then
                        HoseSystemUtil:log(HoseSystemUtil.ERROR, specializationName .. "-specialization 'preLoadHoseSystem' failed!")

                        if asyncCallbackFunction ~= nil then
                            asyncCallbackFunction(asyncCallbackObject, nil, vehicleLoadState, asyncCallbackArguments)
                        end

                        return vehicleLoadState
                    end

                    if not super.hoseSystemLoaded then
                        HoseSystemRegistrationHelper:register(super, typeDef.specializations, vehicleData.filename)
                    end

                    delete(super.xmlFile)
                    super.xmlFile = nil
                end
            --end
        end
    --end
end

To support Mods / Scripts like this: zzz_ExtendStdVeh_HoseSystem.zip

stijnwop commented 6 years ago

Hey there are reasons why i check on those fields. I don't want to hook into every vehicle.

Also the fact by just deleting the check on nil values which uses a different index to iterate isn't going to be 'safe', if we talk about the range of scripts we currently have available in the modding scene.

Really cool that you want to make a script extension for inserting the functionality into the default vehicles.. but that can be done without touching the main script.

Think about mocking the HoseSystemVehicle.lua and insert that after you did the xml related stuff.

stijnwop commented 6 years ago

Added suggestion, but no response to be seen anywhere. ✌️