www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

monde.js (4388B)


      1 function MMonde(nom) {
      2     $.extend(this, {
      3         uid: singleton.uid(),
      4         // Propriétés
      5         nom: nom,
      6         // Parents
      7         // Enfants
      8         log: null,
      9         recherche: null,
     10         barreOutils: null, // J'ai des doutes sur la présence de barreOutils…
     11         blocs: [],
     12         mBlocScratch: null,
     13         mDéfinitionScratch: null,
     14         // Ajout
     15         ajouterBloc: function(b) {
     16             b.monde = this;
     17             this.blocs.push(b);
     18             var that = this;
     19             b.onModification(function(b) {
     20                 faireCallbacks(that.cbModificationBloc, b);
     21             });
     22             faireCallbacks(this.cbAjoutBloc, b);
     23         },
     24         cbAjoutBloc: [],
     25         onAjoutBloc: function(callback) {
     26             this.cbAjoutBloc.push(callback);
     27         },
     28         cbModificationBloc: [],
     29         onModificationBloc: function(callback) {
     30             this.cbModificationBloc.push(callback);
     31         },
     32         instancesLog: [],
     33         ajouterInstanceLog: function(il) {
     34             this.instancesLog.push(il);
     35             faireCallbacks(this.cbAjoutInstanceLog, il);
     36         },
     37         cbAjoutInstanceLog: [],
     38         onAjoutInstanceLog: function(callback) {
     39             this.cbAjoutInstanceLog.push(callback);
     40         },
     41         instancesRecherche: [],
     42         ajouterInstanceRecherche: function(ir) {
     43             this.instancesRecherche.push(ir);
     44             faireCallbacks(this.cbAjoutInstanceRecherche, ir);
     45         },
     46         cbAjoutInstanceRecherche: [],
     47         onAjoutInstanceRecherche: function(callback) {
     48             this.cbAjoutInstanceRecherche.push(callback);
     49         },
     50         // Suppression
     51         supprimerBloc: function(b) {
     52             this.blocs.remove(b);
     53         }
     54     });
     55 
     56     var that = this;
     57     
     58     /* Actions */
     59     this.actionAucune = function() {};
     60     this.actionNouveauBloc = function(cDéfinition, rect, rectParent) {
     61         that.outilZone = that.actionAucune;
     62         if (rect.width < 10 || rect.height < 10) {
     63             return;
     64         }
     65         
     66         var mb = new MBloc();
     67         that.ajouterBloc(mb);
     68         var mib = mb.demanderInstance();
     69         mib.rect = rect;
     70         mib.rectParent = rectParent
     71         cDéfinition.modèle.ajouterInstanceBloc(mib);
     72     };
     73 
     74     this.actionInstanceBloc_mBloc = null;
     75     this.actionInstanceBloc = function(cDéfinition, rect, rectParent) {
     76         that.outilZone = that.actionAucune;
     77         if (rect.width < 10 || rect.height < 10 || that.actionInstanceBloc_mBloc === null) {
     78             return;
     79         }
     80         
     81         console.log(that);
     82         var mib = that.actionInstanceBloc_mBloc.demanderInstance();
     83         mib.rect = rect;
     84         mib.rectParent = rectParent
     85         cDéfinition.modèle.ajouterInstanceBloc(mib);
     86     };
     87     
     88     /* Outils */
     89     this.outilZone = this.actionNouveauBloc;
     90     
     91     /* Scratch */
     92     this.mBlocScratch = new MBloc();
     93     this.mBlocScratch.changeNom("Scratch");
     94     this.ajouterBloc(this.mBlocScratch);
     95     this.mDéfinitionScratch = new MDéfinition();
     96     this.mBlocScratch.ajouterDéfinition(this.mDéfinitionScratch);
     97     
     98     /* this.scratch = new MDéfinition(); // this.scratch.bloc == null; */
     99     this.barreOutils = new MBarreOutils();
    100     this.barreOutils.monde = this;
    101     this.recherche = new MRecherche();
    102     this.recherche.monde = this;
    103     this.log = new MLog();
    104     this.log.monde = this;
    105 }
    106 
    107 function VMonde(appendToElement) {
    108     $.extend(this, (
    109         $('#vue-monde')
    110             .jqote({})
    111             .appendTo(appendToElement)));
    112     
    113     this.vBarreOutils = null;
    114     this.vScratch = this.find('.scratch');
    115     
    116     this.ajoutVDéfinition = function(vTitreDéfinition, vCorpsDéfinition) {
    117         this.vScratch.replaceWith(vCorpsDéfinition);
    118         this.vScratch = vCorpsDéfinition;
    119     }
    120 }
    121 
    122 function CMonde(mMonde, appendToElement) {
    123     this.modèle = mMonde;
    124     this.vue = new VMonde(appendToElement, mMonde);
    125     this.vue.vBarreOutils = new CBarreOutils(this.modèle.barreOutils, this.vue);
    126     
    127     var that = this;
    128     
    129     CDéfinition(this.modèle.mDéfinitionScratch, this.vue);
    130     
    131     this.modèle.onAjoutInstanceLog(function (instanceLog) {
    132         var cil = new CInstanceLog(instanceLog, that.vue);
    133     });
    134     
    135     this.modèle.onAjoutInstanceRecherche(function (instanceRecherche) {
    136         var cil = new CInstanceRecherche(instanceRecherche, that.vue);
    137     });
    138 }
    139