Permalink
Browse files

Created new database entity, UserCodeNugget, and page for creating/up…

…dating them. This is prereq for the Monster API etc.
  • Loading branch information...
1 parent dc5c159 commit ad80d138a45cfbe98afc49a889c7fd34ab8fc374 @jonoxia committed Jan 17, 2012
Showing with 101 additions and 6 deletions.
  1. +15 −4 database_tables.py
  2. +49 −0 nugget-editor.py
  3. +16 −2 strings.json
  4. +21 −0 templates/nugget-editor.html
View
19 database_tables.py
@@ -46,8 +46,19 @@ class sqlmeta:
trinkets = IntCol(default = 0)
achievedOn = DateTimeCol()
+class UserCodeNugget( SQLObject ):
+ name = StringCol()
+ creator = ForeignKey("Player")
+ modified = DateTimeCol()
+ code = StringCol()
+ type = StringCol() # Monster, Powerup, or Obstacle
+ #?? Monster, Powerup, or Obstacle ? or can i have more than one in the same module?
+ # How are we going to refer to these in order to load them? Have to be able to tell what's in there
+ # before loading the code nuggets, I think
+
if __name__ == "__main__":
- Player.createTable()
- Level.createTable()
- LevelObject.createTable()
- Score.createTable()
+ #Player.createTable()
+ #Level.createTable()
+ #LevelObject.createTable()
+ #Score.createTable()
+ UserCodeNugget.createTable()
View
49 nugget-editor.py
@@ -0,0 +1,49 @@
+#!/usr/bin/python
+from database_tables import UserCodeNugget
+from webserver_utils import *
+
+import cgi
+import cgitb
+import datetime
+
+cgitb.enable()
+q = cgi.FieldStorage()
+nuggetId = q.getfirst("id", "")
+
+nugget = None
+if nuggetId != "":
+ nugget = UserCodeNugget.get(int(nuggetId))
+
+code = q.getfirst("code-input", "")
+name = q.getfirst("nugget-name", "")
+type = q.getfirst("nugget-type", "")
+
+if code != "":
+ player = verify_id()
+ if nugget == None:
+ nugget = UserCodeNugget(name = name,
+ type = type,
+ code = code,
+ modified = datetime.datetime.now(),
+ creator = player)
+ else:
+ if player == nugget.creator:
+ nugget.code = code
+ nugget.name = name
+ nugget.type = type
+
+if nugget != None:
+ values = {"nugget_id": nugget.id,
+ "nugget_name": nugget.name,
+ "nugget_type": nugget.type,
+ "nugget_code": nugget.code}
+else:
+ values = {"nugget_id": "",
+ "nugget_name": "",
+ "nugget_type": "",
+ "nugget_code": ""}
+
+
+print "Content-type: text/html"
+print
+print render_template_file("nugget-editor.html", values)
View
18 strings.json
@@ -32,6 +32,8 @@
"_lose_falling": "GRAVITY IS A HARSH MISTRESS",
"_level_designer": "Level Designer",
"_play_this_level": "Play This Level",
+ "_edit_this_level": "Edit This Level",
+ "_created_by": "Created by %s.",
"_background_img_url": "Background Img URL",
"_tileset_url": "Tileset URL",
"_goal_img_url": "Goal Img URL",
@@ -60,7 +62,12 @@
"_published_yes": "Yes",
"_published_no": "No",
"_other_player_score": "%(time)s by %(player)s with %(trinkets)d trinkets",
- "_your_score": "%(time)s with %(trinkets)d trinkets"
+ "_your_score": "%(time)s with %(trinkets)d trinkets",
+ "_code_editor": "Code Editor",
+ "_nugget_name": "namae",
+ "_nugget_type": "donna",
+ "_test_code": "tesuto",
+ "_save_code": "bozon"
},
"jp": {
"_runjumpbuild": "ランジャンプブイルド",
@@ -95,6 +102,8 @@
"_lose_falling": "落として死んだ!",
"_level_designer": "レベルの設計",
"_play_this_level": "このレベルをしてみる",
+ "_edit_this_level": "Edit This Level",
+ "_created_by": "Created by %s.",
"_background_img_url": "風景の画像のURL",
"_tileset_url": "タイルセットのURL",
"_goal_img_url": "目的の画像のURL",
@@ -123,7 +132,12 @@
"_published_yes": "公開した",
"_published_no": "公開していない",
"_other_player_score": "%(player)sが宝を%(trinkets)d もって、%(time)s をかかって完成した",
- "_your_score": "宝を%(trinkets)d もって、%(time)s をかかって完成した"
+ "_your_score": "宝を%(trinkets)d もって、%(time)s をかかって完成した",
+ "_code_editor": "Codo Editaa",
+ "_nugget_name": "namae",
+ "_nugget_type": "donna",
+ "_test_code": "tesuto",
+ "_save_code": "bozon"
}
}
View
21 templates/nugget-editor.html
@@ -0,0 +1,21 @@
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <title>${_runjumpbuild} &mdash; ${_code_editor}</title>
+ <script src="jquery.js"></script>
+ <script src="nugget-loader.js"></script>
+</head>
+<body>
+ <form action="nugget-editor.py" method="POST">
+ <input type="hidden" name="id" value="${nugget_id}"/>
+ ${_nugget_name}: <input type="text" name="nugget-name"
+ value="${nugget_name}"/><br/>
+ ${_nugget_type}: <input type="text" name="nugget-type"
+ value="${nugget_type}"/><br/>
+ <textarea rows="30" cols="80" name="code-input"/>${nugget_code}</textarea>
+ <button id="test" onclick="testCode()">${_test_code}</button><br/>
+ <input type="submit" value="${_save_code}"/><br/>
+ </form>
+ <span id="debug"></span>
+</body>
+</html>

0 comments on commit ad80d13

Please sign in to comment.