[881] | 1 | /*global Module*/ |
---|
| 2 | "use strict"; |
---|
| 3 | |
---|
| 4 | /** |
---|
| 5 | * Static class containing tools for genotype parsing. |
---|
| 6 | */ |
---|
| 7 | class GenotypeParser { |
---|
| 8 | /** |
---|
| 9 | * Methods for checking if the given genotype is valid |
---|
| 10 | * @param {string} genotype input genotype |
---|
| 11 | * @returns {boolean} true if genotype is valid, false otherwise |
---|
| 12 | */ |
---|
| 13 | static parseGeno(genotype) { |
---|
| 14 | //let genetics = new Module.PreconfiguredGenetics(); |
---|
| 15 | let stringObj = new Module.SString(); |
---|
| 16 | stringObj.set(genotype); |
---|
| 17 | |
---|
| 18 | let genoObj = new Module.Geno(stringObj); |
---|
| 19 | let result = genoObj.isValid(); |
---|
| 20 | Module.destroy(genoObj); |
---|
| 21 | Module.destroy(stringObj); |
---|
| 22 | //Module.destroy(genetics); |
---|
| 23 | return result; |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | /** |
---|
| 27 | * HTML-ize genotype for syntax highlighting. The generated genotype is ready to use. |
---|
| 28 | * Based on Genman::HTMLize method from Framsticks SDK. |
---|
| 29 | * @param {string} genotype input genotype |
---|
| 30 | * @returns {string} HTML code that displays highlighted genotype code |
---|
| 31 | */ |
---|
| 32 | static generateHighlights(genotype) { |
---|
| 33 | //let genetics = new Module.PreconfiguredGenetics(); |
---|
| 34 | //let stringObj = new Module.SString(); |
---|
| 35 | //stringObj.set(genotype); |
---|
| 36 | let resultObj = window.genetics.get_genman().HTMLize(genotype); |
---|
| 37 | let result = resultObj.c_str(); |
---|
| 38 | //Module.destroy(resultObj); |
---|
| 39 | //Module.destroy(stringObj); |
---|
| 40 | //Module.destroy(genetics); |
---|
| 41 | return result; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | /** |
---|
| 45 | * Method that parse genotype and returns Framsticks Model. |
---|
| 46 | * @param {string} genotype string code for Framsticks creature |
---|
| 47 | * @returns {Module.Model} Model from genotype, or undefined if genotype is not valid |
---|
| 48 | */ |
---|
| 49 | static getModelFromGenotype(genotype) { |
---|
| 50 | //let genetics = new Module.PreconfiguredGenetics(); |
---|
| 51 | let stringObj = new Module.SString(); |
---|
| 52 | stringObj.set(genotype); |
---|
| 53 | let genoObj = new Module.Geno(stringObj); |
---|
| 54 | if (!genoObj.isValid()) { |
---|
| 55 | Module.destroy(stringObj); |
---|
| 56 | Module.destroy(genoObj); |
---|
| 57 | //Module.destroy(genetics); |
---|
| 58 | return; //undefined |
---|
| 59 | } |
---|
| 60 | let model = new Module.Model(genoObj, true); |
---|
| 61 | Module.destroy(stringObj); |
---|
| 62 | Module.destroy(genoObj); |
---|
| 63 | //Module.destroy(genetics); |
---|
| 64 | return model; |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | export default GenotypeParser; |
---|