ターン回しパネル

ワークショップに「Turn Tracker」で登録あり


■スクリプト内容
--これら3つの値を変更して、移動時にトークンが配置される場所を変更します
--これらはすべて、プレーヤーのハンドゾーン(名前がどこにあるか)に関連しています。
--これは左または右です
leftRight = 0
--これはテーブルの上下(上下)です。
upDown = 1
--これは前方または後方です
forwardBack = 5

--トラッカーを所定の位置に固定しますか?(Lで固定した状態) true か false で設定
lockTrackerAfterMove = true

--↑ここまでが設定できる項目。以下はスクリプト

handOffset = {["x"]=leftRight,["y"]=upDown,["z"]=forwardBack}
defaultColorList = {"White", "Brown", "Red", "Orange", "Yellow", "Green", "Teal", "Blue", "Purple", "Pink"}

function onSave()
    local data_to_save = {currentColor}
    saved_data = JSON.encode(data_to_save)
    return saved_data
end

function onload(saved_data)
    if saved_data == "" then
        currentColor = ""
        self.setColorTint({0.5,0.5,0.5})
        createMainButton()
    else
        local loaded_data = JSON.decode(saved_data)
        currentColor = loaded_data[1]
        if currentColor == "" then
            self.setColorTint({0.5,0.5,0.5})
            createMainButton()
        else
            createFullySpawnedButtons()
            placeToken()
        end
    end
end


function forwardOneTurn() moveTurn(1) end
function backOneTurn() moveTurn(-1) end
function moveTurn(whichWay)
    currentColor = findNextPlayerColor(whichWay)
    placeToken()
end

function placeToken()
    local handTable = Player[currentColor].getPlayerHand()
    local handPos = {["x"]=handTable.pos_x,["y"]=handTable.pos_y,["z"]=handTable.pos_z}
    local handRot = {handTable.rot_x, handTable.rot_y+180, handTable.rot_z}
    local xFinal = handPos.x + (handTable.trigger_forward_x * handOffset.z) + (handTable.trigger_right_x * handOffset.x)
    local yFinal = handPos.y + handOffset.y
    local zFinal = handPos.z + (handTable.trigger_forward_z * handOffset.z) + (handTable.trigger_right_z * handOffset.x)
    self.setColorTint(stringColorToRGB(currentColor))
    self.setPosition({xFinal,yFinal,zFinal})
    self.setRotation(handRot)
    if lockTrackerAfterMove == true then self.lock() end
end

--ボタンを起動/削除/編集するためのリセット機能と開始機能
function activateToolButtons(o, clickColor)
    if clickColor ~= "Black" then
        currentColor = clickColor
        placeToken()
        --self.setColorTint(stringColorToRGB(currentColor))
        self.editButton({index=0, label="End\nTurn", click_function="forwardOneTurn"})
        createOtherButtons()
    end
end

--テーブルのデフォルトのカラーオーダーテーブルで次のカラーを検索します。
function findNextPlayerColor(int)
    local playerList = explode(self.getName())
    if checkIfListIsValid(playerList) ~= true then
        playerList = getSeatedPlayers()
        --playerList = {"White", "Orange", "Green", "Purple"}-----------------------------------------DEBUG LINE
    end

    local nextColor = ""
    for i, color in ipairs(playerList) do
        if color == currentColor then
            if int == 1 and i == #playerList then
                nextColor = playerList[1]
            elseif int == -1 and i == 1 then
                nextColor = playerList[#playerList]
            else
                nextColor = playerList[i+int]
            end
        end
    end
    if nextColor == "" then
        print("Error in findNextPlayerColor, color was not found")
        return nil
    else
        return nextColor
    end
end




--テーブルをスペースで区切ります
function explode(stringToExplode)
    local pos,arr = 0,{}
    for st,sp in function() return string.find(stringToExplode," ",pos,true) end do
        table.insert(arr,string.sub(stringToExplode,pos,st-1))
        pos = sp + 1
    end
    table.insert(arr,string.sub(stringToExplode,pos))
    return arr
end

--テーブル内のすべての名前が有効な色と一致することを保証し、true / falseを返します。
function checkIfListIsValid(listToCheck)
    for i, pColor in ipairs(listToCheck) do
        local foundColor = false
        for j, dColor in ipairs(defaultColorList) do
            if dColor == pColor then
                foundColor = true
            end
        end
        if foundColor == false then
            return false
        end
    end
    if #listToCheck ~= 0 then
        return true
    else
        return false
    end
end

--ツールを開始状態にリセットします。
function deactivateToolButtons(o, clickColor)
    self.setColorTint({0.5,0.5,0.5})
    self.editButton({index=0, label="Start", click_function="activateToolButtons"})
    self.removeButton(1)
    self.removeButton(2)
    currentColor = ""
end

--この時点からのボタンの作成
function createMainButton()
    self.createButton({
        label="Start", click_function="activateToolButtons", function_owner=self,
        position={0.4,0.10,0.2}, height=500, width=700, font_size=200
    })
end

function createFullySpawnedButtons()
    self.createButton({
        label="End\nTurn", click_function="forwardOneTurn", function_owner=self,
        position={0.4,0.10,0.2}, height=500, width=700, font_size=200
    })
    createOtherButtons()
end

function createOtherButtons()
    self.createButton({
        label="Back", click_function="backOneTurn", function_owner=self,
        position={-0.75,0.10,0.05}, height=300, width=400, font_size=80
    })
    self.createButton({
        label="Reset", click_function="deactivateToolButtons", function_owner=self,
        position={-0.75,0.10,0.55}, height=130, width=400, font_size=80
    })
end

タグ:

+ タグ編集
  • タグ:
最終更新:2017年07月07日 18:40