Skip to content

Commit 6206a47

Browse files
committed
small project refactoring
1 parent efb9bb0 commit 6206a47

25 files changed

+244
-136
lines changed

.gitmodules

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[submodule "src/Gamz/PuyoBundle"]
22
path = src/Gamz/PuyoBundle
33
url = [email protected]:gamz/GamzPuyoBundle.git
4-
[submodule "src/Gamz/TypefastrBundle"]
5-
path = src/Gamz/TypefastrBundle
6-
url = [email protected]:gamz/GamzTypefastrBundle.git
4+
[submodule "src/Gamz/TypeBundle"]
5+
path = src/Gamz/TypeBundle
6+
url = [email protected]:gamz/GamzTypeBundle.git

app/AppKernel.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use Symfony\Component\HttpKernel\Kernel;
44
use Symfony\Component\Config\Loader\LoaderInterface;
55

6-
abstract class AppKernel extends Kernel
6+
class AppKernel extends Kernel
77
{
88
public function registerBundles()
99
{
@@ -17,6 +17,9 @@ public function registerBundles()
1717
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
1818
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
1919
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
20+
new Gamz\PuyoBundle\GamzPuyoBundle(),
21+
new Gamz\TypeBundle\GamzTypeBundle(),
22+
new Gamz\GamzBundle\GamzGamzBundle(),
2023
);
2124

2225
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
@@ -31,11 +34,10 @@ public function registerBundles()
3134
public function registerContainerConfiguration(LoaderInterface $loader)
3235
{
3336
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
34-
$loader->load(__DIR__.'/../src/Gamz/'.ucfirst(GAME).'Bundle/Resources/config/config.yml');
3537
}
3638

3739
public function getCacheDir()
3840
{
39-
return $this->rootDir.'/cache/'.GAME.'/'.$this->environment;
41+
return $this->rootDir.'/cache/'.$this->environment;
4042
}
4143
}

app/PuyoKernel.php

-15
This file was deleted.
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
class gamz.board.Matrix
2+
constructor: (@width, @height) -> @empty()
3+
empty: -> @cells = {}
4+
length: -> length = 0 ; (if not cell.empty() then length += 1) for cell of @cells ; length
5+
id: (x, y) -> x+','+y
6+
available: (x, y) -> @get(x, y).available()
7+
get: (x, y) -> id = @id x, y ; if @cells[id]? then @cells[id] else if @inside x, y then new gamz.board.Cell x, y, @ else new gamz.board.InvalidCell(x, y, @)
8+
set: (cell, x, y) -> cell.x = x ; cell.y = y ; @cells[@id x, y] = cell
9+
add: (cell) -> if @available cell.x, cell.y then @set cell, cell.x, cell.y ; true else false
10+
pop: (x, y) -> cell = @get x, y ; @remove x, y ; cell
11+
remove: (x, y) -> delete @cells[@id x, y]
12+
move: (cell, x, y) -> if @available x, y then @set @pop(cell.x, cell.y), x, y
13+
inside: (x, y) -> 0 <= x < @width and 0 <= y < @height
14+
15+
class gamz.board.AbstractCell
16+
constructor: (@x, @y, matrix) -> if matrix? then @bind matrix
17+
bind: (matrix) -> if matrix.add @ then @matrix = matrix ; true else false
18+
unbind: -> (if @bound() then @matrix.remove @x, @y) ; @matrix = null
19+
bound: -> @matrix?
20+
neighbor: (dx, dy) -> @matrix?.get @x+dx, @y+dy
21+
remove: -> @matrix?.remove @x, @y
22+
test: (dx, dy) -> @matrix?.available @x+dx, @y+dy
23+
24+
class gamz.board.InvalidCell extends gamz.board.AbstractCell
25+
available: -> false
26+
empty: -> true
27+
28+
class gamz.board.Cell extends gamz.board.AbstractCell
29+
available: -> @empty()
30+
empty: -> not @content?
31+
move: (dx, dy) -> @matrix?.move @, @x+dx, @y+dy
32+
push: (@content) ->
33+
pop: -> content = @content ; @remove() ; content
34+
35+
class gamz.board.Group
36+
constructor: (root) -> @cells = [] ; @add root
37+
add: (cell) -> if not @has cell then (@cells.push cell ; true) else false
38+
has: (cell) -> cell in @cells
39+
size: -> @cells.length
40+
41+
class gamz.board.ContentGroup extends gamz.board.Group
42+
add: (cell) -> if super(cell) then (if @match cell, neighbor then @add neighbor) for neighbor in @neighborhood cell
43+
neighborhood: (cell) -> [cell.neighbor(0, 1), cell.neighbor(0, -1), cell.neighbor(1, 0), cell.neighbor(-1, 0)]
44+
match: (cell, neighbor) -> neighbor?.content?
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class gamz.event.Dispatcher
2+
constructor: -> @listeners = {} ; @reflection = new gamz.utils.Reflection()
3+
dispatch: (event, args...) -> if @listeners[event]? then listener[0].apply listener[1], args for listener in @listeners[event]
4+
bind: (event, func, subject=@) -> (if not @listeners[event]? then @listeners[event] = []) ; @listeners[event].push [func, subject]
5+
unbind: (func) -> ((if listener[0] is func then listeners.splice(index, 1)) for listener, index in listeners) for event, listeners of @listeners
6+
subscribe: (obj) -> @bind name, meth, obj for name, meth of @reflection.methods obj ; console.log @reflection.methods obj
7+
unsubscribe: (obj) -> ((if listener[1] is obj then listeners.splice(index, 1)) for listener, index in listeners) for event, listeners of @listeners
8+
9+
class gamz.event.Pulsar
10+
constructor: (@dispatcher, start, stop, @time) ->
11+
@dispatcher.bind start, (args...)=> @start(args)
12+
@dispatcher.bind stop, ()=> @stop()
13+
@pulsar = new gamz.utils.Pulsar (()=> @trigger()), @time
14+
@listeners = [] ; @sleeping = false
15+
start: (@args) -> if not @sleeping then @args = args ; @pulsar.start(true) ; @sleep()
16+
stop: -> @pulsar.stop()
17+
bind: (func, subject=@) -> @listeners.push [func, subject]
18+
trigger: -> listener[0].apply listener[1], @args for listener in @listeners
19+
sleep: -> @sleeping = true ; setTimeout (()=> @sleeping = false), @time

