public void OnVariableSet(DreamObject dreamObject, string varName, DreamValue value, DreamValue oldValue) { ParentType?.OnVariableSet(dreamObject, varName, value, oldValue); switch (varName) { case "name": { value.TryGetValueAsString(out string name); EntityUid entity = _atomManager.GetAtomEntity(dreamObject); if (!_entityManager.TryGetComponent(entity, out MetaDataComponent metaData)) { break; } metaData.EntityName = name; break; } case "desc": { value.TryGetValueAsString(out string desc); EntityUid entity = _atomManager.GetAtomEntity(dreamObject); if (!_entityManager.TryGetComponent(entity, out MetaDataComponent metaData)) { break; } metaData.EntityDescription = desc; break; } case "icon": _atomManager.UpdateAppearance(dreamObject, appearance => { if (value.TryGetValueAsDreamResource(out DreamResource resource)) { appearance.Icon = resource.ResourcePath; } else if (value.TryGetValueAsDreamObjectOfType(DreamPath.Icon, out DreamObject iconObject)) { DreamMetaObjectIcon.DreamIconObject icon = DreamMetaObjectIcon.ObjectToDreamIcon[iconObject]; appearance.Icon = icon.Icon; if (icon.State != null) { appearance.IconState = icon.State; } //TODO: If a dir is set, the icon will stay that direction. Likely will be a part of "icon generation" when that's implemented. if (icon.Direction != null) { appearance.Direction = icon.Direction.Value; } } else { appearance.Icon = null; } });
public DreamValue OperatorMultiply(DreamValue a, DreamValue b) { if (!a.TryGetValueAsDreamObjectOfType(DreamPath.Matrix, out DreamObject left)) { throw new ArgumentException($"Invalid matrix {a}"); } left.GetVariable("a").TryGetValueAsFloat(out float lA); left.GetVariable("b").TryGetValueAsFloat(out float lB); left.GetVariable("c").TryGetValueAsFloat(out float lC); left.GetVariable("d").TryGetValueAsFloat(out float lD); left.GetVariable("e").TryGetValueAsFloat(out float lE); left.GetVariable("f").TryGetValueAsFloat(out float lF); if (b.TryGetValueAsFloat(out float bFloat)) { DreamObject output = _dreamManager.ObjectTree.CreateObject(DreamPath.Matrix); output.SetVariable("a", new(lA * bFloat)); output.SetVariable("b", new(lB * bFloat)); output.SetVariable("c", new(lC * bFloat)); output.SetVariable("d", new(lD * bFloat)); output.SetVariable("e", new(lE * bFloat)); output.SetVariable("f", new(lF * bFloat)); return(new(output)); } else if (b.TryGetValueAsDreamObjectOfType(DreamPath.Matrix, out DreamObject right)) { right.GetVariable("a").TryGetValueAsFloat(out float rA); right.GetVariable("b").TryGetValueAsFloat(out float rB); right.GetVariable("c").TryGetValueAsFloat(out float rC); right.GetVariable("d").TryGetValueAsFloat(out float rD); right.GetVariable("e").TryGetValueAsFloat(out float rE); right.GetVariable("f").TryGetValueAsFloat(out float rF); DreamObject output = _dreamManager.ObjectTree.CreateObject(DreamPath.Matrix); output.SetVariable("a", new(rA * lA + rD * lB)); output.SetVariable("b", new(rB * lA + rE * lB)); output.SetVariable("c", new(rC * lA + rF * lB + lC)); output.SetVariable("d", new(rA * lD + rD * lE)); output.SetVariable("e", new(rB * lD + rE * lE)); output.SetVariable("f", new(rC * lD + rF * lE + lF)); return(new(output)); } if (ParentType == null) { throw new InvalidOperationException($"Multiplication cannot be done between {a} and {b}"); } return(ParentType.OperatorMultiply(a, b)); }
public override void OnObjectCreated(DreamObject dreamObject, DreamProcArguments creationArguments) { _dreamManager.WorldContentsList.AddValue(new DreamValue(dreamObject)); DreamValue locArgument = creationArguments.GetArgument(0, "loc"); if (locArgument.TryGetValueAsDreamObjectOfType(DreamPath.Atom, out _)) { dreamObject.SetVariable("loc", locArgument); //loc is set before /New() is ever called } else if (creationArguments.ArgumentCount == 0) { creationArguments.OrderedArguments.Add(DreamValue.Null); //First argument is loc, which is null } base.OnObjectCreated(dreamObject, creationArguments); }
public override void OnVariableSet(DreamObject dreamObject, string variableName, DreamValue variableValue, DreamValue oldVariableValue) { base.OnVariableSet(dreamObject, variableName, variableValue, oldVariableValue); switch (variableName) { case "x": case "y": case "z": { int x = (variableName == "x") ? variableValue.GetValueAsInteger() : dreamObject.GetVariable("x").GetValueAsInteger(); int y = (variableName == "y") ? variableValue.GetValueAsInteger() : dreamObject.GetVariable("y").GetValueAsInteger(); int z = (variableName == "z") ? variableValue.GetValueAsInteger() : dreamObject.GetVariable("z").GetValueAsInteger(); DreamObject newLocation = _dreamMapManager.GetTurf(x, y, z); dreamObject.SetVariable("loc", new DreamValue(newLocation)); break; } case "loc": { EntityUid entity = _atomManager.GetAtomEntity(dreamObject); if (!_entityManager.TryGetComponent <TransformComponent>(entity, out var transform)) { return; } if (variableValue.TryGetValueAsDreamObjectOfType(DreamPath.Atom, out DreamObject loc)) { EntityUid locEntity = _atomManager.GetAtomEntity(loc); transform.AttachParent(locEntity); transform.LocalPosition = Vector2.Zero; } else { transform.AttachParent(_mapManager.GetMapEntityId(MapId.Nullspace)); } break; } case "screen_loc": UpdateScreenLocation(dreamObject, variableValue); break; } }
public override DreamValue OperatorMultiply(DreamValue a, DreamValue b) { DreamObject left = a.GetValueAsDreamObjectOfType(DreamPath.Matrix); float lA = left.GetVariable("a").GetValueAsFloat(); float lB = left.GetVariable("b").GetValueAsFloat(); float lC = left.GetVariable("c").GetValueAsFloat(); float lD = left.GetVariable("d").GetValueAsFloat(); float lE = left.GetVariable("e").GetValueAsFloat(); float lF = left.GetVariable("f").GetValueAsFloat(); if (b.TryGetValueAsFloat(out float bFloat)) { DreamObject output = _dreamManager.ObjectTree.CreateObject(DreamPath.Matrix); output.SetVariable("a", new(lA * bFloat)); output.SetVariable("b", new(lB * bFloat)); output.SetVariable("c", new(lC * bFloat)); output.SetVariable("d", new(lD * bFloat)); output.SetVariable("e", new(lE * bFloat)); output.SetVariable("f", new(lF * bFloat)); return(new(output)); } else if (b.TryGetValueAsDreamObjectOfType(DreamPath.Matrix, out DreamObject right)) { float rA = right.GetVariable("a").GetValueAsFloat(); float rB = right.GetVariable("b").GetValueAsFloat(); float rC = right.GetVariable("c").GetValueAsFloat(); float rD = right.GetVariable("d").GetValueAsFloat(); float rE = right.GetVariable("e").GetValueAsFloat(); float rF = right.GetVariable("f").GetValueAsFloat(); DreamObject output = _dreamManager.ObjectTree.CreateObject(DreamPath.Matrix); output.SetVariable("a", new(rA * lA + rD * lB)); output.SetVariable("b", new(rB * lA + rE * lB)); output.SetVariable("c", new(rC * lA + rF * lB + lC)); output.SetVariable("d", new(rA * lD + rD * lE)); output.SetVariable("e", new(rB * lD + rE * lE)); output.SetVariable("f", new(rC * lD + rF * lE + lF)); return(new(output)); } return(base.OperatorMultiply(a, b)); }
public override void OnVariableSet(DreamObject dreamObject, string variableName, DreamValue variableValue, DreamValue oldVariableValue) { base.OnVariableSet(dreamObject, variableName, variableValue, oldVariableValue); if (variableName == "loc") { if (variableValue.TryGetValueAsDreamObjectOfType(DreamPath.Turf, out DreamObject replacedTurf)) { DreamList contents = replacedTurf.GetVariable("contents").GetValueAsDreamList(); while (contents.GetLength() > 0) //Transfer all the old turf's contents { contents.GetValues()[0].GetValueAsDreamObjectOfType(DreamPath.Atom).SetVariable("loc", new DreamValue(dreamObject)); } int x = replacedTurf.GetVariable("x").GetValueAsInteger(); int y = replacedTurf.GetVariable("y").GetValueAsInteger(); int z = replacedTurf.GetVariable("z").GetValueAsInteger(); Program.DreamMap.SetTurf(x, y, z, dreamObject); } } }
public void OnVariableSet(DreamObject dreamObject, string varName, DreamValue value, DreamValue oldValue) { ParentType?.OnVariableSet(dreamObject, varName, value, oldValue); if (varName == "loc") { if (value.TryGetValueAsDreamObjectOfType(DreamPath.Turf, out DreamObject replacedTurf)) { //Transfer all the old turf's contents DreamList contents = replacedTurf.GetVariable("contents").GetValueAsDreamList(); foreach (DreamValue child in contents.GetValues()) { child.GetValueAsDreamObjectOfType(DreamPath.Movable).SetVariable("loc", new DreamValue(dreamObject)); } int x = replacedTurf.GetVariable("x").GetValueAsInteger(); int y = replacedTurf.GetVariable("y").GetValueAsInteger(); int z = replacedTurf.GetVariable("z").GetValueAsInteger(); _dreamMapManager.SetTurf(x, y, z, dreamObject); } } }