예제 #1
0
파일: views.py 프로젝트: chrismcmath/Lucura
def new_game(request):
	#Create a new game
	game = Game(
		title = 'New Game',
		description = 'Write a description here',
		author = request.user,
		pubDate = datetime.datetime.now(),
		lastEditDate = datetime.datetime.now())
	game.save()
	
	layer = Layer(
		gameID = game,
		layerID = 0,
		goal = 0,
		target = 1,
		timeLimit = 5,
		instruction = '"edit this instruction"',
		background = '"#a4c4c3"',
		xGrav = 0,
		yGrav = 10)
	layer.save()

	return redirect('/build/' + str(game.id))
예제 #2
0
def save_game(request):
	if request.method == 'POST':
		info = json.loads(request.body);

		game = Game.objects.get(pk=info.get('ID'))
		game.title = info.get('title')
		game.description= info.get('description')
		# game.lastEditDate = datetime.datetime.now()
		game.author = User.objects.get(username='******')
		game.save()
		
		layers = info.get('layers')
		for lr in layers:
		 	layer = Layer(gameID = game, layerID = lr.get('ID'))
		 	layer.save()
 			# pdb.set_trace()
		 	blocks = lr.get('Blocks')
		 	for b in blocks:
		 		block = Block(layerID = layer, blockID = b.get('ID'),
		 			position = b.get('Position'), scale = b.get('Scale'),
		 			rotation = b.get('Rotation'), blockType = b.get('Type'))
		 		block.save()
		
	return HttpResponse(request.body, mimetype="application/json")
예제 #3
0
파일: views.py 프로젝트: chrismcmath/Lucura
def save_game(request):
	if request.method == 'POST':
		info = json.loads(request.body);

		game = Game.objects.get(pk=info.get('ID'))
		game.title = info.get('title')
		game.description= info.get('description')
		game.lastEditDate = datetime.datetime.now()
		game.author = request.user
		game.save()
		
		layers = info.get('layers')
		for lr in layers:
			if(Layer.objects.filter(layerID = lr.get('ID'), gameID = game).count()):
				#if already exists, update
				layer = Layer.objects.get(layerID = lr.get('ID'), gameID = game)
				layer.goal = lr.get('Goal')
				layer.target = lr.get('Target')
				layer.timeLimit = lr.get('TimeLimit')
				layer.instruction = lr.get('Instruction')
				layer.background = lr.get('Background')
				layer.xGrav = lr.get('gravX')
				layer.yGrav = lr.get('gravY')
			else:
				#create new layer
				layer = Layer(gameID = game,
				layerID = lr.get('ID'),
				goal = lr.get('Goal'),
				target = lr.get('Target'),
				timeLimit = lr.get('TimeLimit'),
				instruction = lr.get('Instruction'),
				background = lr.get('Background'),
				xGrav = lr.get('gravX'),
				yGrav = lr.get('gravY'))
		 	layer.save()
		 	
		 	blocks = lr.get('Blocks')
		 	for tempBlock in blocks:
		 		if(Block.objects.filter(layerID = layer, blockID = tempBlock.get('ID')).count()):
		 			#BLOCK already exists, update
		 			block = Block.objects.get(layerID = layer, blockID = tempBlock.get('ID'))
		 			block.position = tempBlock.get('Position')
		 			block.size = tempBlock.get('Size')
			 		block.scale = tempBlock.get('Scale')
			 		block.rotation = int(round(float(tempBlock.get('Rotation'))))
			 		block.blockType = tempBlock.get('Type')
			 		block.parentLayer = tempBlock.get('ParentLayer')
			 		block.fill = tempBlock.get('Fill')
			 		block.points = tempBlock.get('Points')
			 		block.movement = tempBlock.get('Movement')
			 		block.nodeData = tempBlock.get('NodeData')
			 		block.isTarget = tempBlock.get('IsTarget')
			 		block.text = tempBlock.get('Text')
			 		block.fontFamily = tempBlock.get('FontFamily')
			 		block.fontSize = tempBlock.get('FontSize')
			 		block.fontColour = tempBlock.get('FontColour')
		 		else:
			 		block = Block(layerID = layer,
			 		blockID = tempBlock.get('ID'),
			 		position = tempBlock.get('Position'),
			 		size = tempBlock.get('Size'),
			 		scale = tempBlock.get('Scale'),
			 		rotation = int(round(float(tempBlock.get('Rotation')))),
			 		blockType = tempBlock.get('Type'),
			 		parentLayer = tempBlock.get('ParentLayer'),
			 		fill = tempBlock.get('Fill'),
			 		points = tempBlock.get('Points'),
			 		movement = tempBlock.get('Movement'),
			 		nodeData = tempBlock.get('NodeData'),
			 		isTarget = tempBlock.get('IsTarget'),
			 		text = tempBlock.get('Text'),
			 		fontFamily = tempBlock.get('FontFamily'),
			 		fontSize = tempBlock.get('FontSize'),
			 		fontColour = tempBlock.get('FontColour'))
		 		block.save()
	return HttpResponse(request.body, mimetype="application/json")