Permalink
Browse files

Levels now have a published status, and appear on front page only if …

…published is true or if you're the creator.
  • Loading branch information...
jonoxia committed Jan 12, 2012
1 parent c524641 commit 74650c14d6b4be94d8ef8263dcd84a6a83616503
View
@@ -25,6 +25,7 @@ class Level(SQLObject):
musicUrl = StringCol(default = "")
physicsConsts = StringCol(default = "")
soundUrls = StringCol(default = "")
+ published = BoolCol(default = False)
class LevelObject( SQLObject ):
level = ForeignKey("Level")
View
@@ -21,12 +21,12 @@
<label for="level-music-url">Music URL:</label><input type="text" id="level-music-url"/><br>
<div id="physics-props">
<label for="gravity">Gravity:</label><input type="text" id="gravity"/><br>
- <label for="friction">Ground Friction:</label><input type="text" id="groundFriction"/><br>
- <label for="friction">Air Friction:</label><input type="text" id="airFriction"/><br>
- <label for="acceleration">Ground Acceleration:</label><input type="text" id="groundAcceleration"/><br>
- <label for="acceleration">Air Acceleration:</label><input type="text" id="airAcceleration"/><br>
- <label for="acceleration">Ground Deceleration:</label><input type="text" id="groundDeceleration"/><br>
- <label for="acceleration">Air Deceleration:</label><input type="text" id="airDeceleration"/><br>
+ <label for="groundFriction">Ground Friction:</label><input type="text" id="groundFriction"/><br>
+ <label for="airFriction">Air Friction:</label><input type="text" id="airFriction"/><br>
+ <label for="groundAcceleration">Ground Acceleration:</label><input type="text" id="groundAcceleration"/><br>
+ <label for="airAcceleration">Air Acceleration:</label><input type="text" id="airAcceleration"/><br>
+ <label for="groundDeceleration">Ground Deceleration:</label><input type="text" id="groundDeceleration"/><br>
+ <label for="airDeceleration">Air Deceleration:</label><input type="text" id="airDeceleration"/><br>
<label for="jump-power">Jump Power:</label><input type="text" id="jumpPower"/><br>
<label for="top-speed">Top Speed:</label><input type="text" id="topSpeed"/><br>
</div>
@@ -41,6 +41,7 @@
<label for="goal-tool">Goal Location Tool</label><br>
<hr/>
<div id="more-tools"></div>
+ <input type="checkbox" id="publish"/><label for="publish">Make this level visible to others</label>
<button onclick="saveChanges();">Save Changes</button><br>
</div>
View
@@ -9,6 +9,7 @@
from database_tables import Level, LevelObject, Score
from webserver_utils import render_template_file, verify_id
+from sqlobject import OR
def formatTime(ms):
s = math.floor(ms / 1000)
@@ -22,16 +23,18 @@ def printList(player):
print "Content-type: text/html"
print
- matches = Level.select(orderBy = "-modified")
- work_list = ""
+ # Show levels that are published and/or created by the current player.
+ matches = Level.select(OR(Level.q.published == True,
+ Level.q.creator == player), orderBy = "-modified")
+ published_list = ""
+ your_list = ""
for level in matches:
title = level.name
date = level.modified
edit_link = ""
if level.creator != None:
if level.creator == player:
creator = "You"
- edit_link = "<a href=\"designer.html?level=%s\">Edit</a>" % title
else:
creator = level.creator.name
else:
@@ -50,15 +53,27 @@ def printList(player):
if (scores.count() > 0):
your_time = "%s with %d trinkets" % (formatTime(scores[0].completionTime),
scores[0].trinkets)
- work_list += render_template_file( "list-level-row.html",
+ if level.creator == player:
+ if level.published:
+ published = "Yes"
+ else:
+ published = "No"
+ your_list += render_template_file( "list-my-level-row.html",
+ {"moddate": date,
+ "title": title,
+ "published": published,
+ "best": best,
+ "yourtime": your_time} )
+ else:
+ published_list += render_template_file( "list-level-row.html",
{"moddate": date,
"title": title,
"creator": creator,
- "editlink": edit_link,
"best": best,
"yourtime": your_time} )
- print render_template_file( "list-levels.html", {"work_list": work_list,
+ print render_template_file( "list-levels.html", {"published_list": published_list,
+ "your_list": your_list,
"player": player.name,
"avatarURL": player.avatarURL})
View
@@ -30,6 +30,7 @@
data["tilesetUrl"] = levels[0].tilesetUrl
data["musicUrl"] = levels[0].musicUrl
data["physicsConsts"] = levels[0].physicsConsts
+ data["published"] = levels[0].published
print "Content-type: text/html"
print
View
@@ -41,6 +41,7 @@
level.goalUrl = data["goalUrl"]
level.tilesetUrl = data["tilesetUrl"]
level.physicsConsts = simplejson.dumps(data["physicsConsts"])
+ level.published = (data["published"] == "true")
for obj in data["worldData"]:
l = LevelObject(level = level, type = obj["type"],
@@ -5,9 +5,6 @@
<td>
<a href="play.py?level=${title}">Play</a>
</td>
- <td>
- ${editlink}
- </td>
<td>
${moddate}
</td>
View
@@ -7,9 +7,16 @@
<body>
<h1>RunJumpBuild - All Levels</h1>
<h2>Welcome, ${player}</h2>
+ <h3>Published Levels</h3>
<table>
- <tr><th>Title</th><th></th><th></th><th>Last Modified</th><th>Creator</th><th>Your Time</th><th>Best Time</th></tr>
- ${work_list}
+ <tr><th>Title</th><th></th><th>Last Modified</th><th>Creator</th><th>Your Time</th><th>Best Time</th></tr>
+ ${published_list}
+ </table>
+ <hr/>
+ <h3>Your Levels</h3>
+ <table>
+ <tr><th>Title</th><th></th><th></th><th>Last Modified</th><th>Published?</th><th>Your Time</th><th>Best Time</th></tr>
+ ${your_list}
</table>
<hr/>
<form action="newlevel.py" method="post">
@@ -0,0 +1,23 @@
+<tr>
+ <td>
+ ${title}
+ </td>
+ <td>
+ <a href="play.py?level=${title}">Play</a>
+ </td>
+ <td>
+ <a href="designer.html?level=${title}">Edit</a>
+ </td>
+ <td>
+ ${moddate}
+ </td>
+ <td>
+ ${published}
+ </td>
+ <td>
+ ${yourtime}
+ </td>
+ <td>
+ ${best}
+ </td>
+</tr>
View
@@ -289,6 +289,7 @@ function saveChanges() {
allData.physicsConsts[prop] = isNaN(fieldVal) ?
PhysicsConstants[prop] : fieldVal;
}
+ allData.published = $("#publish").attr("checked") ? "true":"false";
$.ajax({type: "POST",
url: URL,
@@ -393,6 +394,10 @@ $(document).ready(function() {
$("#" + prop).val( PhysicsConstants[prop] );
}
+ if (TheWorld.published) {
+ $("#publish").attr("checked", "checked");
+ }
+
loader.loadThemAll(redraw, function(progress) {
progressBar.draw(0.5 + 0.5 * progress);
});
View
@@ -443,6 +443,7 @@ var TheWorld = {
PhysicsConstants = parsedConsts;
}
}
+ self.published = parsedData.published;
//$("#debug").html("Loaded.");
callback(loader);
},

0 comments on commit 74650c1

Please sign in to comment.