Skip to content

Commit

Permalink
Add compiler support for set src in range() and orange()
Browse files Browse the repository at this point in the history
These were undocumented values.

Also made `set src in world/usr` implicitly convert into `set src = world/usr.contents`
  • Loading branch information
wixoaGit committed Feb 10, 2024
1 parent 28a5b71 commit e3655a5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions DMCompiler/DM/VerbSrc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
public enum VerbSrc {
View,
OView,
Range,
ORange,
World,
WorldContents,
Usr,
Expand Down
8 changes: 6 additions & 2 deletions DMCompiler/DM/Visitors/DMProcBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void ProcessStatementSet(DMASTProcStatementSet statementSet) {
// TODO: Would be much better if the parser was just more strict with the expression
switch (statementSet.Value) {
case DMASTIdentifier {Identifier: "usr"}:
_proc.VerbSrc = VerbSrc.Usr;
_proc.VerbSrc = statementSet.WasInKeyword ? VerbSrc.UsrContents : VerbSrc.Usr;
break;
case DMASTDereference {Expression: DMASTIdentifier{Identifier: "usr"}, Operations: var operations}:
if (operations is not [DMASTDereference.FieldOperation {Identifier: var deref}])
Expand All @@ -214,7 +214,7 @@ public void ProcessStatementSet(DMASTProcStatementSet statementSet) {

break;
case DMASTIdentifier {Identifier: "world"}:
_proc.VerbSrc = VerbSrc.World;
_proc.VerbSrc = statementSet.WasInKeyword ? VerbSrc.WorldContents : VerbSrc.World;
DMCompiler.UnimplementedWarning(statementSet.Location,
"'set src = world' is unimplemented");
break;
Expand All @@ -229,6 +229,10 @@ public void ProcessStatementSet(DMASTProcStatementSet statementSet) {
case DMASTProcCall {Callable: DMASTCallableProcIdentifier {Identifier: { } viewType and ("view" or "oview")}}:
_proc.VerbSrc = viewType == "view" ? VerbSrc.View : VerbSrc.OView; // TODO: Ranges
break;
// range() and orange() are undocumented, but they work
case DMASTProcCall {Callable: DMASTCallableProcIdentifier {Identifier: { } viewType and ("range" or "orange")}}:
_proc.VerbSrc = viewType == "range" ? VerbSrc.Range : VerbSrc.ORange; // TODO: Ranges
break;
default:
DMCompiler.Emit(WarningCode.BadExpression, statementSet.Value.Location, "Invalid verb src");
break;
Expand Down
4 changes: 3 additions & 1 deletion OpenDreamRuntime/ServerVerbSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ public void RegisterVerb(DreamProc verb) {
}

VerbAccessibility? verbAccessibility = verb.VerbSrc switch {
VerbSrc.View => VerbAccessibility.View, // TODO: Ranges on the view() types
VerbSrc.View => VerbAccessibility.View, // TODO: Ranges on the view()/range() types
VerbSrc.OView => VerbAccessibility.OView,
VerbSrc.Range => VerbAccessibility.Range,
VerbSrc.ORange => VerbAccessibility.ORange,
VerbSrc.World => VerbAccessibility.WorldContents,
VerbSrc.WorldContents => VerbAccessibility.WorldContents,
VerbSrc.Usr or VerbSrc.UsrContents => VerbAccessibility.UsrContents,
Expand Down
2 changes: 2 additions & 0 deletions OpenDreamShared/Dream/VerbSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public struct VerbArg {
public enum VerbAccessibility : byte {
View,
OView,
Range,
ORange,
WorldContents,
UsrContents,
Usr,
Expand Down

0 comments on commit e3655a5

Please sign in to comment.