Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- board_image_factor = 11/12 --estimate of how much of board model is the actual image
- image_dimensions = Vector(1200, 0, 900)
- button_width = 650 --not sure what this means size-wise, might need to play around
- debug_button_visible = 0 --set to 1 to see the button positioning
- -- shouldn't need to change this
- board_size = self.getBounds().size * board_image_factor
- -- can define variables for character labels here to minimize chance of typos
- -- these only work if the value matches the variable name; will think about why later
- char_frost = 'char_frost'
- char_redhood = 'char_redhood'
- char_sunny = 'char_sunny'
- char_arc = 'char_arc'
- char_depths = 'char_depths'
- char_wyrm = 'char_wyrm'
- char_lich = 'char_lich'
- char_storm = 'char_storm'
- char_season_mns = 'char_season_mns'
- char_marisa = 'char_marisa'
- char_suwako = 'char_suwako'
- char_ran = 'char_ran'
- char_suika = 'char_suika'
- char_kokoro = 'char_kokoro'
- char_junko = 'char_junko'
- char_seija = 'char_seija'
- char_season_2hu = 'char_season_2hu'
- char_season_all = 'char_season_all'
- char_season_focus = 'char_season_focus'
- -- indicate where your character's square is on your board, in pixels
- character_coordinate_map = {
- char_frost = {150, 100},
- char_redhood = {250, 100},
- char_sunny = {350, 100},
- char_arc = {150, 200},
- char_depths = {350, 200},
- char_wyrm = {150, 300},
- char_lich = {250, 300},
- char_storm = {350, 300},
- char_season_mns = {250, 200},
- char_marisa = {500, 100},
- char_suwako = {600, 100},
- char_ran = {700, 100},
- char_suika = {500, 200},
- char_kokoro = {700, 200},
- char_junko = {500, 300},
- char_seija = {700, 300},
- char_season_2hu = {600, 200},
- char_season_all = {175, 825},
- char_season_focus = {1025, 825}
- }
- -- can include entries in this for differently sized buttons (as multipliers to width/height)
- button_resize_map = {
- -- char_season_all = {1.5, 1.5},
- -- char_season_focus = {1.5, 1.5}
- }
- -- tooltips for each button, likely character names
- character_tooltip_map = {
- char_frost = 'Hero of Frost (Maiden & Spell)',
- char_redhood = 'Silent Redhood (Maiden & Spell)',
- char_sunny = 'Sun Priestess (Maiden & Spell)',
- char_arc = 'Royal Arcanist (Maiden & Spell)',
- char_depths = 'Depth\'s Secret (Maiden & Spell)',
- char_wyrm = 'Dreadwyrm Heir (Maiden & Spell)',
- char_lich = 'Lich of Flowers (Maiden & Spell)',
- char_storm = 'Stormbeast (Maiden & Spell)',
- char_season_mns = 'Maiden & Spell',
- char_marisa = 'Kirisame Marisa (Touhou Project)',
- char_suwako = 'Moriya Suwako (Touhou Project)',
- char_ran = 'Yakumo Ran (Touhou Project)',
- char_suika = 'Ibuki Suika (Touhou Project)',
- char_kokoro = 'Hata no Kokoro (Touhou Project)',
- char_junko = 'Junko (Touhou Project)',
- char_seija = 'Kijin Seija (Touhou Project)',
- char_season_2hu = 'Touhou Project',
- char_season_all = 'All Characters',
- char_season_focus = 'Test These Guys'
- }
- -- for random buttons, indicate which characters they can roll
- character_collection_map = {
- char_season_mns = {
- characters = {char_frost, char_redhood, char_sunny, char_arc,
- char_depths, char_wyrm, char_lich, char_storm},
- color_string = [[{
- "r": 0,
- "g": 0.89,
- "b": 0.13
- }]]
- },
- char_season_2hu = {
- characters = {char_marisa, char_suwako, char_ran, char_suika,
- char_kokoro, char_junko, char_seija},
- color_string = [[{
- "r": 1,
- "g": 0.2,
- "b": 0.3
- }]]
- },
- char_season_all = {
- characters = {char_frost, char_redhood, char_sunny, char_arc, char_depths, char_wyrm, char_lich,
- char_storm, char_marisa, char_suwako, char_ran, char_suika, char_kokoro, char_junko, char_seija},
- color_string = [[{
- "r": 0,
- "g": 0.6,
- "b": 0
- }]]
- },
- -- special 'season' for characters i want people to test
- char_season_focus = {
- characters = {char_redhood, char_suika, char_suwako, char_kokoro},
- color_string = [[{
- "r": 0,
- "g": 0.46,
- "b": 0.89
- }]]
- }
- }
- -- for everyone else, map them to their jsons; this will prob be pretty long
- -- note that if copying from a saved object, you only want the section under the 'ObjectStates' field, not the full json
- -- i 'dehydrated' the jsons by taking out newlines for readability, depend on text editor tho
- char_json_map = {
- -- char_frost = [[{ "GUID": <--other stuff removed for brevity-->}]],
- -- char_redhood = [[{ "GUID": <--other stuff removed for brevity-->}]],
- -- char_sunny = [[{ "GUID": <--other stuff removed for brevity-->}]],
- -- char_arc = [[{ "GUID": <--other stuff removed for brevity-->}]],
- -- char_depths = [[{ "GUID": <--other stuff removed for brevity-->}]],
- -- char_wyrm = [[{ "GUID": <--other stuff removed for brevity-->}]],
- -- char_lich = [[{ "GUID": <--other stuff removed for brevity-->}]],
- -- char_storm = [[{ "GUID": <--other stuff removed for brevity-->}]],
- -- char_marisa = [[{ "GUID": <--other stuff removed for brevity-->}]],
- -- char_suwako = [[{ "GUID": <--other stuff removed for brevity-->}]],
- -- char_ran = [[{ "GUID": <--other stuff removed for brevity-->}]],
- -- char_suika = [[{ "GUID": <--other stuff removed for brevity-->}]],
- -- char_kokoro = [[{ "GUID": <--other stuff removed for brevity-->}]],
- -- char_junko = [[{ "GUID": <--other stuff removed for brevity-->}]],
- -- char_seija = [[{ "GUID": <--other stuff removed for brevity-->}]]
- }
- -- end of big json variable
- board_dim_ratio = image_dimensions.x / image_dimensions.z
- did_initialize = false
- function onload()
- if did_initialize then
- return
- end
- did_initialize = true
- local base_rotation = self.getRotation()
- self.setRotation(Vector(0, 180, 0))
- board_size = self.getBounds().size * board_image_factor
- for char_label, button_pos_px in pairs(character_coordinate_map) do
- local button_pos = pixelToRelativeWorldPosition(button_pos_px[1], button_pos_px[2], true)
- local char_tooltip = character_tooltip_map[char_label]
- if character_collection_map[char_label] ~= nil then
- char_tooltip = char_tooltip .. "\n(Left Click for Bag, Right Click for Random)"
- end
- local width_mult = 1
- local height_mult = 1
- if button_resize_map[char_label] ~= nil then
- width_mult = button_resize_map[char_label][1]
- height_mult = button_resize_map[char_label][2]
- end
- self.createButton({
- click_function = attachArg('spawnCharacter', char_label),
- function_owner = self,
- position = button_pos + Vector(0, -0.2 * (0.5 - debug_button_visible), 0),
- width = button_width * width_mult,
- height = button_width * board_dim_ratio * height_mult,
- tooltip = char_tooltip
- })
- end
- self.setRotation(base_rotation)
- end
- function attachArg(click_function, arg)
- local fn_name = click_function .. arg
- _G[fn_name] = function(obj, player_color, alt_click)
- _G[click_function](obj, player_color, alt_click, arg)
- end
- return fn_name
- end
- function spawnCharacter(_, player_color, alt_click, char_label)
- --print('yippee ' .. char_label)
- -- The clicks are caught by UI elements, which Grey actually CAN interact with.
- -- Nobody actually expects this, so we should ignore Grey's clicks.
- if player_color == "Grey" then return end
- local spawned_object = nil
- local is_season_bag = false
- -- Check if it's a collection; if so, choose a random appropriate char_label
- local check_collection = character_collection_map[char_label]
- if check_collection ~= nil then
- collection_characters = check_collection.characters
- collection_colors = check_collection.color_string
- if alt_click then -- if right click, spawn a random character
- char_label = collection_characters[math.random(#collection_characters)]
- else -- if left click, spawn the full collection
- local season_json_list = {}
- for _, single_json in ipairs(collection_characters) do
- table.insert(season_json_list, char_json_map[single_json])
- end
- local season_json_list_string = table.concat(season_json_list, ", ")
- spawned_object = spawnObjectJSON({
- json = [[{
- "Name": "Bag",
- "Transform": {
- "posX": 0,
- "posY": 0,
- "posZ": 0,
- "rotX": 0,
- "rotY": 0,
- "rotZ": 0,
- "scaleX": 1,
- "scaleY": 1,
- "scaleZ": 1
- },
- "ColorDiffuse": ]] .. collection_colors .. [[,
- "Nickname": "All Characters - ]] .. character_tooltip_map[char_label].. [[",
- "ContainedObjects": [
- ]] .. season_json_list_string .. [[
- ]
- }]]
- })
- spawned_object.use_hands = true
- is_season_bag = true
- end
- end
- -- Create bag
- if spawned_object == nil then
- spawned_object = spawnObjectJSON({
- json = char_json_map[char_label]
- })
- spawned_object.use_hands = true
- spawned_object.memo = "selfdestruct"
- end
- -- stolen code to move bag into player's hand
- local playerReference = Player[player_color]
- local charPosition = Vector(0, 0, 0)
- local screenRotation = self.getRotation()
- local xPositionOffset = 0
- local zPositionOffset = 0
- local yPositionOffset = 0
- local facingFactor = 1
- if screenRotation.z >= 90 and screenRotation.z < 270 then
- facingFactor = -1
- end
- if screenRotation.y >= 45 and screenRotation.y < 135 then
- xPositionOffset = -1.1*facingFactor*charPosition.z
- yPositionOffset = charPosition.y
- zPositionOffset = -1.1*charPosition.x
- elseif screenRotation.y >= 135 and screenRotation.y < 225 then
- xPositionOffset = -1.1*facingFactor*charPosition.x
- yPositionOffset = facingFactor*charPosition.y
- zPositionOffset = 1.1*charPosition.z
- elseif screenRotation.y >= 225 and screenRotation.y < 315 then
- xPositionOffset = 1.1*facingFactor*charPosition.z
- yPositionOffset = facingFactor*charPosition.y
- zPositionOffset = 1.1*charPosition.x
- elseif screenRotation.y >= 315 or screenRotation.y < 45 then
- xPositionOffset = 1.1*facingFactor*charPosition.x
- yPositionOffset = facingFactor*charPosition.y
- zPositionOffset = -1.1*charPosition.z
- end
- local playerHandTransform = playerReference.getHandTransform() or {
- position = {
- x = xPositionOffset + self.getPosition().x,
- y = 10 + yPositionOffset + self.getPosition().y,
- z = zPositionOffset + self.getPosition().z,
- },
- rotation = self.getRotation(),
- }
- spawned_object.setPosition(playerHandTransform.position);
- spawned_object.setRotation(playerHandTransform.rotation);
- if not is_season_bag then
- spawned_object.setScale(Vector(0.9, 0.6, 0.9))
- end
- end
- function pixelToRelativeWorldPosition(x, z, return_local)
- local x_ratio = ((x / image_dimensions.x) - 0.5) * 2
- local z_ratio = ((z / image_dimensions.z) - 0.5) * -2
- local result = Vector(
- (board_size.x / 2) * x_ratio,
- board_size.y,
- (board_size.z / 2) * z_ratio
- )
- if return_local then
- result.x = result.x * -1
- result = self.positionToLocal(self.getPosition() + result)
- end
- return result
- end
Advertisement
Add Comment
Please, Sign In to add comment