Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added the brief2html utility

  • Loading branch information...
commit a5b67dfb8368bb7149f0f7429862165bd051060e 1 parent fe8a337
@zhuowei authored
View
2  README.markdown
@@ -1,2 +1,2 @@
-Briefs-JS is a library to parse BriefScripts, the format used by the [Briefs](https://github.com/capttaco/Briefs/) project.
+Briefs-JS is a library to parse BriefScripts, the file format used by the [Briefs](https://github.com/capttaco/Briefs/) project.
View
8 brief2html.css
@@ -0,0 +1,8 @@
+.brief-scene {
+ position:absolute;
+ left:0;
+ top:0;
+ width:100%;
+ height:100%;
+ background-repeat: no-repeat;
+}
View
12 brief2html.htm
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="briefs.js"></script>
+
+<script src="brief2html.js"></script>
+</head>
+<body>
+<textarea id="main-textarea" cols="80" rows="25"></textarea>
+<button id="startbutton">Go!</button>
+</body>
+</html>
View
67 brief2html.js
@@ -0,0 +1,67 @@
+var textArea;
+var startButton;
+var briefDom;
+var BRIEF_PREFIX = "brief-"
+function init(){
+ textArea=document.getElementById("main-textarea");
+ startButton=document.getElementById("startbutton");
+ startButton.onclick=startParse;
+}
+function startParse(){
+ var briefXML = brief2html(textArea.value);
+ alert(briefXML);
+}
+function brief2html(briefScriptText){
+ var parser = new BriefParser(briefScriptText);
+ var world = parser.parse();
+ alert(world);
+ var doc = document.implementation.createDocument ('http://www.w3.org/1999/xhtml', 'html', null);
+ var head = document.createElementNS('http://www.w3.org/1999/xhtml', 'head');
+ doc.documentElement.appendChild(head);
+ /* add stylesheet and javascript */
+ var styleElem = document.createElementNS('http://www.w3.org/1999/xhtml', 'link');
+ styleElem.setAttribute("type", "text/css");
+ styleElem.setAttribute("rel", "stylesheet");
+ styleElem.setAttribute("href", "brief2html.css");
+ head.appendChild(styleElem);
+ var scriptElem = document.createElementNS('http://www.w3.org/1999/xhtml', 'script');
+ scriptElem.setAttribute("type", "text/javascript");
+ scriptElem.setAttribute("src", "brief2html.js");
+ head.appendChild(scriptElem);
+ /* end stylesheet and js*/
+ var body = document.createElementNS('http://www.w3.org/1999/xhtml', 'body');
+ doc.documentElement.appendChild(body);
+ for(var sceneNum=0;sceneNum<world.scenes.length;sceneNum++){
+ var scene=world.scenes[sceneNum];
+ var sceneElem = doc.createElementNS('http://www.w3.org/1999/xhtml', "div");
+ sceneElem.setAttribute("id", BRIEF_PREFIX + "scene-"+scene.name);
+ sceneElem.setAttribute("class", BRIEF_PREFIX + "scene");
+ var scenestyle="";
+ if(scene.name!=world.start){
+ scenestyle+="display:none;";
+ }
+ scenestyle+="background-image:url('"+scene.image+"');";
+ sceneElem.setAttribute("style", scenestyle);
+ //TODO: Actors
+ for(var actorNum=0;actorNum<scene.actors.length;actorNum++){
+ var actor = scene.actors[actorNum];
+ var actorElem = doc.createElementNS('http://www.w3.org/1999/xhtml', "div");
+ actorElem.setAttribute("id", BRIEF_PREFIX + "actor-"+actor.name);
+ actorElem.setAttribute("class", BRIEF_PREFIX + "actor");
+ var actorstyle="left:"+actor.x+"px;top:"+actor.y+"px;width:"+actor.width+"px;" +
+ "height:"+actor.height+"px;";
+ if(actor.image){
+ actorstyle+="background-image:url('"+actor.image+"');";
+ }
+ if(!actor.visible){
+ actorstyle+="display:none;";
+ }
+ actorElem.setAttribute("style", actorstyle);
+ sceneElem.appendChild(actorElem);
+ }
+ body.appendChild(sceneElem);
+ }
+ var serializer =new XMLSerializer();
+ return serializer.serializeToString(doc);
+}
+window.onload=init;
View
7 briefs.js
@@ -2,7 +2,13 @@ function Actor(name, world, scene){
this.name=name;
this.world=world;
this.scene=scene;
+ this.x=0;
+ this.y=0;
+ this.width=0;
+ this.height=0;
+ this.visible=true;
}
+Actor.prototype.visible=true;
function World(){
this.scenes=[];
}
@@ -213,5 +219,6 @@ BriefParser.prototype.parse=function(){
}
this.world=world;
+ return world;
}
Please sign in to comment.
Something went wrong with that request. Please try again.