File size: 4,850 Bytes
f27460e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d8cee44
 
f27460e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import gradio as gr

# Default configuration template
default_config = {
    'background': '/AutoGameBackgrounds/1stGameLoc123.png',
    'inventory': [],
    'skills': [],
    'objectives': [],
    'targets': [],
    'story': [],
    'actions': {}
}

# Helper functions to dynamically add items
def add_inventory_item(inventory_items, type, name, description):
    new_item = {"type": type, "name": name, "description": description}
    inventory_items.append(new_item)
    return inventory_items

def add_skill(skills_items, branch, name, learned):
    new_skill = {"branch": branch, "name": name, "learned": learned == 'True'}
    skills_items.append(new_skill)
    return skills_items

def add_objective(objectives_items, id, name, complete):
    new_objective = {"id": id, "name": name, "complete": complete == 'True'}
    objectives_items.append(new_objective)
    return objectives_items

def add_target(targets_items, name, x, y, collisionType, collisiontext):
    new_target = {"name": name, "x": int(x), "y": int(y), "collisionType": collisionType, "collisiontext": collisiontext}
    targets_items.append(new_target)
    return targets_items

with gr.Blocks() as demo:
    gr.HTML("Companion Space for zerogpu workflow planning for a way to send a zip to the Basic Game Engine at the bottom of https://huggingface.co/spaces/KwabsHug/TestSvelteStatic")
    gr.HTML("Some conderations for future integration: https://huggingface.co/spaces/dylanebert/3d-arena, https://github.com/fudan-generative-vision/hallo")
    inventory_items = gr.State([])
    skills_items = gr.State([])
    objectives_items = gr.State([])
    targets_items = gr.State([])

    with gr.Tabs():
        with gr.TabItem("Inventory"):
            inventory_type = gr.Textbox(label="Type")
            inventory_name = gr.Textbox(label="Name")
            inventory_description = gr.Textbox(label="Description")
            add_inventory = gr.Button("Add Inventory Item")
            inventory_textbox = gr.JSON(label="Inventory Items", value=[])

        with gr.TabItem("Skills"):
            skills_branch = gr.Textbox(label="Branch")
            skills_name = gr.Textbox(label="Name")
            skills_learned = gr.Dropdown(choices=["True", "False"], label="Learned")
            add_skill_button = gr.Button("Add Skill")
            skills_textbox = gr.JSON(label="Skills", value=[])

        with gr.TabItem("Objectives"):
            objectives_id = gr.Textbox(label="ID")
            objectives_name = gr.Textbox(label="Name")
            objectives_complete = gr.Dropdown(choices=["True", "False"], label="Complete")
            add_objective_button = gr.Button("Add Objective")
            objectives_textbox = gr.JSON(label="Objectives", value=[])

        with gr.TabItem("Targets"):
            targets_name = gr.Textbox(label="Name")
            targets_x = gr.Textbox(label="X Coordinate")
            targets_y = gr.Textbox(label="Y Coordinate")
            targets_collisionType = gr.Textbox(label="Collision Type")
            targets_collisiontext = gr.Textbox(label="Collision Text")
            add_target_button = gr.Button("Add Target")
            targets_textbox = gr.JSON(label="Targets", value=[])

    config_output = gr.JSON(label="Updated Configuration")

    @gr.render(inputs=[inventory_items, skills_items, objectives_items, targets_items]) #, outputs=config_output)
    def aggregate_config(inventory, skills, objectives, targets):
        config = default_config.copy()
        config['inventory'] = inventory
        config['skills'] = skills
        config['objectives'] = objectives
        config['targets'] = targets
        return config

    add_inventory.click(add_inventory_item, inputs=[inventory_items, inventory_type, inventory_name, inventory_description], outputs=inventory_textbox)
    add_inventory.click(aggregate_config, inputs=[inventory_items, skills_items, objectives_items, targets_items], outputs=config_output)

    add_skill_button.click(add_skill, inputs=[skills_items, skills_branch, skills_name, skills_learned], outputs=skills_textbox)
    add_skill_button.click(aggregate_config, inputs=[inventory_items, skills_items, objectives_items, targets_items], outputs=config_output)

    add_objective_button.click(add_objective, inputs=[objectives_items, objectives_id, objectives_name, objectives_complete], outputs=objectives_textbox)
    add_objective_button.click(aggregate_config, inputs=[inventory_items, skills_items, objectives_items, targets_items], outputs=config_output)

    add_target_button.click(add_target, inputs=[targets_items, targets_name, targets_x, targets_y, targets_collisionType, targets_collisiontext], outputs=targets_textbox)
    add_target_button.click(aggregate_config, inputs=[inventory_items, skills_items, objectives_items, targets_items], outputs=config_output)

demo.launch()