app/Resources/assets/gamz/geom.coffee

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
class gamz.geom.Coords
2+
constructor: (@x, @y) ->
3+
clone: -> new gamz.geom.Coords @x, @y
4+
add: (coords) -> @x += coords.x ; @y += coords.y ; (@)
5+
sub: (coords) -> @x -= coords.x ; @y -= coords.y ; (@)
6+
mul: (coords) -> @x *= coords.x ; @y *= coords.y ; (@)
7+
8+
class gamz.geom.Point extends gamz.geom.Coords
9+
clone: -> new gamz.geom.Point @x, @y
10+
vector: (point) -> new gamz.geom.Vector point.x-@x, point.y-@y
11+
line: (point) -> @vector(point).line point
12+
box: (point) -> new gamz.geom.Box Math.min(@x, point.x), Math.min(@y, point.y), Math.abs(@x-point.x), Math.abs(@y-point.y)
13+
dist: (point) -> @vector(point).norm()
14+
translate: (vector) -> @add vector
15+
rotate: (angle, point) -> @translate(@vector point).translate(point.vector(@).rotate angle)
16+
17+
class gamz.geom.Vector extends gamz.geom.Coords
18+
clone: -> new gamz.geom.Vector @x, @y
19+
reverse: -> @x = -@x ; @y = -@y ; (@)
20+
rotate: (angle) -> @angle @angle+angle
21+
opposite: -> @clone().reverse()
22+
norm: (norm) -> if norm? then @mult norm/@norm() else Math.sqrt Math.pow(@x, 2)+Math.pow(@y, 2)
23+
angle: (angle) -> norm = @norm() ; (if angle? then @x = norm*Math.cos angle ; @y = norm*Math.sin angle else angle = Math.acos @x/norm ; (if @y < 0 then angle += Math.PI)) ; (@)
24+
isnull: -> @x is 0 and @y is 0
25+
line: (point) ->
26+
if @isnull() then return null
27+
if @x is 0 then return new gamz.geom.HorizontalLine point.y
28+
if @y is 0 then return new gamz.geom.VerticalLine point.x
29+
a = @x/@y ; new gamz.geom.ObliqueLine a, point.y-a*point.x
30+
31+
class gamz.geom.Box
32+
constructor: (@x, @y, @w, @h) ->
33+
clone: -> new gamz.geom.Box @x, @y, w, h
34+
contains: (point) -> (@x <= point.x <= @x+@w) and (@y <= point.y <= @y+@h)
35+
36+
class gamz.geom.ObliqueLine
37+
constructor: (@a, @b) ->
38+
clone: -> new gamz.geom.ObliqueLine @a, @b
39+
slope: -> @a
40+
parallel: (line) -> line instanceof gamz.geom.ObliqueLine and @a is line.a
41+
cross: (line) ->
42+
if @parallel line then return null
43+
if line instanceof gamz.geom.ObliqueLine then new gamz.geom.Vector (line.b-@b)/ @a-line.a, (@a*(line.b-@b)/ @a-line.a)+@b
44+
else line.cross @
45+
46+
class gamz.geom.HorizontalLine
47+
constructor: (@y) ->
48+
clone: -> new gamz.geom.HorizontalLine @y
49+
slope: -> 0
50+
parallel: (line) -> line instanceof gamz.geom.HorizontalLine
51+
cross: (line) ->
52+
if @parallel line then return null
53+
if line instanceof gamz.geom.ObliqueLine then new gamz.geom.Vector (@y-line.b)/ line.a, @y
54+
else new gamz.geom.Vector @x, line.y
55+
56+
class gamz.geom.VerticalLine
57+
constructor: (@x) ->
58+
clone: -> new gamz.geom.VerticalLine @x
59+
slope: -> Infinity
60+
parallel: (line) -> line instanceof gamz.geom.VerticalLine
61+
cross: (line) ->
62+
if @parallel line then return null
63+
if line instanceof gamz.geom.ObliqueLine then new gamz.geom.Vector @x, line.a*@x+line.b
64+
else line.cross @
65+
66+
class gamz.geom.Segment
67+
constructor: (@p1, @p2) ->
68+
clone: -> new gamz.geom.Segment @p1.clone(), @p2.clone()
69+
length: -> Math.sqrt Math.pow(@width(), 2)+Math.pow(@height(), 2)
70+
vector: -> p1.vector p2
71+
line: -> p1.line p2
72+
box: -> p1.box p2

