Skip to content

Commit

Permalink
adding subimage saving support
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredly committed Jun 24, 2010
1 parent aae4754 commit 4982729
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 165 deletions.
4 changes: 3 additions & 1 deletion apps/gcc_projects/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
from gcc_sprites.models import Sprite
from gcc_objects.models import Object
from gcc_maps.models import Map
from django.contrib.auth.models import AnonymousUser

service = Service()

@service.add
def load(request, project):
if isinstance(request.user, AnonymousUser):
return {'error':'not logged in', 'action':'/accounts/login/?next=/editor/#%s' % project}
obj = Project.objects.get(author=request.user, slug=project)
res = {'title': obj.title} # expose Project metadata through a different call -- get the form.
sprites = obj.asset_sprites.all()
#res['categories'] =
res['_models'] = {'project':obj}
res['_models']['assets'] = {
'sprites': obj.asset_sprites.all(),
Expand Down
7 changes: 7 additions & 0 deletions apps/gcc_sprites/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
def new(request, pid):
return rest.new(request, pid, 'Sprite', Sprite, speed=1, collision_type=1, collision_attrs="")

@service.add(name = '(?P<id>\d+)/save_subimages')
def save_subimages(request, id, subimages):
obj = Sprite.objects.get(pk=id)
obj.subimages = str(subimages)
obj.save()
return {}

urlpatterns = service.urls()

# vim: et sw=4 sts=4
115 changes: 0 additions & 115 deletions gameccorg/media/editor/index.css

This file was deleted.

35 changes: 10 additions & 25 deletions gameccorg/media/editor/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<html>
<head>
<title>PJs example w/ the ExtJS library</title>
<link rel="stylesheet" type="text/css"
href="/media/editor/ext/css/ext-all.css">
<link rel="stylesheet" type="text/css" href="/media/editor/index.css"/>
<link rel="stylesheet" type="text/css" href="/media/editor/ext/css/ext-all.css">
<link rel="stylesheet" type="text/css" href="/media/editor/main.css"/>
<script type="text/javascript" src="/media/editor/ext/ext-base.js"></script>
<script type="text/javascript" src="/media/editor/ext/ext-all.js"></script>
<script type="text/javascript" src="/media/editor/ext/MultiSelect.js"></script>
<script src="/media/editor/ext/jquery.min.js"></script>
<script src="/media/editor/ext/jquery-ui.min.js"></script>
<script src="/media/editor/ext/json2.js"></script>
<script src="/media/editor/pjslib.js"></script>
<script type="text/javascript" src="/media/editor/layout2.js"> </script>
Expand Down Expand Up @@ -37,7 +37,7 @@
<div id='general-nav'>
<ul>
<li class='project-info selected'>Project Info</li>
<li class='media-manager'>Media Manager</li>
<!--li class='media-manager'>Media Manager</li-->
</ul>
</div>

Expand Down Expand Up @@ -66,7 +66,6 @@
</div>
</div>
<div id="sprite-subimages">
<div class="item add"></div>
</div>

<div id="object-info" class='asset-info'>
Expand Down Expand Up @@ -98,32 +97,18 @@
<div id="map-main">
</div>



<!-- @end -->

</div>

<!-- @group dialogs -->

<div id="add-subimage">

</div>
<!-- @eng -->


<!-- use class="x-hide-display" to prevent a brief flicker of the content -->
<div id="west" class="x-hide-display">
<p>Hi. I'm the west panel.</p>
</div>
<div id="center2" class="x-hide-display">
<a id="hideit" href="#">Toggle the west region</a>
<p>My closable attribute is set to false so you can't close me. The other center panels can be closed.</p>
<p>The center panel automatically grows to fit the remaining space in the container that isn't taken up by the border regions.</p>
<hr>
</div>
<div id="center1" class="x-hide-display">
<p><b>Done reading me? Close me by clicking the X in the top right corner.</b></p>
</div>
<div id="props-panel" class="x-hide-display" style="width:200px;height:200px;overflow:hidden;">
</div>
<div id="south" class="x-hide-display">
<p>south - generally for informational stuff, also could be for status bar</p>
</div>

<div id="loading-icon"></div>

Expand Down
15 changes: 10 additions & 5 deletions gameccorg/media/editor/layout2.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var layouts = {
}
},*/ {
region: 'west',
id: 'west-panel', // see Ext.getCmp() below
id: 'west-panel',
title: 'Assets',
split: true,
width: 200,
Expand Down Expand Up @@ -124,7 +124,7 @@ var layouts = {
id: 'main-content',
border: false,
activeItem: 0,
items: [{ // project info
items: [{
id: 'project-info',
xtype: 'form',
margins: '10px',
Expand Down Expand Up @@ -185,7 +185,7 @@ var layouts = {
{
region: 'west',
split: false,
width: 200,
width: 160,
contentEl: 'sprite-info'
}, {
region: 'center',
Expand All @@ -194,6 +194,11 @@ var layouts = {
{ text: '&nbsp;&nbsp;-&nbsp;&nbsp;' }
],
contentEl: 'sprite-subimages'
}, {
region: 'east',
split: false,
width: 300,
contentEl: 'media-images'
}
]
}, {
Expand All @@ -205,7 +210,7 @@ var layouts = {
{
region: 'west',
split: false,
width: 200,
width: 160,
margin: 5,
contentEl: 'object-info'
}, {
Expand Down Expand Up @@ -247,7 +252,7 @@ var layouts = {
items: [
{
region: 'west',
width: 200,
width: 160,
contentEl: 'map-info'
}, {
region: 'center',
Expand Down
3 changes: 1 addition & 2 deletions gameccorg/media/editor/make.pbj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ build = Builder('GameCC Editor')

@build.file('main.js', depends=['*.py', '@lib'], always=True)
def main(name):
text = pjs.compile('py/main.py', 'js')
open('main.js', 'w').write(text)
pjs.convert('py/main.py', 'main.js', 'js', import_css=True, css_dir='css')

build.clean('main.js', 'pjslib.js')

Expand Down
9 changes: 9 additions & 0 deletions gameccorg/media/editor/py/asset_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def __init__(self, parent):
window.Ext.getCmp('new-' + self.asset_type + '-button').on('click', self.new_)
self.node = js.jq('#' + self.asset_type + '-editor')
self.current = None
self.pk = None
self.dirty = []

def new_(self, button, event):
ajax.send(self.asset_type + '/new', {'pid':self.parent.pid}, self.onNew)
Expand All @@ -21,8 +23,15 @@ def onNew(self, data):
def load(self, aid):
window.Ext.getCmp('main-content').layout.setActiveItem(self.asset_type + '-editor')
self.current = self.parent.assets[self.asset_type + 's'][aid]
self.pk = aid
js.jq('.title', self.node).val(self.current['fields']['title'])

def set_attr(self, attr, value):
self.current['fields'][attr] = value
if self.pk not in self.dirty:
self.dirty.append(self.pk)
print 'dirty',self.asset_type,self.dirty




Expand Down
22 changes: 19 additions & 3 deletions gameccorg/media/editor/py/editor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python

## get the ajax handler

import widgets
from nav import NavMan
from mediaman import MediaManager
Expand All @@ -11,11 +9,16 @@
from map_editor import MapEditor

from ajax import ajax
import json

from CSS import index

jq = window.jQuery

class Editor:
def __init__(self):
bg = new(window.Image())
bg.src = js('/media/editor/images/trans-bg-big.png')
window.layouts['main']['items'][2]['items'][0]['buttons'][0]['handler'] = self.onProjectInfoSave
new(window.Ext.Viewport(window.layouts['main']))
self.pid = None
Expand Down Expand Up @@ -70,6 +73,13 @@ def __init__(self, parent, project):
self.msg = widgets.NumProgressBar('Loading project', 'Retrieving project data from server', 3)

def load_project(self, data):
if data.has_key('error'):
window.alert(data['error'])
if data.has_key('action'):
if data['action'] == 'reload':
window.location.reload()
else:
window.location = js(data['action'])
models = self.organize_models(data['_models'])
self.parent.load(loader=self.msg, **models)
self.msg.total += 3
Expand All @@ -81,7 +91,11 @@ def load_media(self, data):
self.msg.increment()
self.msg.setMessage('Loading Items')
toload = data['_models']
self.parent.media.load(data['media_url'], toload, self.msg)
self.parent.media.load(data['media_url'], toload, self.msg, self.finished_media)

def finished_media(self):
pass
# print 'media done'

def organize_models(self, models):
dct = {'project':None, 'assets':{'sprites':{},'objects':{},'maps':{}}}
Expand All @@ -92,6 +106,8 @@ def organize_models(self, models):
else:
name = '.'.join(model['model'].split('.')[1:]) + 's'
dct['assets'][name][model['pk']] = model
if name == 'sprites':
model['fields']['subimages'] = list(json.loads(model['fields']['subimages']))
return dct

def load():
Expand Down
Loading

0 comments on commit 4982729

Please sign in to comment.