public void UnitDefinitionElement(Hashtable attrs) { UnitDefinition unitDef = new UnitDefinition(this.model, attrs); unitDef.createUnitsList(); this.model.listOfUnitDefinitions.Add(unitDef); elementStack.Push(unitDef); }
public static int Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage: printNotes filename"); return(1); } int i, j; string filename = args[0]; SBMLDocument document; document = libsbml.readSBML(filename); int errors = (int)document.getNumErrors(); Console.WriteLine(); Console.WriteLine("filename: " + filename); Console.WriteLine(); if (errors > 0) { document.printErrors(); return(errors); } /* Model */ Model m = document.getModel(); printNotes(m); for (i = 0; i < m.getNumReactions(); i++) { Reaction re = m.getReaction(i); printNotes(re); /* SpeciesReference (Reacatant) */ for (j = 0; j < re.getNumReactants(); j++) { SpeciesReference rt = re.getReactant(j); if (rt.isSetNotes()) { Console.WriteLine(" "); } printNotes(rt, (rt.isSetSpecies() ? rt.getSpecies() : "")); } /* SpeciesReference (Product) */ for (j = 0; j < re.getNumProducts(); j++) { SpeciesReference rt = re.getProduct(j); if (rt.isSetNotes()) { Console.WriteLine(" "); } printNotes(rt, (rt.isSetSpecies() ? rt.getSpecies() : "")); } /* ModifierSpeciesReference (Modifier) */ for (j = 0; j < re.getNumModifiers(); j++) { ModifierSpeciesReference md = re.getModifier(j); if (md.isSetNotes()) { Console.WriteLine(" "); } printNotes(md, (md.isSetSpecies() ? md.getSpecies() : "")); } /* Kineticlaw */ if (re.isSetKineticLaw()) { KineticLaw kl = re.getKineticLaw(); if (kl.isSetNotes()) { Console.WriteLine(" "); } printNotes(kl); /* Parameter */ for (j = 0; j < kl.getNumParameters(); j++) { Parameter pa = kl.getParameter(j); if (pa.isSetNotes()) { Console.WriteLine(" "); } printNotes(pa); } } } /* Species */ for (i = 0; i < m.getNumSpecies(); i++) { Species sp = m.getSpecies(i); printNotes(sp); } /* Compartment */ for (i = 0; i < m.getNumCompartments(); i++) { Compartment sp = m.getCompartment(i); printNotes(sp); } /* FunctionDefinition */ for (i = 0; i < m.getNumFunctionDefinitions(); i++) { FunctionDefinition sp = m.getFunctionDefinition(i); printNotes(sp); } /* UnitDefinition */ for (i = 0; i < m.getNumUnitDefinitions(); i++) { UnitDefinition sp = m.getUnitDefinition(i); printNotes(sp); } /* Parameter */ for (i = 0; i < m.getNumParameters(); i++) { Parameter sp = m.getParameter(i); printNotes(sp); } /* Rule */ for (i = 0; i < m.getNumRules(); i++) { Rule sp = m.getRule(i); printNotes(sp); } /* InitialAssignment */ for (i = 0; i < m.getNumInitialAssignments(); i++) { InitialAssignment sp = m.getInitialAssignment(i); printNotes(sp); } /* Event */ for (i = 0; i < m.getNumEvents(); i++) { Event sp = m.getEvent(i); printNotes(sp); /* Trigger */ if (sp.isSetTrigger()) { Trigger tg = sp.getTrigger(); if (tg.isSetNotes()) { Console.WriteLine(" "); } printNotes(tg); } /* Delay */ if (sp.isSetDelay()) { Delay dl = sp.getDelay(); if (dl.isSetNotes()) { Console.WriteLine(" "); } printNotes(dl); } /* EventAssignment */ for (j = 0; j < sp.getNumEventAssignments(); j++) { EventAssignment ea = sp.getEventAssignment(j); if (ea.isSetNotes()) { Console.WriteLine(" "); } printNotes(ea); } } /* SpeciesType */ for (i = 0; i < m.getNumSpeciesTypes(); i++) { SpeciesType sp = m.getSpeciesType(i); printNotes(sp); } /* Constraint */ for (i = 0; i < m.getNumConstraints(); i++) { Constraint sp = m.getConstraint(i); printNotes(sp); } return(errors); }
public bool TryGetValue(UnitDefinition unit, out CreatureSpriteCollection collection) { return(TryGetValue(unit.race.mat_index, out collection)); }
public virtual void MakeSchemaCompliant() { UnitDefinition.MakeSchemaCompliant(); }
abstract public bool GetValue(UnitDefinition unit, out T value);
internal void UpdateLayers(UnitDefinition unit, CreatureRaw creatureRaw, CasteRaw casteRaw) { for (int i = 0; i < spriteList.Count; i++) { var spriteLayerDef = SpriteCollection.spriteLayers[i]; var sprite = spriteList[i]; switch (spriteLayerDef.spriteSource) { case CreatureSpriteLayer.SpriteSource.Static: sprite.gameObject.SetActive(true); switch (spriteLayerDef.colorSource) { case CreatureSpriteLayer.ColorSource.Fixed: sprite.color = spriteLayerDef.color; break; case CreatureSpriteLayer.ColorSource.Job: sprite.color = new Color(unit.profession_color.red / 255.0f, unit.profession_color.green / 255.0f, unit.profession_color.blue / 255.0f, 0.5f); break; default: sprite.color = new Color32(128, 128, 128, 128); break; } break; case CreatureSpriteLayer.SpriteSource.Bodypart: sprite.gameObject.SetActive(true); switch (spriteLayerDef.colorSource) { case CreatureSpriteLayer.ColorSource.Fixed: sprite.color = spriteLayerDef.color; break; case CreatureSpriteLayer.ColorSource.Material: ColorDefinition unitColor = new ColorDefinition(); int colorModIndex = casteRaw.color_modifiers.FindIndex(x => x.part == spriteLayerDef.token && x.start_date == 0); if (colorModIndex >= 0 && unit.appearance != null) { unitColor = casteRaw.color_modifiers[colorModIndex].patterns[unit.appearance.colors[colorModIndex]].colors[spriteLayerDef.patternIndex]; sprite.color = new Color32((byte)unitColor.red, (byte)unitColor.green, (byte)unitColor.blue, 128); } else { int tissueIndex = creatureRaw.tissues.FindIndex(x => x.name == spriteLayerDef.token); if (tissueIndex >= 0) { sprite.color = ContentLoader.GetColor(creatureRaw.tissues[tissueIndex].material); } else { sprite.gameObject.SetActive(false); } break; } break; case CreatureSpriteLayer.ColorSource.Job: sprite.color = new Color(unit.profession_color.red / 255.0f, unit.profession_color.green / 255.0f, unit.profession_color.blue / 255.0f, 0.5f); break; case CreatureSpriteLayer.ColorSource.BodyPart: var part = casteRaw.body_parts.Find(x => x.token == spriteLayerDef.token); if (part == null) { sprite.gameObject.SetActive(false); break; } sprite.color = ContentLoader.GetColor(creatureRaw.tissues[part.layers[0].tissue_id].material); break; default: sprite.color = new Color32(128, 128, 128, 128); break; } switch (spriteLayerDef.hairType) { case CreatureSpriteLayer.HairType.Hair: if (unit.inventory.FindIndex(x => x.item.type.mat_type == (int)ItemType.Helm) >= 0) { sprite.gameObject.SetActive(false); break; } if (unit.appearance == null || unit.appearance.hair == null) { sprite.gameObject.SetActive(spriteLayerDef.hairStyle == HairStyle.UNKEMPT); } else { sprite.gameObject.SetActive((spriteLayerDef.hairStyle == unit.appearance.hair.style) && (spriteLayerDef.hairMin <= unit.appearance.hair.length) && ((spriteLayerDef.hairMax < 0) || (spriteLayerDef.hairMax > unit.appearance.hair.length))); } break; case CreatureSpriteLayer.HairType.Beard: if (unit.appearance == null || unit.appearance.beard == null) { sprite.gameObject.SetActive(spriteLayerDef.hairStyle == HairStyle.UNKEMPT); } else { sprite.gameObject.SetActive((spriteLayerDef.hairStyle == unit.appearance.beard.style) && (spriteLayerDef.hairMin <= unit.appearance.beard.length) && ((spriteLayerDef.hairMax < 0) || (spriteLayerDef.hairMax > unit.appearance.beard.length))); } break; case CreatureSpriteLayer.HairType.Moustache: if (unit.appearance == null || unit.appearance.moustache == null) { sprite.gameObject.SetActive(spriteLayerDef.hairStyle == HairStyle.UNKEMPT); } else { sprite.gameObject.SetActive((spriteLayerDef.hairStyle == unit.appearance.moustache.style) && (spriteLayerDef.hairMin <= unit.appearance.moustache.length) && ((spriteLayerDef.hairMax < 0) || (spriteLayerDef.hairMax > unit.appearance.moustache.length))); } break; case CreatureSpriteLayer.HairType.Sideburns: if (unit.appearance == null || unit.appearance.sideburns == null) { sprite.gameObject.SetActive(spriteLayerDef.hairStyle == HairStyle.UNKEMPT); } else { sprite.gameObject.SetActive((spriteLayerDef.hairStyle == unit.appearance.sideburns.style) && (spriteLayerDef.hairMin <= unit.appearance.sideburns.length) && ((spriteLayerDef.hairMax < 0) || (spriteLayerDef.hairMax > unit.appearance.sideburns.length))); } break; default: sprite.gameObject.SetActive(true); break; } break; case CreatureSpriteLayer.SpriteSource.Equipment: int inventoryIndex = unit.inventory.FindIndex( x => (x.mode == InventoryMode.Weapon || x.mode == InventoryMode.Worn) && spriteLayerDef.token == ItemRaws.Instance[x.item.type].id ); if (inventoryIndex < 0) { sprite.gameObject.SetActive(false); break; } else { sprite.enabled = true; } var item = unit.inventory[inventoryIndex].item; switch (spriteLayerDef.colorSource) { case CreatureSpriteLayer.ColorSource.Fixed: sprite.color = spriteLayerDef.color; break; case CreatureSpriteLayer.ColorSource.Material: sprite.color = ContentLoader.GetColor(item); break; case CreatureSpriteLayer.ColorSource.Job: sprite.color = new Color(unit.profession_color.red / 255.0f, unit.profession_color.green / 255.0f, unit.profession_color.blue / 255.0f, 0.5f); break; default: sprite.color = new Color32(128, 128, 128, 128); break; } break; default: sprite.gameObject.SetActive(false); break; } if (sprite.color.a < 0.5f) { sprite.sharedMaterial = SpriteMatTrans; } else { sprite.sharedMaterial = SpriteMat; } } }
static void testListOfRemove(ListOf lof, SBase s) { string ename = s.getElementName(); lof.append(s); SBase c = lof.get(0); if (c is CompartmentType) { CompartmentType x = (lof as ListOfCompartmentTypes).remove(0); c = x; } else if (c is Compartment) { Compartment x = (lof as ListOfCompartments).remove(0); c = x; } else if (c is Constraint) { Constraint x = (lof as ListOfConstraints).remove(0); c = x; } else if (c is EventAssignment) { EventAssignment x = (lof as ListOfEventAssignments).remove(0); c = x; } else if (c is Event) { Event x = (lof as ListOfEvents).remove(0); c = x; } else if (c is FunctionDefinition) { FunctionDefinition x = (lof as ListOfFunctionDefinitions).remove(0); c = x; } else if (c is InitialAssignment) { InitialAssignment x = (lof as ListOfInitialAssignments).remove(0); c = x; } else if (c is Parameter) { Parameter x = (lof as ListOfParameters).remove(0); c = x; } else if (c is Reaction) { Reaction x = (lof as ListOfReactions).remove(0); c = x; } else if (c is Rule) { Rule x = (lof as ListOfRules).remove(0); c = x; } else if (c is Species) { Species x = (lof as ListOfSpecies).remove(0); c = x; } else if (c is SpeciesReference) { SimpleSpeciesReference x = (lof as ListOfSpeciesReferences).remove(0); c = x; } else if (c is SpeciesType) { SpeciesType x = (lof as ListOfSpeciesTypes).remove(0); c = x; } else if (c is UnitDefinition) { UnitDefinition x = (lof as ListOfUnitDefinitions).remove(0); c = x; } else if (c is Unit) { Unit x = (lof as ListOfUnits).remove(0); c = x; } else { ERR("[testListOfRemove] Error: (" + ename + ") : ListOfXXX::remove() failed."); return; } if (c == null) { ERR("[testListOfRemove] Error: (" + ename + ") : ListOfXXX::remove() failed."); return; } string enameGet = c.getElementName(); if (ename == enameGet) { //Console.Out.WriteLine("[testListOfRemove] OK: (" + ename + ") remove(" + enameGet + ") : type match."); OK(); } else { ERR("[testListOfRemove] Error: (" + ename + ") remove(" + enameGet + ") : type mismatch."); } }
static void testClone(SBase s) { string ename = s.getElementName(); SBase c = s.clone(); if (c is Compartment) { Compartment x = (s as Compartment).clone(); c = x; } else if (c is CompartmentType) { CompartmentType x = (s as CompartmentType).clone(); c = x; } else if (c is Constraint) { Constraint x = (s as Constraint).clone(); c = x; } else if (c is Delay) { Delay x = (s as Delay).clone(); c = x; } else if (c is Event) { Event x = (s as Event).clone(); c = x; } else if (c is EventAssignment) { EventAssignment x = (s as EventAssignment).clone(); c = x; } else if (c is FunctionDefinition) { FunctionDefinition x = (s as FunctionDefinition).clone(); c = x; } else if (c is InitialAssignment) { InitialAssignment x = (s as InitialAssignment).clone(); c = x; } else if (c is KineticLaw) { KineticLaw x = (s as KineticLaw).clone(); c = x; } // currently return type of ListOf::clone() is SBase else if (c is ListOf) { SBase x = (s as ListOf).clone(); c = x; } else if (c is Model) { Model x = (s as Model).clone(); c = x; } else if (c is Parameter) { Parameter x = (s as Parameter).clone(); c = x; } else if (c is Reaction) { Reaction x = (s as Reaction).clone(); c = x; } else if (c is AlgebraicRule) { AlgebraicRule x = (s as AlgebraicRule).clone(); c = x; } else if (c is AssignmentRule) { AssignmentRule x = (s as AssignmentRule).clone(); c = x; } else if (c is RateRule) { RateRule x = (s as RateRule).clone(); c = x; } else if (c is SBMLDocument) { SBMLDocument x = (s as SBMLDocument).clone(); c = x; } else if (c is Species) { Species x = (s as Species).clone(); c = x; } else if (c is SpeciesReference) { SpeciesReference x = (s as SpeciesReference).clone(); c = x; } else if (c is SpeciesType) { SpeciesType x = (s as SpeciesType).clone(); c = x; } else if (c is SpeciesReference) { SpeciesReference x = (s as SpeciesReference).clone(); c = x; } else if (c is StoichiometryMath) { StoichiometryMath x = (s as StoichiometryMath).clone(); c = x; } else if (c is Trigger) { Trigger x = (s as Trigger).clone(); c = x; } else if (c is Unit) { Unit x = (s as Unit).clone(); c = x; } else if (c is UnitDefinition) { UnitDefinition x = (s as UnitDefinition).clone(); c = x; } else if (c is ListOfCompartmentTypes) { ListOfCompartmentTypes x = (s as ListOfCompartmentTypes).clone(); c = x; } else if (c is ListOfCompartments) { ListOfCompartments x = (s as ListOfCompartments).clone(); c = x; } else if (c is ListOfConstraints) { ListOfConstraints x = (s as ListOfConstraints).clone(); c = x; } else if (c is ListOfEventAssignments) { ListOfEventAssignments x = (s as ListOfEventAssignments).clone(); c = x; } else if (c is ListOfEvents) { ListOfEvents x = (s as ListOfEvents).clone(); c = x; } else if (c is ListOfFunctionDefinitions) { ListOfFunctionDefinitions x = (s as ListOfFunctionDefinitions).clone(); c = x; } else if (c is ListOfInitialAssignments) { ListOfInitialAssignments x = (s as ListOfInitialAssignments).clone(); c = x; } else if (c is ListOfParameters) { ListOfParameters x = (s as ListOfParameters).clone(); c = x; } else if (c is ListOfReactions) { ListOfReactions x = (s as ListOfReactions).clone(); c = x; } else if (c is ListOfRules) { ListOfRules x = (s as ListOfRules).clone(); c = x; } else if (c is ListOfSpecies) { ListOfSpecies x = (s as ListOfSpecies).clone(); c = x; } else if (c is ListOfSpeciesReferences) { ListOfSpeciesReferences x = (s as ListOfSpeciesReferences).clone(); c = x; } else if (c is ListOfSpeciesTypes) { ListOfSpeciesTypes x = (s as ListOfSpeciesTypes).clone(); c = x; } else if (c is ListOfUnitDefinitions) { ListOfUnitDefinitions x = (s as ListOfUnitDefinitions).clone(); c = x; } else if (c is ListOfUnits) { ListOfUnits x = (s as ListOfUnits).clone(); c = x; } else { ERR("[testClone] Error: (" + ename + ") : clone() failed."); return; } if (c == null) { ERR("[testClone] Error: (" + ename + ") : clone() failed."); return; } string enameClone = c.getElementName(); if (ename == enameClone) { //Console.Out.WriteLine("[testClone] OK: (" + ename + ") clone(" + enameClone + ") : type match."); OK(); } else { ERR("[testClone] Error: (" + ename + ") clone(" + enameClone + ") : type mismatch."); } }