app/Resources/assets/gamz/main.coffee

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@gamz =
2+
geom: {}
3+
utils: {}
4+
event: {}
5+
board: {}
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class gamz.utils.Reflection
2+
filter: (obj, func) -> map = {} ; (if key isnt 'constructor' and func(key, val) then map[key] = val) for key, val of obj ; map
3+
values: (obj, filter) -> obj[key] for key, val of (if filter? then @filter(obj, filter) else obj)
4+
keys: (obj, filter) -> key for key, val of (if filter? then @filter(obj, filter) else obj)
5+
types: (obj, type) -> @filter obj, (key, val)-> typeof val is type
6+
methods: (obj) -> @types obj, 'function'
7+
scalars: (obj) -> @filter obj, (key, val)-> typeof val not in ['function', 'object', 'array']
8+
9+
class gamz.utils.Pulsar
10+
constructor: (@func, @time) ->
11+
start: (call=false) -> if not @started then @started = true ; (if call then @call() else @schedule()) ; true else false
12+
stop: -> if @started then @unschedule() ; @started = false ; true else false
13+
reset: -> started = @started ; @stop() ; @start() ; started
14+
schedule: -> @timer = setTimeout (()=> @call()), @time
15+
unschedule: -> clearTimeout(@timer)
16+
call: -> @schedule() ; if @started then @func.call @

app/Resources/views/gamz.html.twig

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{% javascripts filter="coffee" output="media/common/gamz.js"
2+
"%kernel.root_dir%/Resources/assets/gamz/main.coffee"
3+
"%kernel.root_dir%/Resources/assets/gamz/utils.coffee"
4+
"%kernel.root_dir%/Resources/assets/gamz/event.coffee"
5+
"%kernel.root_dir%/Resources/assets/gamz/geom.coffee"
6+
%}
7+
<script type="text/javascript" src="{{ asset_url }}"></script>
8+
{% endjavascripts %}

app/TypefastrKernel.php

-15
This file was deleted.

