ccdom

0.0.31 • Public • Published

주의사항: repeat에는 배열이 사용되는데, 배열의 element는 object여야함... 그래야 $index 속성이 추가됨.

주의사항2: scope간 prototype으로 상속이 이루어짐... 그래서 child scope에서 root scope의 객체를 액세스가 가능하지만, 대입하면 child scope만의 객체로서 만들어지고 root scope의 객체는 영향받지 않음

lobby scene example!!

modules

helper = require './helper'
pop_msg_node = require './pop-node'
R = require './r'
yes_no = require './yes-no'
ccdom = require 'ccdom'
select_friends = require './select-friends'

module.exports = (cb_remote) ->
	template =
		type: 'scene'
		controller: 'AppCtrl'
		children: [
			type: 'layer_color'
			controller: 'LayerCtrl'
			color: '{{this.white}}'
			children: [
				{
					# main title
					type: 'label'
					font_size: 75
					text: '알까기 게임...!'
					anchor: '0 0'
					color: '149 149 79 255'
				}
				{
					# announcments
					type: 'node'
					pos: '0 {{this.win_size.height}}'
					anchor: '0 1'
					repeat: {
						bind: 'item in ann_items'
						template: {
							type: 'label'
							font_size: 30
							text: '{{this.item.text}}'
							pos: '0 {{this.item.$index * -35}}'
							anchor: '0 1'
							color: '{{this.black}}'
						}
					}
				}
				{
					# main menu
					type: 'menu'
					pos: '{{this.win_size.width}} 0'
					anchor: '1 0'
					children: [
						{
							type: 'label_item'
							show: '{{this.conn}}'
							text: '친구와 한 판 한다'
							callback: '{{this.matchWithFriend}}'
							pos: '0 200'
							anchor: '1 0'
							color: '{{this.menu_color}}'
							font_size: 45
						}
						{
							type: 'label_item'
							text: '다른 게임을 한다'
							callback: '{{this.another_game}}'
							pos: '0 100'
							anchor: '1 0'
							color: '{{this.menu_color}}'
							font_size: 45
						}
						{
							type: 'label_item'
							text: '그만한다'
							callback: '{{this.end_game}}'
							pos: '0 0'
							anchor: '1 0'
							color: '{{this.menu_color}}'
							font_size: 45
						}
					]
				}
			]
		]

	ctrlers =
		AppCtrl: ($scope) ->
			$scope.font_name = 'Arial'
			$scope.win_size = director.getWinSize()
			$scope.black = '0 0 0 255'
			$scope.white = '255 255 255 255'
			$scope.menu_color = '73 62 32 255'
			$scope.conn = false
			$scope.ann_items = []
			$scope.end_game = ->
				director.end()
			$scope.another_game = ->
				__jsc__.selectGame()

		LayerCtrl: ($scope) ->
#			$scope.pop_node = pop_msg_node [$scope.win_size.width/2, $scope.win_size.height - 150]
#			@addChild $scope.pop_node
#			$scope.pop_node.push_msg (CurrentUser?.name or '아무개') + '님 반갑습니다'

			$scope.$watch 'this.conn', ->
				$scope.$update()
			$scope.$watch 'this.ann_items', ->
				$scope.$update()

			cb_remote (remote) ->
				$scope.$apply ->
					$scope.conn = true
					$scope.matchWithFriend = ->
						select_friends cb_remote, (res, friend_id) ->
							if res
								remote.req_match_with friend_id, (err) ->
									unless err
	#									pop_node.push_msg '대국이 곧 시작됩니다. 접속 중 입니다', 3
									else
	#									pop_node.push_msg err, 3

				remote.req_annouce (item) ->
					$scope.$apply ->
						$scope.ann_items.push item

	scene = ccdom template, ctrlers
	director.replaceScene scene

	scene.handlers = {}
	scene.handlers.req_match_with = ( user, cb ) ->
		yes_no user.name + '님이 대국을 원하십니다.', cb		
	
	scene

Readme

Keywords

none

Package Sidebar

Install

npm i ccdom

Weekly Downloads

2

Version

0.0.31

License

BSD

Last publish

Collaborators

  • seobyeongky