这应该是几年程序员可以写出的代码?

2018-01-29 09:14:12 +08:00
 huanyingch01

如下代码是是在某个类中的某个 api,项目中各处充斥着大量这种函数

function ChangeUserPropertiesResult:execute()
    local processQueue = {}

    local resultData = self.mData.resultData
    local allAnimationData = {}

    --dump(resultData, "resultData resultData", 10, 2)
    if resultData.uaitems and next(resultData.uaitems)  then
        for _,item in pairs(resultData.uaitems) do
            local aniResult = {}
            local userid = item.userId or item.userid

            if item.name == Player.DIRECTION then 
                SingletonShareData:getPlayerWithId(userid):updateDataBonusWithName(Player.DIRECTION,{count = item.count})
                --
                local bd = MapDataManager:getUserPosition(userid).branchDirection or -1
                MapDataManager:saveUserPosition(bd,userid,"branchDirection")

                local posData = MapDataManager:getUserPosition(userid)
                -- local nextPaths = PathFinder:findPathFromToEnd(posData.nowPos, item.count, 1)
                -- local nextPath = nextPaths[1]
                local tilePath = posData.nowPos
                -- AvatarWalker:setStandAction(userid, tilePath, nextPath)
                AvatarWalker:setAvatarPosition(userid,tilePath)

            elseif string.find(item.name,"c_") ~= nil then
                local cardid = string.sub(item.name, 3, -1)
                local action = ""
                if item.count > 0 then
                    action = "add"
                elseif item.count == 0 then
                    action = "clear"
                else
                    action = "remove"
                end

            
                local itemType,itemName = unpack(string.split(item.name,"_"))
                local cradsData = cc.exports.SingletonShareData:getPlayerWithId(userid):getDataBonusWithName(Player.CARDS)
                local isHasBaoXianKa = false
                if cradsData then 
                   for k,v in pairs(cradsData) do
                        if tonumber(v) == 29 then
                            isHasBaoXianKa = true
                            break
                        end
                    end
                end
            
                local isEnterHospital = cc.exports.SingletonShareData:getPlayerWithId(userid):hasStatusWithName("hospital")
            
                if (isEnterHospital == true and isHasBaoXianKa == true) and tonumber(itemName) == 29 and item.count < 0 then
                    local data = {}
                    data.cardId = tonumber(itemName)
                    data.playerId = userid
                    local dialog = require("app.process.CardUseController").new() --// 建议位置
                    dialog:setInputData(data)
                    if data.cardId then
                       table.insert(processQueue, dialog)
                    end
                    --行为记录
                    PlayerActionRecordHelper:pushRecordData({tips_name="tips_card_other",function_name="getCardContent",data={userId=userid,resultData={cardid=data.cardId}}})

                    EmotionResult:getInstance():pushEmotionData({userId = userid,action = EA_USE_CARD,cardId = E_CARD_INSURANCE})
                    EmotionResult:getInstance():execute()                    
                end

                aniResult = {userId = userid,action=action,itemName = cardid,itemType = "card"}
                if item.count > 0 then
                   for k = 1,item.count do
                       cc.exports.SingletonShareData:getPlayerWithId(userid):updateDataBonusWithName(Player.CARDS,{itemName = cardid, action = action})
                    end
                else
                    cc.exports.SingletonShareData:getPlayerWithId(userid):updateDataBonusWithName(Player.CARDS,{itemName = cardid, action = action})
                end
            else
                cc.exports.SingletonShareData:getPlayerWithId(userid):updateDataBonusWithName(
                                                item.name,{itemCount = item.count})
                if item.count > 0 then
                    aniResult = {userId = userid,action="add",itemName = item.name,itemType = "points"}
                end
            end

            allAnimationData[#allAnimationData + 1] = aniResult
        end
    end


    local diplayCtrlName = self.mExtraData and self.mExtraData.displayCtrlClass --or "UserPropertiesDisplayResult"
    if diplayCtrlName then
        local ctrl = require("app.processResult.displayResult."..diplayCtrlName).new()
        ctrl:setInputData(allAnimationData)
        ctrl:setCallBack(handler(self,self.executeProcessComplete))

        table.insert(processQueue, ctrl)
    end

    if next(processQueue) then
        local processCtrl = require("app.process.ProcessQueue").new(processQueue,function()
            self:executeProcessComplete()
        end)
        processCtrl:handlerQueue()
    else
        self:executeProcessComplete()
    end
end
9617 次点击
所在节点    程序员
87 条回复
w3sy
2018-01-29 17:38:52 +08:00
@woscaizi swift? 你这是黑 swift 吧……😊
sobigfish
2018-01-29 20:09:59 +08:00
@jyf #29 这个 moonscript 是新语言吧,居然不是强类型的 😂

hello = "world"
a,b,c = 1, 2, 3
hello = 123 -- uses the existing variable
DavidNineRoc
2018-01-29 21:10:38 +08:00
<?php
call_user_func_array(function (...$parameters) {
echo implode('', $parameters);
}, [
(string) new class {
public function __toString()
{
return 'hello, world!';
}
},
'DavidNineRoc'
]);
DavidNineRoc
2018-01-29 21:13:58 +08:00
```php
call_user_func_array(function (...$parameters) {
echo implode('', $parameters);
}, [
(string) new class {
public function __toString()
{
return 'hello, world!';
}
},
'DavidNineRoc'
]);
```
akira
2018-01-30 04:59:27 +08:00
缩进挺整齐的
Technetiumer
2018-01-30 05:33:32 +08:00
看到用 -- 做注釋就應該知道這是 Lua

PHP 有超多的$
Java 滿屏 public class
jyf
2018-01-30 10:12:22 +08:00
@sobigfish 是的 杂揉了 typescript 和 python 至少语法上比 lua 舒服多了 也不罗嗦了 当然好坏就见仁见智了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/426672

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX