]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
xml improvements
authorClyne Sullivan <tullivan99@gmail.com>
Fri, 8 Jan 2016 13:47:04 +0000 (08:47 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Fri, 8 Jan 2016 13:47:04 +0000 (08:47 -0500)
Changelog
include/entities.h
src/gameplay.cpp
src/ui.cpp
xml/playerSpawnHill1.xml

index d48e16d001312fd7a18bc7173d548fd2d9ef411c..e8a016ae659b1026fcebbb0023c54df3c2e50729 100644 (file)
--- a/Changelog
+++ b/Changelog
        - worked on wrapping text for dialog boxes
        - did more work on GLSL shaders
 
-1/3/2015:
+1/3/2016:
 =========
 
        - finished wrapping text for dialog boxes
        - began working on world saving/loading again
        - got some mad GLSL shaders running
 
-1/4/2015:
+1/4/2016:
 =========
 
        - fixed basic world save/load, working on entity saving
        - GLSL shaders worked?
 
-1/5/2015:
+1/5/2016:
 =========
 
        - can save NPCs and Structures
        - more shadering
        
-1/6/2015:
+1/6/2016:
 =========
 
        - flashlight!
        - XML-scripted worlds!!!
        - !!!!!!!!!!!!!!!!!!!!!!!!
+       
+1/7/2016:
+=========
+
+       - xml'd npc and mob spawning
+       - xml'd npc dialogs
+       - drafted page xml
+       
index 0fcc662c9f53e65c5db84cfb43e76d03ea654447..f26863e9a9ed11ffc7840957fea16a3c4aea756a 100644 (file)
@@ -223,7 +223,6 @@ public:
        void (*hey)(Mob *callee);
        
        Mob(int);
-       Mob(int,unsigned int);
        ~Mob();
        
        void wander(int);
index 52ce7292b5ffd3df12d0bf88d53d0e014b0b817d..6637d239ce265ccda66504bbcff4ea8f324a8671 100644 (file)
@@ -27,36 +27,123 @@ extern Player      *player;
  *     initEverything() start
  */
 
+typedef struct {
+       World *ptr;
+       char *file;
+} WorldXML;
+
+typedef struct {
+       NPC *npc;
+       unsigned int index;
+} NPCDialog;
+
+std::vector<NPCDialog> npcd;
+std::vector<WorldXML>  earthxml;
 std::vector<World *>   earth;
 
+int commonAIFunc(NPC *speaker){
+       XMLDocument xml;
+       XMLElement *exml;
+       unsigned int idx;
+       
+       for(auto &n : npcd){
+               if(n.npc == speaker){
+                       idx = n.index;
+                       break;
+               }
+       }
+       
+       for(auto &e : earthxml){
+               if(e.ptr == currentWorld){
+                       xml.LoadFile(e.file);
+                       exml = xml.FirstChildElement("Dialog")->FirstChildElement();
+                       
+                       do{
+                               if(!strcmp(exml->Name(),"text")){
+                                       if(!strcmp(exml->Attribute("name"),speaker->name) && exml->UnsignedAttribute("id") == idx){
+                                               ui::dialogBox(speaker->name,"",false,exml->GetText());
+                                               ui::waitForDialog();
+                                               if(exml->QueryUnsignedAttribute("nextid",&idx) == XML_NO_ERROR){
+                                                       for(auto &n : npcd){
+                                                               if(n.npc == speaker){
+                                                                       n.index = idx;
+                                                                       break;
+                                                               }
+                                                       }
+                                                       return 1;
+                                               }
+                                               return 0;
+                                       }
+                               }
+                               exml = exml->NextSiblingElement();
+                       }while(exml);
+               }
+       }
+       return 0;
+}
+
 void destroyEverything(void);
 void initEverything(void){
-       const char *gentype;
+       const char *name;
        std::vector<std::string> xmlFiles;
-       char *file;
+       static char *file;
+       bool dialog;
        XMLDocument xml;
+       XMLElement *wxml;
+       
        if(getdir("./xml/",xmlFiles)){
                std::cout<<"Error reading XML files!!!1"<<std::endl;
                abort();
        }
+       
        for(auto x : xmlFiles){
                if(strncmp(x.c_str(),".",1) && strncmp(x.c_str(),"..",2)){
                        file = new char[4 + x.size()];
                        strncpy(file,"xml/",4);
                        strcpy(file+4,x.c_str());
                        xml.LoadFile(file);
-                       delete[] file;
+
+                       wxml = xml.FirstChildElement("World")->FirstChildElement();
 
                        earth.push_back(new World());
-                       earth.back()->setBackground((WORLD_BG_TYPE)atoi(xml.FirstChildElement("World")->FirstChildElement("Background")->GetText()));
-                       earth.back()->setBGM(xml.FirstChildElement("World")->FirstChildElement("BGM")->GetText());
-                       gentype = xml.FirstChildElement("World")->FirstChildElement("GenerationType")->GetText();
-                       if(!strcmp(gentype,"Random")){
-                               std::cout<<"rand\n";
-                               earth.back()->generate(atoi(xml.FirstChildElement("World")->FirstChildElement("GenerationWidth")->GetText()));
-                       }else{
-                               abort();
-                       }
+                       
+                       do{
+                               name = wxml->Name();
+                               
+                               if(!strcmp(name,"style")){
+                                       earth.back()->setBackground((WORLD_BG_TYPE)wxml->UnsignedAttribute("background"));
+                                       earth.back()->setBGM(wxml->Attribute("bgm"));
+                               }else if(!strcmp(name,"generation")){
+                                       if(!strcmp(wxml->Attribute("type"),"Random")){
+                                               earth.back()->generate(wxml->UnsignedAttribute("width"));
+                                       }
+                               }else if(!strcmp(name,"mob")){
+                                       earth.back()->addMob(wxml->UnsignedAttribute("type"),wxml->FloatAttribute("x"),wxml->FloatAttribute("y"));
+                               }else if(!strcmp(name,"npc")){
+                                       earth.back()->addNPC(wxml->FloatAttribute("x"),wxml->FloatAttribute("y"));
+                                       if(wxml->Attribute("name")){
+                                               delete[] earth.back()->npc.back()->name;
+                                               earth.back()->npc.back()->name = new char[strlen(wxml->Attribute("name"))+1];
+                                               strcpy(earth.back()->npc.back()->name,wxml->Attribute("name"));
+                                       }
+                                       dialog = false;
+                                       if(wxml->QueryBoolAttribute("hasDialog",&dialog) == XML_NO_ERROR && dialog){
+                                               for(auto &ex : earthxml){
+                                                       if(ex.ptr == earth.back())
+                                                               goto SKIP;
+                                               }
+                                               earthxml.push_back((WorldXML){earth.back(),new char[64]});
+                                               strcpy(earthxml.back().file,file);
+SKIP:
+                                               earth.back()->npc.back()->addAIFunc(commonAIFunc,false);
+                                               npcd.push_back((NPCDialog){earth.back()->npc.back(),0});
+                                       }
+                               }
+                               
+                               wxml = wxml->NextSiblingElement();
+                       }while(wxml);
+                       
+                       delete[] file;
                }
        }
        
index cf5e31ee1f9cbf5c45be57f23d7ea6cdfb64d158..ead9d8cc48cae1e1d246d1e437307b26bbe91cc8 100644 (file)
@@ -274,10 +274,11 @@ namespace ui {
                                if(s[i] == ' ')
                                        i++;
                        }
-                       if(s[i] == '\n'){
+                       if(s[i] == '\n' || s[i] == '\r' || s[i] == '\t'){
+                       /*if(s[i] == '\n'){
                                yo-=fontSize*1.05;
                                xo=x;
-                       }else if(s[i]==' '){    //      Handle spaces
+                       */}else if(s[i]==' '){  //      Handle spaces
                                xo+=fontSize/2;
                        }else if(s[i]=='\b'){   //      Handle backspaces?
                                xo-=add.x;
index 3544a7e789404bebc669a6c1077998c391fb37a8..c924d7e6af74a874324e84c84e71cc2bbaf7c6b5 100644 (file)
@@ -1,7 +1,22 @@
 <?xml version="1.0"?>
 <World>
-       <Background>0</Background>
-       <BGM>assets/music/embark.wav</BGM>
-       <GenerationType>Random</GenerationType>
-       <GenerationWidth>500</GenerationsWidth>
+       <style background="0" bgm="assets/music/embark.wav" />
+       <generation type="Random" width="500" />
+       
+       <!--<mob type="1" x="250" y="100" />-->
+       
+       <npc name="Ralph" x="0" y="100" hasDialog="true"/>
+
 </World>
+
+<Dialog>
+       
+       <text name="Ralph" id="0" nextid="1">
+               Hello there!
+       </text>
+       
+       <text name="Ralph" id="1">
+               Lol
+       </text>
+       
+</Dialog>