Many files move to under "arescue" directory.
--- /dev/null
+try:\r
+ __import__('pkg_resources').declare_namespace(__name__)\r
+except ImportError:\r
+ from pkgutil import extend_path\r
+ __path__ = extend_path(__path__, __name__)\r
--- /dev/null
+<?xml version="1.0" ?>
+<stageitem_list name="test_items">
+ <stageitem name="rock" x="0" y="0"/>
+ <stageitem name="rock" x="1" y="0"/>
+ <stageitem name="rock" x="0" y="1"/>
+ <stageitem name="rock" x="2" y="0"/>
+ <stageitem name="rock" x="3" y="0"/>
+ <stageitem name="rock" x="4" y="0"/>
+ <stageitem name="rock" x="5" y="0"/>
+ <stageitem name="rock" x="6" y="0"/>
+ <stageitem name="rock" x="7" y="0"/>
+ <stageitem name="rock" x="8" y="0"/>
+ <stageitem name="rock" x="9" y="0"/>
+ <stageitem name="rock" x="10" y="0"/>
+ <stageitem name="rock" x="11" y="0"/>
+ <stageitem name="rock" x="12" y="0"/>
+ <stageitem name="rock" x="13" y="0"/>
+ <stageitem name="rock" x="14" y="0"/>
+ <stageitem name="rock" x="15" y="0"/>
+ <stageitem name="rock" x="0" y="2"/>
+ <stageitem name="rock" x="0" y="3"/>
+ <stageitem name="rock" x="0" y="4"/>
+ <stageitem name="rock" x="0" y="5"/>
+ <stageitem name="rock" x="0" y="6"/>
+ <stageitem name="rock" x="1" y="7"/>
+ <stageitem name="rock" x="1" y="8"/>
+ <stageitem name="rock" x="2" y="9"/>
+ <stageitem name="rock" x="1" y="10"/>
+ <stageitem name="rock" x="0" y="10"/>
+ <stageitem name="rock" x="0" y="11"/>
+ <stageitem name="rock" x="1" y="12"/>
+ <stageitem name="rock" x="2" y="13"/>
+ <stageitem name="rock" x="2" y="14"/>
+ <stageitem name="rock" x="3" y="14"/>
+ <stageitem name="rock" x="4" y="14"/>
+ <stageitem name="rock" x="5" y="14"/>
+ <stageitem name="rock" x="6" y="14"/>
+ <stageitem name="rock" x="7" y="14"/>
+ <stageitem name="rock" x="7" y="13"/>
+ <stageitem name="rock" x="7" y="12"/>
+ <stageitem name="rock" x="7" y="11"/>
+ <stageitem name="rock" x="7" y="10"/>
+ <stageitem name="rock" x="7" y="9"/>
+ <stageitem name="rock" x="7" y="8"/>
+ <stageitem name="rock" x="8" y="8"/>
+ <stageitem name="rock" x="8" y="9"/>
+ <stageitem name="rock" x="9" y="9"/>
+ <stageitem name="rock" x="10" y="9"/>
+ <stageitem name="rock" x="11" y="8"/>
+ <stageitem name="rock" x="11" y="7"/>
+ <stageitem name="rock" x="13" y="5"/>
+ <stageitem name="rock" x="14" y="4"/>
+ <stageitem name="rock" x="15" y="3"/>
+ <stageitem name="rock" x="15" y="2"/>
+ <stageitem name="rock" x="15" y="1"/>
+ <stageitem name="rock" x="11" y="1"/>
+ <stageitem name="rock" x="10" y="2"/>
+ <stageitem name="rock" x="10" y="1"/>
+ <stageitem name="rock" x="9" y="1"/>
+ <stageitem name="rock" x="4" y="6"/>
+ <stageitem name="rock" x="5" y="5"/>
+ <stageitem name="rock" x="5" y="4"/>
+ <stageitem name="rock" x="4" y="4"/>
+ <stageitem name="rock" x="4" y="5"/>
+ <stageitem name="rock" x="6" y="7"/>
+ <stageitem name="rock" x="4" y="7"/>
+ <stageitem name="rock" x="5" y="9"/>
+ <stageitem name="rock" x="6" y="10"/>
+ <stageitem name="rock" x="6" y="8"/>
+ <stageitem name="rock" x="6" y="9"/>
+ <stageitem name="rock" x="1" y="9"/>
+ <stageitem name="rock" x="1" y="1"/>
+ <stageitem name="rock" x="1" y="2"/>
+ <stageitem name="rock" x="5" y="8"/>
+ <stageitem name="rock" x="2" y="10"/>
+ <stageitem name="rock" x="1" y="11"/>
+ <stageitem name="rock" x="0" y="7"/>
+ <stageitem name="rock" x="11" y="9"/>
+ <stageitem name="rock" x="8" y="10"/>
+ <stageitem name="rock" x="6" y="13"/>
+ <stageitem name="rock2" x="14" y="5"/>
+ <stageitem name="rock" x="14" y="5"/>
+ <stageitem name="rock" x="15" y="4"/>
+ <stageitem name="rock" x="9" y="10"/>
+ <stageitem name="rock" x="8" y="11"/>
+ <stageitem name="rock" x="6" y="4"/>
+ <stageitem name="rock" x="2" y="1"/>
+ <stageitem name="rock" x="10" y="10"/>
+ <stageitem name="rock" x="12" y="8"/>
+ <stageitem name="rock" x="14" y="6"/>
+ <stageitem name="rock" x="15" y="5"/>
+ <stageitem name="rock" x="8" y="12"/>
+ <stageitem name="rock" x="8" y="13"/>
+ <stageitem name="rock" x="1" y="13"/>
+ <stageitem name="rock" x="0" y="12"/>
+ <stageitem name="rock" x="0" y="9"/>
+ <stageitem name="rock" x="0" y="8"/>
+ <stageitem name="rock" x="1" y="14"/>
+ <stageitem name="rock" x="0" y="13"/>
+ <stageitem name="rock" x="2" y="15"/>
+ <stageitem name="rock" x="3" y="15"/>
+ <stageitem name="rock" x="4" y="15"/>
+ <stageitem name="rock" x="5" y="15"/>
+ <stageitem name="rock" x="6" y="15"/>
+ <stageitem name="rock" x="4" y="3"/>
+ <stageitem name="rock" x="5" y="3"/>
+ <stageitem name="rock" x="3" y="4"/>
+ <stageitem name="rock" x="3" y="5"/>
+ <stageitem name="rock" x="11" y="10"/>
+ <stageitem name="rock" x="12" y="9"/>
+ <stageitem name="rock" x="9" y="11"/>
+ <stageitem name="rock" x="15" y="6"/>
+ <stageitem name="rock" x="14" y="7"/>
+ <stageitem name="rock" x="10" y="11"/>
+ <stageitem name="rock" x="9" y="12"/>
+ <stageitem name="rock" x="8" y="15"/>
+ <stageitem name="rock" x="9" y="15"/>
+ <stageitem name="rock" x="10" y="15"/>
+ <stageitem name="rock" x="11" y="15"/>
+ <stageitem name="rock" x="12" y="14"/>
+ <stageitem name="rock" x="13" y="14"/>
+ <stageitem name="rock" x="14" y="14"/>
+ <stageitem name="rock" x="14" y="13"/>
+ <stageitem name="rock" x="15" y="13"/>
+ <stageitem name="rock" x="15" y="12"/>
+ <stageitem name="rock" x="15" y="11"/>
+ <stageitem name="rock" x="15" y="10"/>
+ <stageitem name="rock" x="15" y="9"/>
+ <stageitem name="rock" x="15" y="8"/>
+ <stageitem name="rock" x="15" y="7"/>
+ <stageitem name="rock" x="11" y="14"/>
+ <stageitem name="rock" x="8" y="14"/>
+ <stageitem name="rock" x="9" y="14"/>
+ <stageitem name="myship" x="2" y="2"/>
+ <stageitem name="rock" x="14" y="1"/>
+</stageitem_list>
--- /dev/null
+try:\r
+ __import__('pkg_resources').declare_namespace(__name__)\r
+except InportError:\r
+ from pkgutil import extend_path\r
+ __path__ = extend_path(__path__, __name__)\r
--- /dev/null
+try:\r
+ __import__('pkg_resources').declare_namespace(__name__)\r
+except InportError:\r
+ from pkgutil import extend_path\r
+ __path__ = extend_path(__path__, __name__)\r
class Color(list):
+ """Color
+
+ Attribute:
+ r - read
+ g - green
+ b - blue
+ a - alfa
+ """
attrs = ['r', 'g', 'b', 'a']
__slots__ = attrs
def test():
+ """test for Color
+ """
c = Color(3, 4, 5, 255)
print c.g
print c.a
return Vector(a)\r
\r
\r
-def calcVertexs(vertexs, move, scale, matrix):\r
+def calcVertexsOrg(vertexs, move, scale, matrix):\r
calced = []\r
for v in vertexs:\r
vec = Vector(v)\r
calced.append(Vertex(vec[0], vec[1], vec[2]))\r
return calced\r
\r
+def calcMove(vec, move):\r
+ """move vector"""\r
+ if move:\r
+ vec -= Vector(move) # move\r
+ return vec\r
+\r
+def calcScale(vec, scale):\r
+ if scale:\r
+ vec *= scale # scale\r
+ return vec\r
+\r
+def calcRotate(vec, matrix):\r
+ if matrix:\r
+ vec = calcMatrix(matrix, vec) # rotate\r
+ return vec\r
+\r
+def calcVertexs(vertexs, move, scale, matrix, mode='msr'):\r
+ calced = []\r
+ for v in vertexs:\r
+ vec = Vector(v)\r
+ for c in mode:\r
+ if c == 'm':\r
+ vec = calcMove(vec, move)\r
+ elif c == 's':\r
+ vec = calcScale(vec, scale)\r
+ elif c == 'r':\r
+ vec = calcRotate(vec, matrix)\r
+ calced.append(Vertex(vec[0], vec[1], vec[2]))\r
+ return calced\r
+\r
\r
__all__ = ["Model", "load", "save", "new"]\r
\r
vertexs = p.vertexs\r
if move_self or scale_self or matrix_self:\r
vertexs = calcVertexs(vertexs, move_self, scale_self,\r
- matrix_self)\r
+ matrix_self, mode='rsm')\r
if move or scale or matrix:\r
vertexs = calcVertexs(vertexs, move, scale, matrix)\r
q = Polygon(vertexs, tuple(p.fill), tuple(p.outline), p.name)\r
--- /dev/null
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""rect class
+"""
+
+__all__ = ["Rect"]
+
+
+class Rect(object):
+ __slots__ = ['left', 'top', 'right', 'bottom']
+
+ def __init__(self, left, top, right, bottom):
+ if left <= right:
+ self.left = left
+ self.right = right
+ else:
+ self.left = right
+ self.right = left
+ if top <= bottom:
+ self.top = top
+ self.bottom = bottom
+ else:
+ self.top = bottom
+ self.bottom = top
+
+ def __str__(self):
+ return "<Rect: (%d, %d, %d, %d)>" \
+ % (self.left, self.top, self.right, self.bottom)
+
+ def width(self):
+ return self.right - self.left + 1
+
+ def height(self):
+ return self.bottom - self.top + 1
+
+ def size(self):
+ return self.width(), self.height()
+
+ def cx(self):
+ return self.left + self.width() // 2
+
+ def cy(self):
+ return self.top + self.height() // 2
+
+ def center(self):
+ return self.cx(), self.cy()
+
+ def calcArea(self, other):
+ return self.width() * self.height()
+
+ def isIntersect(self, other):
+ if self.left < other.right and other.left < self.right:
+ if self.top < other.bottom and other.top < self.bottom:
+ return 1
+ return 0
+
+ def isIn(self, x, y):
+ if self.left <= x and x <= self.right:
+ if self.top <= y and y <= self.bottom:
+ return 1
+ return 0
+
+ def isNull(self):
+ if self.left == 0 and self.top == 0 and self.right == 0 and \
+ self.bottom == 0:
+ return 1
+ return 0
+
+ def __and__(self, other):
+ if not self.isIntersect(other):
+ return Rect(0, 0, 0, 0)
+ left = max(self.left, other.left)
+ top = max(self.top, other.top)
+ right = min(self.right, other.right)
+ bottom = min(self.bottom, other.bottom)
+ return Rect(left, top, right, bottom)
+
+ def __or__(self, ohter):
+ left = min(self.left, other.left)
+ top = min(self.top, other.top)
+ right = max(self.right, other.right)
+ bottom = max(self.bottom, other.bottom)
+ return Rect(left, top, right, bottom)
+
+
+if __name__ == "__main__":
+ a = Rect(0, 0, 15, 15)
+ b = Rect(16, 16, 32, 32)
+ print a
+ print b
+ c = a | b
+ print c
+ d = a & b
+ print d
+ print a.isOverlap(b)
--- /dev/null
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except InportError:
+ from pkgutil import extend_path
+ __path__ = extend_path(__path__, __name__)
--- /dev/null
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except InportError:
+ from pkgutil import extend_path
+ __path__ = extend_path(__path__, __name__)
--- /dev/null
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# common
+COL_BACK = (0, 0, 0, 0)
+COL_GRID = (128, 128, 128, 255)
+COL_CURSOR = (255, 0, 0, 255)
+GRID_STEP = 32
+
+LIST_WIDTH = 30 # not pixels
+
+# piceinfo
+GRID_NUM = 6
+
+# mapedit
+MAP_WIDTH = 32
+MAP_HEIGHT = 32
+EDIT_WIDTH = 16
+EDIT_HEIGHT = 16
import ImageDraw
import ImageTk
-import settings
+import config
import common.model as model
from common.stageitem import Stageitem
__all__ = ["CtrMapedit"]
-COL_BACK = settings.COL_BACK
-COL_GRID = settings.COL_GRID
-COL_CURSOR = settings.COL_CURSOR
-GRID_STEP = settings.GRID_STEP
-MAP_WIDTH = settings.MAP_WIDTH
-MAP_HEIGHT = settings.MAP_HEIGHT
-EDIT_WIDTH = settings.EDIT_WIDTH
-EDIT_HEIGHT = settings.EDIT_HEIGHT
+COL_BACK = config.COL_BACK
+COL_GRID = config.COL_GRID
+COL_CURSOR = config.COL_CURSOR
+GRID_STEP = config.GRID_STEP
+MAP_WIDTH = config.MAP_WIDTH
+MAP_HEIGHT = config.MAP_HEIGHT
+EDIT_WIDTH = config.EDIT_WIDTH
+EDIT_HEIGHT = config.EDIT_HEIGHT
class Cursor(object):
import os
-import settings
-
import common.model as model
-from common.piece import Piece
from common.stageitem import Stageitem
import common.stagemap as stagemap
+from piece import Piece
from ctrmapedit import CtrMapedit
from piecelist import PieceList
from stagemaplist import StagemapList
SCR_H = 480
SCALE = 4
-
class Mapedit(Tk.Frame):
"""Widget for map edit.
"""
- def __init__(self, master=None):
+ def __init__(self, model_path, stage_path, master=None):
Tk.Frame.__init__(self, master)
- self.init('../../data/model/', '../../data/stage/')
+ self.init(model_path, stage_path)
self.pack()
def init(self, modeldir, stagedir):
def save(self):
"""save stage data
"""
- filename = tkFileDialog.asksaveasfilename(
- initialdir=os.path.dirname(self.stagedir))
+ filename = tkFileDialog.asksaveasfilename(initialdir=self.stagedir)
if filename != "":
try:
stagemap.save(filename, self.stagemap)
def load(self):
"""load stage data
"""
- filename = tkFileDialog.askopenfilename(
- initialdir=os.path.dirname(self.stagedir))
+ filename = tkFileDialog.askopenfilename(initialdir=self.stagedir)
if filename != "":
try:
self.stagemap = stagemap.load(filename)
import Image
import ImageDraw
-from model import Model
-import model as model
+from common.model import Model
+import common.model as model
GRID_STEP = 64
GRID_DRAW = 64
import ImageDraw
import ImageTk
-import settings
+import config
import common.model as model
-from common.piece import Piece
+from piece import Piece
__all__ = ["PieceInfo"]
-COL_BACK = settings.COL_BACK
-COL_GRID = settings.COL_GRID
-GRID_STEP = settings.GRID_STEP
-GRID_NUM = settings.GRID_NUM
+COL_BACK = config.COL_BACK
+COL_GRID = config.COL_GRID
+GRID_STEP = config.GRID_STEP
+GRID_NUM = config.GRID_NUM
class PieceInfo(Tk.Frame):
import ImageDraw
import ImageTk
-import settings
+import config
import common.model as model
-from common.piece import Piece
-import common.scrolledlistbox as SL
+import utils.scrolledlistbox as SL
+from piece import Piece
from pieceinfo import PieceInfo
__all__ = ["PieceList"]
-LIST_WIDTH = settings.LIST_WIDTH
+LIST_WIDTH = config.LIST_WIDTH
class PieceList(Tk.Frame):
import Tkinter as Tk
-import settings
+import config
-import common.model as model
-from common.piece import Piece
-import common.scrolledlistbox as SL
from common.stageitem import Stageitem
from common.stagemap import Stagemap
+import common.model as model
+import utils.scrolledlistbox as SL
+
+from piece import Piece
__all__ = ["StagemapList"]
-LIST_WIDTH = settings.LIST_WIDTH
+LIST_WIDTH = config.LIST_WIDTH
def to_text(stageitem):
--- /dev/null
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except InportError:
+ from pkgutil import extend_path
+ __path__ = extend_path(__path__, __name__)
import ImageDraw
import ImageTk
-import settings
-
from common.color import Color
from common.history import History
import common.model as model
mdc = self.md.calc(move, None, None, None, self.scale_self, None)
self._drawmodel(mdc)
- def __init__(self, master=None, fname='', width=480, height=480, scale=4):
+ def __init__(self, model_path, master=None, fname='',
+ width=480, height=480, scale=4):
Frame.__init__(self, master)
# basic setting
self.width = width
self.scale_self = scale
if fname:
- self.filename = "%s/%s" % (settings.DATAPATH, fname)
+ self.filename = "%s/%s" % (model_path, fname)
self.md = model.load(self.filename)
else:
- self.filename = "%s" % settings.DATAPATH
+ self.filename = "%s" % model_path
self.md = model.new()
self.marks = []
self.marks_selected = []
import os
-import settings
-
from ctrcolor import CtrColor
from ctrmodel import CtrModel
import common.pallet
SCR_H = 480
SCALE = 4
-RESOURCE = 'resource'
+SCRIPT_PATH = os.path.dirname(__file__)
+RESOURCE = os.path.join(SCRIPT_PATH, 'resource')
INIT_PALLET = 'pallet.xml'
class Modeledit(Frame):
- def __init__(self, master=None):
+ def __init__(self, model_path, master=None):
Frame.__init__(self, master)
- self.init()
+ self.init(model_path)
self.pack()
def settitle(self):
name = 'None'
self.master.title("%s - model editor" % name)
- def init(self):
+ def init(self, model_path):
lb_font = ('Helvetica', '12')
# main panel
fr_main = Frame(self)
#
# Model
#
- self.cm = CtrModel(fr_main,
+ self.cm = CtrModel(model_path,
+ fr_main,
width=SCR_W,
height=SCR_H,
scale=SCALE,
import sys
selfpath = os.path.dirname(sys.argv[0])
-homepath = os.path.join(selfpath, '..', '..')
+homepath = os.path.join(selfpath, '..', '..', '..')
PROJECTHOME = os.path.abspath(homepath)
-DATAPATH = os.path.join(PROJECTHOME, 'data', 'model')
-LIBPATH = os.path.join(PROJECTHOME, 'lib')
+DATAPATH = os.path.join(PROJECTHOME, 'data')
+LIBPATH = os.path.join(PROJECTHOME, 'arescue', 'lib')
sys.path.insert(1, LIBPATH)
+# data directory
+MODEL_PATH = os.path.join(DATAPATH, 'model')
+
if __name__ == '__main__':
print PROJECTHOME
print DATAPATH
print LIBPATH
print sys.path
+ import common.color
--- /dev/null
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+u""" run map editor
+"""
+import settings
+
+from utils.mapeditor.mapedit import Mapedit
+Mapedit(settings.MODEL_PATH, settings.STAGE_PATH).mainloop()
--- /dev/null
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+u""" run model editor
+"""
+import settings
+
+from utils.modeleditor.modeledit import Modeledit
+Modeledit(settings.MODEL_PATH).mainloop()
"""\r
\r
import os.path\r
-\r
import settings\r
\r
import common.model as model\r
draw_polygon(p)\r
\r
# make model\r
- fname = os.path.join(settings.DATAPATH, "model.xml")\r
+ fname = os.path.join(settings.MODEL_PATH, "model.xml")\r
md = model.load(fname)\r
\r
# model parameter\r
--- /dev/null
+# -*- coding: utf-8 -*-
+u"""settings
+"""
+
+import os.path
+import sys
+
+selfpath = os.path.dirname(__file__)
+homepath = os.path.abspath(selfpath)
+
+PROJECTHOME = homepath
+DATAPATH = os.path.join(PROJECTHOME, 'data')
+LIBPATH = os.path.join(PROJECTHOME, 'lib')
+
+sys.path.insert(1, LIBPATH)
+
+# data directory
+MODEL_PATH = os.path.join(DATAPATH, 'model')
+STAGE_PATH = os.path.join(DATAPATH, 'stagemap')
+++ /dev/null
-<?xml version="1.0" ?>
-<stageitem_list name="test_items">
- <stageitem name="model1101" x="0" y="0"/>
- <stageitem name="model1101" x="2" y="0"/>
- <stageitem name="myship" x="0" y="2"/>
-</stageitem_list>
+++ /dev/null
-#!/usr/bin/env python\r
-# -*- coding: utf-8 -*-\r
+++ /dev/null
-#!/usr/bin/env python\r
-# -*- coding: utf-8 -*-\r
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-import os
-import sys
-
-import os.path
-import sys
-
-selfpath = os.path.dirname(sys.argv[0])
-homepath = os.path.join(selfpath, '..', '..')
-
-PROJECTHOME = os.path.abspath(homepath)
-DATAPATH = os.path.join(PROJECTHOME, 'data')
-LIBPATH = os.path.join(PROJECTHOME, 'lib')
-sys.path.insert(1, LIBPATH)
-
-#
-# application settings
-#
-
-# common
-COL_BACK = (0, 0, 0, 0)
-COL_GRID = (128, 128, 128, 255)
-COL_CURSOR = (255, 0, 0, 255)
-GRID_STEP = 32
-
-LIST_WIDTH = 30 # not pixels
-
-# piceinfo
-GRID_NUM = 6
-
-# mapedit
-MAP_WIDTH = 32
-MAP_HEIGHT = 32
-EDIT_WIDTH = 16
-EDIT_HEIGHT = 16
-
-if __name__ == '__main__':
- print PROJECTHOME
- print DATAPATH
- print LIBPATH
- print sys.path