app/config/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ framework:
77
translator: { fallback: %locale% }
88
secret: %secret%
99
charset: UTF-8
10-
router: { resource: "%kernel.root_dir%/config/routing.php" }
10+
router: { resource: "%kernel.root_dir%/config/routing.yml" }
1111
form: true
1212
csrf_protection: true
1313
validation: { enable_annotations: true }

app/config/routing.php

-9
This file was deleted.

app/config/routing.yml

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
_internal:
22
resource: "@FrameworkBundle/Resources/config/routing/internal.xml"
33
prefix: /_internal
4+
5+
_gamz:
6+
resource: "@GamzGamzBundle/Resources/config/routing.yml"
7+
prefix: /
8+
9+
_puyo:
10+
resource: "@GamzPuyoBundle/Resources/config/routing.yml"
11+
prefix: /puyo

app/config/routing_dev.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,5 @@ _profiler:
1010
resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
1111
prefix: /_profiler
1212

13-
_configurator:
14-
resource: "@SensioDistributionBundle/Resources/config/routing/webconfigurator.xml"
15-
prefix: /_configurator
16-
1713
_main:
18-
resource: routing.php
14+
resource: routing.yml

puyo

-22
This file was deleted.

src/Gamz/AlkaBundle/Resources/assets/alka/ball.coffee

Whitespace-only changes.

src/Gamz/AlkaBundle/Resources/assets/alka/board.coffee

Whitespace-only changes.

src/Gamz/GamzBundle/Resources/config/config.yml

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{% extends "::layout.html.twig" %}
2+
3+
{% block assets %}
4+
5+
<link href="http://fonts.googleapis.com/css?family=Marvel:700" rel="stylesheet" type="text/css">
6+
<link href="http://fonts.googleapis.com/css?family=Rosario" rel="stylesheet" type="text/css">
7+
<link href="http://fonts.googleapis.com/css?family=Syncopate:700" rel="stylesheet" type="text/css">
8+
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
9+
10+
{% stylesheets filter="compass" output="media/puyo/layout.css"
11+
"@GamzPuyoBundle/Resources/assets/styles/layout.skeleton.sass"
12+
"@GamzPuyoBundle/Resources/assets/styles/layout.header.sass"
13+
"@GamzPuyoBundle/Resources/assets/styles/layout.footer.sass"
14+
%}
15+
<link rel="stylesheet" href="{{ asset_url }}" />
16+
{% endstylesheets %}
17+
18+
{% javascripts filter="coffee" output="media/puyo/layout.js"
19+
"@GamzPuyoBundle/Resources/assets/scripts/layout.coffee"
20+
%}
21+
<script type="text/javascript" src="{{ asset_url }}"></script>
22+
{% endjavascripts %}
23+
24+
{% endblock %}
25+
26+
{% block header %}
27+
28+
<h1>ぷよぷよ</h1>
29+
30+
{% macro menu_item(name, label, path, current) %}
31+
<li class="{{ name }}{% if current %} current{% endif %}">
32+
<a{% if path %} href="{{ path }}"{% endif %}>{{ label }}</a>
33+
</li>
34+
{% endmacro %}
35+
36+
<ul id="menu">
37+
{{ _self.menu_item('game', 'New game', path('puyo_game_modes'), currentMenu is defined and currentMenu == 'game') }}
38+
{{ _self.menu_item('scores', 'Hi scores', null, currentMenu is defined and currentMenu == 'scores') }}
39+
{{ _self.menu_item('profile', 'My profile', null, currentMenu is defined and currentMenu == 'profile') }}
40+
{{ _self.menu_item('events', 'My events', null, currentMenu is defined and currentMenu == 'friends') }}
41+
{{ _self.menu_item('wish', 'Wish box', null, currentMenu is defined and currentMenu == 'wish') }}
42+
</ul>
43+
44+
{% endblock %}
45+
46+
{% block footer %}
47+
48+
<p>
49+
Powered by
50+
<a target="_blank" href="http://symfony.com">Symfony2</a>,
51+
<a target="_blank" href="http://jashkenas.github.com/coffee-script/">CoffeeScript</a>,
52+
<a target="_blank" href="http://raphaeljs.com">Raphaël</a>,
53+
<a target="_blank" href="http://compass-style.org/">Compass</a> &
54+
<a target="_blank" href="http://jquery.com/">jQuery</a>
55+
</p>
56+
57+
{% endblock %}

typefastr

-22
This file was deleted.

0 commit comments

Comments
 (0)