public void AddGlobals() { if (bot != null) { curStatusColor = new ValString(bot.statusColor.ToHexString()); curScreenColor = new ValString(bot.screenColor.ToHexString()); var globals = interpreter.vm.globalContext; if (globals.variables == null) { globals.variables = new ValMap(); } globals.variables["statusColor"] = curStatusColor; globals.variables["screenColor"] = curScreenColor; globals.variables.assignOverride = (key, value) => { string keyStr = key.ToString(); if (keyStr == "_") { return(false); } //Debug.Log($"global {key} = {value}"); if (keyStr == "statusColor") { bot.statusColor = value.ToString().ToColor(); } else if (keyStr == "screenColor") { bot.screenColor = value.ToString().ToColor(); } return(false); // allow the assignment }; } }
public static ValMap ToMap(StardewValley.Object obj) { var result = new ValMap(); string type = obj.Type; if (type == "asdf") { type = obj.Name; // because, c'mon. } result.map[_type] = new ValString(type); // ToDo: limit the following to ones that really apply for this type. result.map[_name] = new ValString(obj.Name); result["displayName"] = new ValString(obj.DisplayName); result["health"] = new ValNumber(obj.getHealth()); if (obj.isLamp.Get()) { result["isOn"] = ValNumber.Truth(obj.IsOn); } result["quality"] = new ValNumber(obj.Quality); result.map[_harvestable] = ValNumber.Truth(obj.readyForHarvest.Get()); result["minutesTillReady"] = new ValNumber(obj.MinutesUntilReady); result["value"] = new ValNumber(obj.sellToStorePrice()); result["description"] = new ValString(obj.getDescription()); return(result); }
public void Ent_PropGroup_Prop_KString_VString() { EtagairCore core = Common.CreateCoreInMemory(); // create an entity template to instantiate EntityTempl templComputer = core.EditorTempl.CreateEntityTempl("TemplComputer"); // create the group Core PropGroupTempl propGroupTemplCore = core.EditorTempl.CreatePropGroupTempl(templComputer, "Core"); // under the propGroup Core, create the prop Type=Intel PropTempl propTemplType = core.EditorTempl.CreatePropTempl(templComputer, propGroupTemplCore, "Type", "Intel"); //====Instantiate EntityTemplToInst templToInst = core.ProcessTempl.CreateEntity(templComputer); // check that the execution finishes with success Assert.AreEqual(TemplToInstState.Success, templToInst.State, "the state should be sucess"); Assert.AreEqual(TemplToInstStep.Ends, templToInst.NextStep, "the next step should be ends"); //=====Check the creation //----check the prop group: Core PropertyBase propBase = core.Searcher.FindPropertyByKey(templToInst.Entity, templToInst.Entity.PropertyRoot, "Core", false); PropertyGroup propGroup = propBase as PropertyGroup; Assert.IsNotNull(propGroup, "the propgroup Core should exists"); // Check the prop group key PropertyKeyString propGroupKey = propGroup.Key as PropertyKeyString; Assert.IsNotNull(propGroupKey, "the propgroup key Core should exists"); Assert.AreEqual("Core", propGroupKey.Key, "the key should be Core"); //----check the property child: Type=Computer propBase = core.Searcher.FindPropertyByKey(templToInst.Entity, propGroup, "Type", false); Property prop = propBase as Property; Assert.IsNotNull(prop, "the prop child Type should exists"); // find the prop Intel (inside the group Core) from the root property PropertyBase propBaseTypeIntel = core.Searcher.FindPropertyByKey(templToInst.Entity, "Type", true); Property propTypeIntel = propBaseTypeIntel as Property; Assert.IsNotNull(propTypeIntel, "the prop child Type should exists (find from the root)"); // check the prop key: Type, find the prop from the parent PropertyKeyString propKeyString = prop.Key as PropertyKeyString; Assert.IsNotNull(propKeyString, "the prop key string Type should exists"); Assert.AreEqual("Type", propKeyString.Key, "the key should be Type"); // check the prop value //PropertyValueString propValueString = prop.Value as PropertyValueString; ValString propValueString = prop.Value as ValString; Assert.IsNotNull(propValueString, "the prop key string Type should exists"); Assert.AreEqual("Intel", propValueString.Value, "the value should be Intel"); }
/// <summary> /// Create a property to an object: key - value, /// </summary> /// <param name="entity"></param> /// <param name="tcKey"></param> /// <param name="tcValue"></param> /// <returns></returns> public Property CreateProperty(Entity entity, PropertyGroup propertyParent, TextCode tcKey, string value) { // create the property value ValString valString = new ValString(); valString.Value = value; return(CreateProperty(entity, propertyParent, tcKey, valString)); }
private string GetPropValueText(EtagairEngine engine, IValue value) { ValString propValueString = value as ValString; if (propValueString != null) { return("\"" + propValueString.Value + "\""); } ValTextCodeId propValueTextCode = value as ValTextCodeId; string propKeyText = "\"" + "tc/" + engine.Searcher.FindTextCodeById(propValueTextCode.TextCodeId).Code + "\""; return(propKeyText); }
static ValMap ToMap(TerrainFeature feature) { if (feature == null) { return(null); } var result = new ValMap(); result.map[_type] = result["name"] = new ValString(feature.GetType().Name); if (feature is Tree tree) { result.map[_treeType] = new ValNumber(tree.treeType.Value); result.map[_growthStage] = new ValNumber(tree.growthStage.Value); result.map[_health] = new ValNumber(tree.health.Value); result.map[_stump] = ValNumber.Truth(tree.stump.Value); result.map[_tapped] = ValNumber.Truth(tree.tapped.Value); result.map[_hasSeed] = ValNumber.Truth(tree.hasSeed.Value); } else if (feature is HoeDirt hoeDirt) { result.map[_dry] = ValNumber.Truth(hoeDirt.state.Value != 1); var crop = hoeDirt.crop; if (crop == null) { result.map[_crop] = null; } else { ValMap cropInfo = new ValMap(); cropInfo.map[_phase] = new ValNumber(crop.currentPhase.Value); cropInfo.map[_maxPhase] = new ValNumber(crop.phaseDays.Count - 1); cropInfo.map[_mature] = ValNumber.Truth(crop.fullyGrown.Value); cropInfo.map[_dead] = ValNumber.Truth(crop.dead.Value); cropInfo.map[_harvestMethod] = ValNumber.Truth(crop.harvestMethod.Value); bool harvestable = (int)crop.currentPhase.Value >= crop.phaseDays.Count - 1 && (!crop.fullyGrown.Value || (int)crop.dayOfCurrentPhase.Value <= 0); cropInfo.map[_harvestable] = ValNumber.Truth(harvestable); //Note: we might be able to get the name of the crop // using crop.indexOfHarvest or crop.netSeedIndex var product = new StardewValley.Object(crop.indexOfHarvest.Value, 0); cropInfo.map[_name] = new ValString(product.DisplayName); result.map[_crop] = cropInfo; } } return(result); }
static ValMap ToMap(Character character) { if (character == null) { return(null); } var result = new ValMap(); result.map[_type] = new ValString("Character"); result.map[_name] = new ValString(character.Name); result["displayName"] = new ValString(character.displayName); result["facing"] = new ValNumber(character.FacingDirection); result["isEmoting"] = ValNumber.Truth(character.isEmoting); result["emote"] = new ValNumber(character.CurrentEmote); result["isMonster"] = ValNumber.Truth(character.IsMonster); return(result); }
/// <summary> /// Return the property value content as a string. /// Can be a string, a textCodeId. /// Later: image,... /// /// </summary> /// <param name="propertyKeyBase"></param> /// <returns></returns> public static string GetPropertyValueContent(IValue value) { ValString propValueString = value as ValString; if (propValueString != null) { return(propValueString.Value); } ValTextCodeId propValueTextCode = value as ValTextCodeId; if (propValueTextCode != null) { return(propValueTextCode.TextCodeId); } // TODO: implement others types: Image, ImageCode,... return(null); }
public void EntOneProp_KString_VString() { EtagairCore core = Common.CreateCore(RepositConfig); // create an entity template to instantiate EntityTempl templComputer = core.EditorTempl.CreateEntityTempl("TemplComputer"); // add property PropTempl propTempl = core.EditorTempl.CreatePropTempl(templComputer, "Type", "Computer"); // check the property key (type and value) PropKeyTemplString propKeyString = propTempl.Key as PropKeyTemplString; Assert.IsNotNull(propKeyString, "the key should be a string"); Assert.AreEqual("Type", propKeyString.Key, "the key should be 'Type'"); // check the property value (type and value) ValString propValueString = propTempl.PropValueTempl.Value as ValString; Assert.IsNotNull(propValueString, "the value should be a string"); Assert.AreEqual("Computer", propValueString.Value, "the key should be 'Computer'"); }
public void EntOneProp_KString_VString() { EtagairCore core = Common.CreateCore(RepositConfig); // create an entity template to instantiate EntityTempl templComputer = core.EditorTempl.CreateEntityTempl("TemplComputer"); // add property core.EditorTempl.CreatePropTempl(templComputer, "Type", "Computer"); //====Instanciate the template, create an entity, under the root folder EntityTemplToInst templToInst = core.ProcessTempl.CreateEntity(templComputer); //====check that the execution finishes with success Assert.AreEqual(TemplToInstState.Success, templToInst.State, "the state should be sucess"); Assert.AreEqual(TemplToInstStep.Ends, templToInst.NextStep, "the next step should be ends"); // check, get the property: Type=Computer PropertyBase propBase = core.Searcher.FindPropertyByKey(templToInst.Entity, templToInst.Entity.PropertyRoot, "Type", false); Assert.IsNotNull(propBase, "the propBase Type=Computer should exists"); Property prop = propBase as Property; Assert.IsNotNull(prop, "the prop Type=Computer should exists"); // check the key prop PropertyKeyString propKeyString = prop.Key as PropertyKeyString; Assert.IsNotNull(propKeyString, "the prop key string Type should exists"); Assert.AreEqual("Type", propKeyString.Key, "the key should be Type"); // check the prop value //PropertyValueString propValueString = prop.Value as PropertyValueString; ValString propValueString = prop.Value as ValString; Assert.IsNotNull(propValueString, "the prop key string Typeshould exists"); Assert.AreEqual("Computer", propValueString.Value, "the value should be Computer"); }
public void CreateEntity_Prop_KeyString_ValString() { EtagairCore core = Common.CreateCore(RepositConfig); // create an ent Entity toshibaCoreI7 = core.Editor.CreateEntity(); // Add a property to an object: key - value Property propName = core.Editor.CreateProperty(toshibaCoreI7, "Name", "Toshiba"); // check the property key (type and value) PropertyKeyString propKeyString = propName.Key as PropertyKeyString; Assert.IsNotNull(propKeyString, "the key should be a string"); Assert.AreEqual("Name", propKeyString.Key, "the key should be 'Name'"); // check the property value (type and value) //PropertyValueString propValueString = propName.Value as PropertyValueString; ValString propValueString = propName.Value as ValString; Assert.IsNotNull(propValueString, "the value should be a string"); Assert.AreEqual("Toshiba", propValueString.Value, "the key should be 'Toshiba'"); }
/// <summary> /// create the value by copy from the template. /// </summary> /// <param name="actionSetOnInst"></param> /// <param name="ruleValueSetOnInst"></param> /// <returns></returns> //private PropertyValueBase CreatePropValueFromAction(PropTemplRuleActionValueToSet actionSetOnInst, PropTemplRuleValueToSet ruleValueSetOnInst) private IValue CreatePropValueFromAction(PropTemplRuleActionValueToSet actionSetOnInst, PropTemplRuleValueToSet ruleValueSetOnInst) { if (ruleValueSetOnInst.ValueType == PropValueType.String) { //PropertyValueString propValueString = new PropertyValueString(); //propValueString.Value = actionSetOnInst.ValueString; // return propValueString; ValString valString = new ValString(); valString.Value = actionSetOnInst.ValueString; return(valString); } if (ruleValueSetOnInst.ValueType == PropValueType.TextCode) { //PropertyValueTextCode propValueTextCode = new PropertyValueTextCode(); //propValueTextCode.TextCodeId = actionSetOnInst.ValueTextCodeId; //return propValueTextCode; ValTextCodeId valTextCodeId = new ValTextCodeId(); valTextCodeId.TextCodeId = actionSetOnInst.ValueTextCodeId; return(valTextCodeId); } throw new Exception("property Value type not yet implemented!"); }
public static ValMap ToMap(StardewValley.Item item) { if (item == null) { return(null); } var result = new ValMap(); result.map[_type] = new ValString(item.GetType().Name); // ToDo: limit the following to ones that really apply for this type. result.map[_name] = new ValString(item.Name); result["displayName"] = new ValString(item.DisplayName); result["stack"] = new ValNumber(item.Stack); result["maxStack"] = new ValNumber(item.maximumStackSize()); result["category"] = new ValString(item.getCategoryName()); result["value"] = new ValNumber(item.salePrice()); result["description"] = new ValString(item.getDescription().Trim()); if (item is StardewValley.Tools.WateringCan can) { result["waterLeft"] = new ValNumber(can.WaterLeft); result["waterMax"] = new ValNumber(can.waterCanMax); } return(result); }
public void Init(Bot botContext = null) { this.bot = botContext; M1API.Init(this); var display = console.display; display.backColor = new Color(0.31f, 0.11f, 0.86f); display.Clear(); var colors = new Color[] { Color.Red, Color.Yellow, Color.Green, Color.Purple }; display.SetCursor(19, 3); for (int i = 0; i < 4; i++) { display.textColor = colors[i]; display.Print("*"); } display.textColor = Color.Azure; display.Print(" Farmtronics " + (botContext == null ? "Home" : "Bot") + " Computer "); for (int i = 0; i < 4; i++) { display.textColor = colors[3 - i]; display.Print("*"); } display.textColor = Color.White; display.NextLine(); if (interpreter.vm == null) { interpreter.REPL("", 0); // (forces creation of a VM) AddGlobals(); } { var d = new RealFileDisk(); d.readOnly = true; d.Open(Path.Combine(ModEntry.helper.DirectoryPath, "assets", "sysdisk")); sysDisk = d; FileUtils.disks["sys"] = sysDisk; } if (!string.IsNullOrEmpty(Constants.CurrentSavePath)) { var d = new RealFileDisk(); d.readOnly = false; d.Open(Path.Combine(Constants.CurrentSavePath, "usrdisk")); FileUtils.disks["usr"] = d; } // Prepare the env map env = new ValMap(); if (FileUtils.disks.ContainsKey("usr") && FileUtils.disks["usr"] != null) { env["curdir"] = new ValString("/usr/"); } else { env["curdir"] = new ValString("/sys/demo"); } env["home"] = new ValString("/usr/"); env["prompt"] = new ValString("]"); env["morePrompt"] = new ValString("...]"); // NOTE: importPaths is also in the reset function in startup.ms. // If you change this in either place, change it in both! var importPaths = new List <string> { ".", "/usr/lib", "/sys/lib" }; env["importPaths"] = importPaths.ToValue(); RunStartupScripts(); }
public void Ent_PropGroup_Prop_KString_VString_RULToSet() { EtagairCore core = Common.CreateCoreInMemory(); // create an entity template to instantiate EntityTempl entTemplComputer = core.EditorTempl.CreateEntityTempl("TemplComputer"); // create the group Core PropGroupTempl propGroupTemplCore = core.EditorTempl.CreatePropGroupTempl(entTemplComputer, "Core"); // create a property template without the value: will be created on the instantiation PropTempl propTemplType = core.EditorTempl.CreatePropTempl(entTemplComputer, propGroupTemplCore, "Type", (string)null); // On prop type, Add Rule: add property, V=RULE:ToSet, type= string PropTemplRuleValueToSet rule = new PropTemplRuleValueToSet(); rule.ValueType = PropValueType.String; core.EditorTempl.AddPropTemplRule(entTemplComputer, propTemplType, rule); //====Instantiate EntityTemplToInst templToInst = core.ProcessTempl.CreateEntity(entTemplComputer); Assert.AreEqual(TemplToInstState.InProgress, templToInst.State, "the state should be InProgress"); Assert.AreEqual(TemplToInstStep.NeedAction, templToInst.NextStep, "the next step should be NeedAction"); //---provide an action to the rule (to execute it automatically): Property value set on instantiation PropTemplRuleActionValueToSet action = new PropTemplRuleActionValueToSet(); action.SetRule(rule); action.SetValueString("Intel"); // adds actions to rules and create the entity core.ProcessTempl.AddActionsToCreateEntity(templToInst, action); Assert.AreEqual(TemplToInstState.InProgress, templToInst.State, "the state should be InProgress"); Assert.AreEqual(TemplToInstStep.Starts, templToInst.NextStep, "the next step should be NeedAction"); // create the entity, use action core.ProcessTempl.CompleteCreateEntity(templToInst); // check that the execution finishes with success Assert.AreEqual(TemplToInstState.Success, templToInst.State, "the state should be sucess"); Assert.AreEqual(TemplToInstStep.Ends, templToInst.NextStep, "the next step should be ends"); //=====Check the creation //----check the prop group: Core PropertyBase propBase = core.Searcher.FindPropertyByKey(templToInst.Entity, templToInst.Entity.PropertyRoot, "Core", false); PropertyGroup propGroup = propBase as PropertyGroup; Assert.IsNotNull(propGroup, "the propgroup Core should exists"); // Check the prop group key PropertyKeyString propGroupKey = propGroup.Key as PropertyKeyString; Assert.IsNotNull(propGroupKey, "the propgroup key Core should exists"); Assert.AreEqual("Core", propGroupKey.Key, "the key should be Core"); //----check the property child: Type=Computer propBase = core.Searcher.FindPropertyByKey(templToInst.Entity, propGroup, "Type", false); Property prop = propBase as Property; Assert.IsNotNull(prop, "the prop child Type should exists"); // find the prop Intel (inside the group Core) from the root property PropertyBase propBaseTypeIntel = core.Searcher.FindPropertyByKey(templToInst.Entity, "Type", true); Property propTypeIntel = propBaseTypeIntel as Property; Assert.IsNotNull(propTypeIntel, "the prop child Type should exists (find from the root)"); // check the prop key: Type, find the prop from the parent PropertyKeyString propKeyString = prop.Key as PropertyKeyString; Assert.IsNotNull(propKeyString, "the prop key string Type should exists"); Assert.AreEqual("Type", propKeyString.Key, "the key should be Type"); // check the prop value //PropertyValueString propValueString = prop.Value as PropertyValueString; ValString propValueString = prop.Value as ValString; Assert.IsNotNull(propValueString, "the prop key string Type should exists"); Assert.AreEqual("Intel", propValueString.Value, "the value should be Intel"); }
public void EntOneProp_KeyString_ValString_RULToSet() { EtagairCore core = Common.CreateCoreInMemory(); // create an entity template to instanciate EntityTempl templComputer = core.EditorTempl.CreateEntityTempl("TemplComputer"); // create a property template without the value: will be created on the instantiation PropTempl propTempl = core.EditorTempl.CreatePropTemplValueStringNull(templComputer, "Name"); // Add Rule: add property, V=RULE:Toset, type= TextCode: to be set on instanciation PropTemplRuleValueToSet rule = new PropTemplRuleValueToSet(); rule.ValueType = PropValueType.String; core.EditorTempl.AddPropTemplRule(templComputer, propTempl, rule); // provide an action to the rule (to execute it automatically): Property value set on instantiation PropTemplRuleActionValueToSet action = new PropTemplRuleActionValueToSet(); action.SetRule(rule); action.SetValueString("Toshiba"); //====Instantiate the template, create an entity, under the root folder EntityTemplToInst templToInst = core.ProcessTempl.CreateEntity(templComputer); Assert.AreEqual(TemplToInstState.InProgress, templToInst.State, "the state should be InProgress"); Assert.AreEqual(TemplToInstStep.NeedAction, templToInst.NextStep, "the next step should be NeedAction"); // adds actions to rules and create the entity core.ProcessTempl.AddActionsToCreateEntity(templToInst, action); Assert.AreEqual(TemplToInstState.InProgress, templToInst.State, "the state should be InProgress"); Assert.AreEqual(TemplToInstStep.Starts, templToInst.NextStep, "the next step should be Starts"); // create the entity, use action core.ProcessTempl.CompleteCreateEntity(templToInst); // check that the execution finishes with success Assert.AreEqual(TemplToInstState.Success, templToInst.State, "the state should be sucess"); Assert.AreEqual(TemplToInstStep.Ends, templToInst.NextStep, "the next step should be ends"); //====check, get the property: Name=Toshiba PropertyBase propBase = core.Searcher.FindPropertyByKey(templToInst.Entity, templToInst.Entity.PropertyRoot, "Name", false); Assert.IsNotNull(propBase, "the propBase Type=Computer should exists"); Property prop = propBase as Property; Assert.IsNotNull(prop, "the prop Type=Computer should exists"); //----check the prop key PropertyKeyString propKeyString = prop.Key as PropertyKeyString; Assert.IsNotNull(propKeyString, "the prop key string Type should exists"); Assert.AreEqual("Name", propKeyString.Key, "the prop value should be Name"); //----check the prop value //PropertyValueString propValueValue = prop.Value as PropertyValueString; ValString propValueString = prop.Value as ValString; Assert.IsNotNull(propValueString, "the prop key string Typeshould exists"); Assert.AreEqual("Toshiba", propValueString.Value, "the prop value should be Toshiba"); }