コード例 #1
0
ファイル: views.py プロジェクト: dotkrnl/rabot
def stage_info_view(request, sid):
    sid = int(sid)
    manager = StageManager()

    if request.method == 'GET':
        cur_stage = manager.get_stage(sid)
        if cur_stage:
            return HttpResponse(json.dumps({
                'status': 'succeeded',
                'sid': cur_stage.sid,
                'name': cur_stage.name,
                'info': cur_stage.info,
            }))
        else:
            return HttpResponse(json.dumps({
                'status': 'not_exist',
            }))
    else:
        raise Http404
コード例 #2
0
ファイル: views.py プロジェクト: dotkrnl/rabot
def all_stages_info_view(request):
    manager = StageManager()

    if request.method == 'GET':
        all_stages = manager.get_all_stages()
        results = []

        for stage in all_stages:
            cur_stage = {
                'sid': int(stage.sid),
                'name': stage.name,
                'info': stage.info,
            }
            results.append(cur_stage)

        return HttpResponse(json.dumps(results))

    else:
        raise Http404
コード例 #3
0
ファイル: views.py プロジェクト: dotkrnl/rabot
def stage_modify(request):
    manager = StageManager()

    if request.method == 'POST':
        data = json.loads(request.body.decode())
        action = data['action']

        if action == 'add':
            sid = int(data['sid'])
            name = data['name']
            info = data['info']
            result = manager.add_stage(sid, name, info)

        elif action == 'delete':
            sid = int(data['sid'])
            result = manager.delete_stage(sid)

        elif action == 'update':
            sid = int(data['sid'])
            new_name = data['name']
            new_info = data['info']
            result = manager.update_stage(sid, new_name, new_info)

        else:
            result = ''

        if result == '':
            response_data = {}
        elif result[:9] == 'Succeeded':
            response_data = {
                'result': 'succeeded',
            }
        else:
            response_data = {
                'result': 'failed',
                'errorMessage': result,
            }

        return HttpResponse(json.dumps(response_data))

    else:
        raise Http404
コード例 #4
0
ファイル: addstages.py プロジェクト: dotkrnl/rabot
    def handle(self, *args, **options):
        manager = StageManager()
        manager.clear()

        nameArray = [
            ["welcome", "carrot", "river", "key & door", "path"],
            ["welcome", "carrot", "river", "key & door", "path"],
            ["leaf", "frog", "ice", "rain", "spring"],
            ["cake", "apple", "pear", "new carrot", "strawberry"],
            ["cake", "apple", "pear", "new carrot", "strawberry"]
        ]

        sid = 10
        name = '__meta_all_stage_packages'
        info = """
        [101, 102, 103]
        """
        manager.add_stage(sid, name, info)

        sid = 101
        name = 'Beginner\'s Gressland'
        info = """
        {
            "background": "grassland.png",
            "stages": [1001, 1002, 1003, 1004, 1005]
        }
        """
        manager.add_stage(sid, name, info)

        sid = 102
        name = 'Branch Forest'
        info = """
        {
            "background": "forest.png",
            "stages": [2001, 2002, 2003, 2004, 2005]
        }
        """
        manager.add_stage(sid, name, info)

        sid = 103
        name = 'Loop River'
        info = """
        {
            "background": "river.png",
            "stages": [3001, 3002, 3003, 3004, 3005]
        }
        """
        manager.add_stage(sid, name, info)

        for i in range(0, 4):
            sid = 1000 * i + 1
            name = nameArray[i][0]
            info = """
            [
                {
                    "type":"carrot",
                    "region":{"radius":40},
                    "image":{"name":"carrot.svg","width":160,"height":160},
                    "x":500,
                    "y":100
                },
                {
                    "type":"rabbit",
                    "image":{"name":"rabbit.svg","width":160,"height":160},
                    "x":500,
                    "y":700
                }
            ]
            """
            manager.add_stage(sid, name, info)

            sid = 1000 * i + 2
            name = nameArray[i][1]
            info = """
            [
                {
                    "type":"carrot",
                    "region":{"radius":40},
                    "image":{"name":"carrot.svg","width":160,"height":160},
                    "x":500,
                    "y":100
                },
                {
                    "type":"carrot",
                    "region":{"radius":40},
                    "image":{"name":"carrot.svg","width":160,"height":160},
                    "x":500,
                    "y":400
                },
                {
                    "type":"rabbit",
                    "image":{"name":"rabbit.svg","width":160,"height":160},
                    "x":500,
                    "y":700
                }
            ]
            """
            manager.add_stage(sid, name, info)

            sid = 1000 * i + 3
            name = nameArray[i][2]
            info = """
            [
                {
                    "type":"carrot",
                    "region":{"radius":40},
                    "image":{"name":"carrot.svg","width":160,"height":160},
                    "x":500,
                    "y":100
                },
                {
                    "type":"staticimage",
                    "image":{"name":"river.svg","x":0,"y":300,"width":1000,"height":200}
                },
                {
                    "type":"staticimage",
                    "image":{"name":"bridge.png","x":600,"y":260,"width":280,"height":280}
                },
                {
                    "type":"rabbit",
                    "image":{"name":"rabbit.svg","width":160,"height":160},
                    "x":500,
                    "y":700
                },
                {
                    "type":"river",
                    "region":{"width":600,"height":200},
                    "x":300,
                    "y":400
                }
            ]
            """
            manager.add_stage(sid, name, info)

            sid = 1000 * i + 4
            name = nameArray[i][3]
            info = """
            [
                {
                    "type":"carrot",
                    "region":{"radius":40},
                    "image":{"name":"carrot.svg","width":160,"height":160},
                    "x":500,
                    "y":100
                },
                {
                    "type":"staticimage",
                    "image":{"name":"river.svg","x":0,"y":300,"width":1000,"height":200}
                },
                {
                    "type":"staticimage",
                    "image":{"name":"bridge.png","x":600,"y":260,"width":280,"height":280}
                },
                {
                    "type":"rabbit",
                    "image":{"name":"rabbit.svg","width":160,"height":160},
                    "x":500,
                    "y":700
                },
                {
                    "type":"river",
                    "region":{"width":600,"height":200},
                    "x":300,
                    "y":400
                },
                {
                    "type":"key",
                    "image":{"name":"key.svg","width":100,"height":100},
                    "region":{"width":100,"height":100},
                    "x":300,
                    "y":800
                },
                {
                    "type":"door",
                    "image":{"name":"door.svg","width":200,"height":200},
                    "region":{"width":200,"height":200},
                    "x":750,
                    "y":400
                }
            ]
            """
            manager.add_stage(sid, name, info)

            sid = 1000 * i + 5
            name = nameArray[i][4]
            info = """[
                {"type":"river","x":0,"y":150,"width":400,"height":75},
                {"type":"river","x":475,"y":150,"width":400,"height":75},
                {"type":"carrot","x":300,"y":50,"radius":40},
                {"type":"rabbit","x":300,"y":370,"angle":0,"radius":40},
                {"type":"key","x":100,"y":400,"keyId":0,"radius":40},
                {"type":"door","x":400,"y":150,"width":75,"height":75,"keyId":0},
                {"type":"rotator","x":400,"y":400,"rotation":90,"radius":40}
              ]"""
            manager.add_stage(sid, name, info)