Changeset 172


Ignore:
Timestamp:
03/13/14 17:50:13 (10 years ago)
Author:
mmichalski
Message:

Get creature from diffrent sources

File:
1 edited

Legend:

Unmodified
Added
Removed
  • js/viewer-f0/js/main.js

    r149 r172  
    1 var geneWindow =
     1var Viewer =
    22{
     3
     4    Mode: {
     5        LINK: 0,
     6        EMBEDDED: 1,
     7        TEXTAREA: 2,
     8        CODE : 3
     9    },
    310    context: undefined,
    4     urlToXML: "f0def.xml",
    5     debugCreatureName: "test",
     11    urlToXML: "f0def.xml",//"http://www.framsticks.com/files/apps/config/f0def.xml",
    612    xml: undefined,
    713    model: new Model(),
     
    1420    neurons: [],
    1521    neuroConns: [],
    16     neuroClasses: [],
     22    neuroClasses: {},
    1723    modelOne: undefined,
    1824    _graphicsEngine: new GraphicsEngine(),
     
    2127        var local = this;
    2228        $.ajax({
    23             url: "http://www.framsticks.com/files/apps/config/f0def.xml",
     29            url: local.urlToXML,
    2430            dataType: "xml",
    2531            async: false,
     
    6672        {
    6773            var neuroClass = new NeuroClass();
     74            this.neuroClasses[data[i].attributes[0].value] = neuroClass;
    6875            neuroClass.setModel(data);
    69             this.neuroClasses.push(neuroClass);
    70         }
     76        }
     77
    7178    },
    7279    analyseLine: function (line) {
     
    119126            })
    120127    },
    121     downloadCreature: function () {
    122         var lines;
     128    getCreature: function (mode, content) {
     129
     130        var lines = undefined;
     131        if(mode == this.Mode.LINK)
     132            lines = this._getCreatureFromLink(content);
     133        else if(mode == this.Mode.EMBEDDED)
     134            lines = this._getCreatureFromEmbeddedCode(content);
     135        else if (mode == this.Mode.TEXTAREA)
     136            lines = this._getCreatureFromTextArea(content);
     137        else if(mode == this.Mode.CODE)
     138            lines = this._getCreatureFromCode(content);
     139        else
     140        {
     141            throw "Wrong mode in function getCreature";
     142        }
     143        return lines;
     144    },
     145    _getCreatureFromLink: function(link){
     146        var lines = undefined;
    123147        $.ajax({
    124             url: "http://localhost:63343/FramestickFavi/creatures/" + this.debugCreatureName + ".txt",
     148            url: link,
    125149            async: false,
    126150            dataType: "text",
     
    132156                alert("Can't download creature");
    133157            }
    134 
    135         });
    136 
    137         //lines = $("#geno").val();
    138         //lines = lines.split("\n");
    139 
    140         return lines;
    141     },
    142     parseCreature: function () {
    143         var lines = this.downloadCreature();
     158        });
     159        return lines;
     160    },
     161    _getCreatureFromTextArea: function(area){
     162        var lines = undefined;
     163        lines = area.val();
     164        lines = lines.split("\n");
     165        return lines;
     166    },
     167    _getCreatureFromCode: function(code){
     168        var lines = code;
     169        lines = lines.split("\n");
     170        return lines;
     171    },
     172    _getCreatureFromEmbeddedCode: function(link){
     173        var lines = undefined;
     174
     175        $.ajax({
     176            url: link,
     177            async: false,
     178            dataType: "html",
     179            success: function (data) {
     180                var geno = $($(data).find("div")[0]).comments().html();
     181                geno = geno.replace("FRED_GEN", "");
     182                lines = geno.split("\n");
     183            },
     184            error: function () {
     185                alert("Can't download creature");
     186            }
     187        });
     188
     189        return lines;
     190    },
     191    parseCreature: function (mode, content) {
     192        var lines = this.getCreature(mode, content);
    144193        lines.splice(0, 1);
    145194        var local = this;
     
    164213        this._graphicsEngine.initializeScene();
    165214        this.renderCreature();
    166         //this._graphicsEngine.debugTest();
     215        this._graphicsEngine.debugTest();
    167216        this._graphicsEngine.renderScene();
    168217
    169218        this._neuronDrawer.initializeScene();
    170219        new SmartLayout(this.neurons, this.neuroConns);
    171         this._neuronDrawer.drawNetwork(this.neurons, this.neuroConns, einfos);
     220        this._neuronDrawer.drawNetwork(this.neurons, this.neuroConns, einfos, this.neuroClasses);
    172221        this._neuronDrawer.renderScene();
    173222
    174223    }
    175 
    176224}
    177225
    178226function openWindow() {
    179     geneWindow.downloadXML();
    180     geneWindow.parseGeneXml();
    181     geneWindow.parseCreature();
    182     geneWindow.mainLoop();
     227    var debugCreatureName = "example4";
     228    Viewer.downloadXML();
     229    Viewer.parseGeneXml();
     230    //Viewer.parseCreature(Viewer.Mode.LINK, "http://localhost:63343/FramestickFavi/creatures/" + debugCreatureName + ".txt");
     231    //Viewer.parseCreature(Viewer.Mode.TEXTAREA, $("#geno"));
     232    //Viewer.parseCreature(Viewer.Mode.CODE, "//0\np:\np: x=1");
     233    Viewer.parseCreature(Viewer.Mode.EMBEDDED, "http://ec.framsticks.com/www/index.php?PAGE=view_genotype&ID=55")
     234    Viewer.mainLoop();
     235
     236
    183237
    184238}
Note: See TracChangeset for help on using the changeset viewer.