コード例 #1
0
def make_savage(tile_name, textbox_reference):
    """ Creates a request that makes a tile savage

    :param tile_name: The name of the tile to do apply the effect to
    :param textbox_reference: The textbox_reference that is used to get the ID of the tile name
    :return make_savage_request: A single-item list that contains a complete request to make a tile savage. Just append it to the main request.
    """

    make_savage_request = [
        {
            "updateTextStyle": {
                "style": {
                    "foregroundColor": {
                        "opaqueColor": {
                            "rgbColor": {
                                "blue": 0.76,
                                "green": 0.482,
                                "red": 0.194
                            }
                        }
                    },
                    "fontSize": {
                        "unit": "PT",
                        "magnitude": 8
                    }
                },
                "textRange": {
                    "type": "ALL"
                },
                "fields": "foregroundColor,fontSize",
                "objectId": textbox_reference.get(clean_string(tile_name))
            }
        }
    ]
    return make_savage_request
コード例 #2
0
def make_normal(tile_name, textbox_reference):
    """ Creates a request that makes a tile normal

    :param tile_name: The name of the tile to do apply the effect to
    :param textbox_reference: The textbox_reference that is used to get the ID of the tile name
    :return make_blighted_request: A single-item list that contains a complete request to make a tile normal. Just append it to the main request.
    """
    make_normal_request = [
        {
            "updateTextStyle": {
                "style": {
                    "fontSize": {
                        "unit": "PT",
                        "magnitude": 8
                    }
                },
                "objectId": textbox_reference.get(clean_string(tile_name)),
                "textRange": {
                    "type": "ALL"
                },
                "fields": "*"
            }
        }
    ]
    return make_normal_request
コード例 #3
0
textbox_reference = methods.create_textbox_reference(requestedSlideValues, 0)
print(textbox_reference)

# This iterates over the list of page elements
# and only adds the coordinates of the a line in an element group with a line and a shape in it
spawnpoint_reference = methods.create_spawnpoint_reference(requestedSlideValues, 0)
print(spawnpoint_reference)

for row_dirty in requestedSheetValues:
    # Sets to false if any effect is applied to the tile's text. Only used for text color stuff.
    text_default = True

    # Cleans all the row values to keep them from being problematic
    row = []
    for i in row_dirty:
        row.append(methods.clean_string(i))

    # Check to make sure that name of the row corresponds to an ID TODO: Make sure all elements on the slide have an ID!
    if textbox_reference.get(str(row[0]).strip().lower()) is not None:

        # Control blighted tiles
        if row[5] == 'blighted':
            # Something changed, so the tile no longer needs to be set to no effects
            text_default = False
            # The actual request body. Just keep this minimized
            requests_primary.append(JSON_methods.make_savage(row[0], textbox_reference))
            print("Made Blighted")

        # Apply the savage effect
        if row[4] == "savage":
            # Something changed, so the tile no longer needs to be set to no effects
コード例 #4
0
def spawn_pin(slide_page_number, tile_name, spawnpoint_reference, tribe_pin_data, unit_type, unit_type_data,
              requested_slide_values):
    """ Spawns a pin created from the pin_creation_data at the spawnpoint corresponding to the tile name name

    :param slide_page_number: Slide number of the current page to spawn the pins onto
    :param tile_name: Name of the tile that needs to have a pin spawn
    :param spawnpoint_reference: Whole spawnpoint dict created earlier
    :param tribe_pin_data: Data for the specific tribe's pin to spawn. Must be for only one tribe, the tribe in question
    :param unit_type: The type of unit, the 2 letter code in the google sheet
    :param unit_type_data: Data for the shape types associated with certain units
    :param requested_slide_values: The whole slide JSON data
    :return reference_pin_creation_dict_priority_final: Returns the ready-to-use request to create a pin. Must be fired first.
    :return reference_pin_creation_dict_secondary_final: Returns the ready-to-use request to add effects to the pin to make it look right.
    """

    try:
        alpha = ascii_letters + digits + "_"
        spawned_pin_id = "".join(random.choice(alpha) for i in range(45))

        reference_pin_creation_dict_priority = [{
            "createShape": {
                "elementProperties": {
                    "pageObjectId": "$pageObjectID",
                    "size": {
                        "height": {
                            "magnitude": 3000000,
                            "unit": "EMU"
                        },
                        "width": {
                            "magnitude": 3000000,
                            "unit": "EMU"
                        }
                    },
                    "transform": {
                        "scaleX": 0.0532,
                        "scaleY": 0.0532,
                        "shearX": 0,
                        "shearY": 0,
                        "translateX": "$translateX",
                        "translateY": "$translateY",
                        "unit": "EMU"
                    }
                },
                "objectId": "$objectID",
                "shapeType": "$shapeType"
            }}]
        reference_pin_creation_dict_secondary = [{
            "updateShapeProperties": {
                "fields": "outline,shapeBackgroundFill",
                "objectId": "$objectID",
                "shapeProperties": {
                    "outline": {
                        "outlineFill": {
                            "solidFill": {
                                "color": {
                                    "rgbColor": {
                                        "red": "$outlineFillRed",
                                        "green": "$outlineFillGreen",
                                        "blue": "$outlineFillBlue"
                                    }
                                }
                            }
                        },
                        "weight": {
                            "magnitude": 2,
                            "unit": "PT"
                        }
                    },
                    "shapeBackgroundFill": {
                        "solidFill": {
                            "color": {
                                "rgbColor": {
                                    "red": "$solidFillRed",
                                    "green": "$solidFillGreen",
                                    "blue": "$solidFillBlue"
                                }
                            }
                        }
                    }
                }
            }
        }]
        reference_pin_creation_dict_priority_template = Template(json.dumps(reference_pin_creation_dict_priority))
        reference_pin_creation_dict_secondary_template = Template(json.dumps(reference_pin_creation_dict_secondary))

        reference_pin_creation_dict_priority_final = reference_pin_creation_dict_priority_template.substitute(
            pageObjectID=find_slide_id(requested_slide_values, slide_page_number),
            objectID=spawned_pin_id,
            translateX=spawnpoint_reference.get(tile_name)[0],
            translateY=spawnpoint_reference.get(tile_name)[1],
            shapeType=unit_type_data.get(clean_string(unit_type)))

        reference_pin_creation_dict_secondary_final = reference_pin_creation_dict_secondary_template.substitute(
            objectID=spawned_pin_id,
            outlineFillRed=tribe_pin_data.get("outlineFillRed"),
            outlineFillGreen=tribe_pin_data.get("outlineFillGreen"),
            outlineFillBlue=tribe_pin_data.get("outlineFillBlue"),
            solidFillRed=tribe_pin_data.get("solidFillRed"),
            solidFillGreen=tribe_pin_data.get("solidFillGreen"),
            solidFillBlue=tribe_pin_data.get("solidFillBlue"))

        return json.loads(reference_pin_creation_dict_priority_final), \
               json.loads(reference_pin_creation_dict_secondary_final)
    except TypeError:
        pass