-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added way to add creation code in rooms and instances #1901
Open
luizzeroxis
wants to merge
2
commits into
UnderminersTeam:master
Choose a base branch
from
luizzeroxis:add-creation-code
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,11 @@ public partial class UndertaleObjectReference : UserControl | |
new FrameworkPropertyMetadata(true, | ||
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); | ||
|
||
public static readonly DependencyProperty GameObjectProperty = | ||
DependencyProperty.Register("GameObject", typeof(UndertaleGameObject), | ||
typeof(UndertaleObjectReference), | ||
new PropertyMetadata(null)); | ||
|
||
public static DependencyProperty ObjectEventTypeProperty = | ||
DependencyProperty.Register("ObjectEventType", typeof(EventType), | ||
typeof(UndertaleObjectReference), | ||
|
@@ -79,6 +84,15 @@ public partial class UndertaleObjectReference : UserControl | |
new FrameworkPropertyMetadata((uint) 0, | ||
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); | ||
|
||
public static readonly DependencyProperty RoomProperty = | ||
DependencyProperty.Register("Room", typeof(UndertaleRoom), | ||
typeof(UndertaleObjectReference), | ||
new PropertyMetadata(null)); | ||
|
||
public static readonly DependencyProperty RoomGameObjectProperty = | ||
DependencyProperty.Register("RoomGameObject", typeof(UndertaleRoom.GameObject), | ||
typeof(UndertaleObjectReference), | ||
new PropertyMetadata(null)); | ||
|
||
public object ObjectReference | ||
{ | ||
|
@@ -98,6 +112,12 @@ public bool CanRemove | |
set { SetValue(ObjectTypeProperty, value); } | ||
} | ||
|
||
public UndertaleGameObject GameObject | ||
{ | ||
get { return (UndertaleGameObject)GetValue(GameObjectProperty); } | ||
set { SetValue(GameObjectProperty, value); } | ||
} | ||
|
||
public EventType ObjectEventType | ||
{ | ||
get { return (EventType)GetValue(ObjectEventTypeProperty); } | ||
|
@@ -110,6 +130,19 @@ public uint ObjectEventSubtype | |
set { SetValue(ObjectEventSubtypeProperty, value); } | ||
} | ||
|
||
public UndertaleRoom Room | ||
{ | ||
get { return (UndertaleRoom)GetValue(RoomProperty); } | ||
set { SetValue(RoomProperty, value); } | ||
} | ||
|
||
public UndertaleRoom.GameObject RoomGameObject | ||
{ | ||
get { return (UndertaleRoom.GameObject)GetValue(RoomGameObjectProperty); } | ||
set { SetValue(RoomGameObjectProperty, value); } | ||
} | ||
|
||
public bool IsPreCreate { get; set; } = false; | ||
|
||
public UndertaleObjectReference() | ||
{ | ||
|
@@ -149,22 +182,31 @@ private void Details_Click(object sender, RoutedEventArgs e) | |
{ | ||
if (ObjectReference is null) | ||
{ | ||
if (mainWindow.Selected is null) | ||
if (GameObject is not null) | ||
{ | ||
mainWindow.ShowError("Nothing currently selected! This is currently unsupported."); | ||
return; | ||
ObjectReference = GameObject.EventHandlerFor(ObjectEventType, ObjectEventSubtype, mainWindow.Data); | ||
} | ||
else if (mainWindow.Selected is UndertaleGameObject gameObject) | ||
else if (Room is not null) | ||
{ | ||
// Generate the code entry | ||
UndertaleCode code = gameObject.EventHandlerFor(ObjectEventType, ObjectEventSubtype, mainWindow.Data.Strings, mainWindow.Data.Code, mainWindow.Data.CodeLocals); | ||
|
||
ObjectReference = code; | ||
if (RoomGameObject is null) | ||
{ | ||
ObjectReference = CreationCode(mainWindow.Data, "gml_Room_" + Room.Name.Content + "_Create"); | ||
} | ||
else | ||
{ | ||
if (!IsPreCreate) | ||
{ | ||
ObjectReference = CreationCode(mainWindow.Data, "gml_RoomCC_" + Room.Name.Content + "_" + RoomGameObject.InstanceID.ToString() + "_Create"); | ||
} | ||
else | ||
{ | ||
ObjectReference = CreationCode(mainWindow.Data, "gml_RoomCC_" + Room.Name.Content + "_" + RoomGameObject.InstanceID.ToString() + "_PreCreate"); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
mainWindow.ShowError("Adding to non-objects is currently unsupported."); | ||
return; | ||
mainWindow.ShowError($"Adding not supported in this situation."); | ||
} | ||
} | ||
else | ||
|
@@ -173,6 +215,33 @@ private void Details_Click(object sender, RoutedEventArgs e) | |
} | ||
} | ||
|
||
// TODO move this to the models | ||
UndertaleCode CreationCode(UndertaleData data, string name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. function name feels too generic. This is adding a code entry, not creation code. |
||
{ | ||
var nameString = data.Strings.MakeString(name); | ||
|
||
var code = new UndertaleCode() | ||
{ | ||
LocalsCount = 1 | ||
}; | ||
code.Name = nameString; | ||
|
||
data.Code.Add(code); | ||
|
||
UndertaleCodeLocals.LocalVar argsLocal = new UndertaleCodeLocals.LocalVar(); | ||
argsLocal.Name = data.Strings.MakeString("arguments"); | ||
argsLocal.Index = 0; | ||
|
||
UndertaleCodeLocals locals = new UndertaleCodeLocals(); | ||
locals.Name = nameString; | ||
|
||
locals.Locals.Add(argsLocal); | ||
|
||
data.CodeLocals.Add(locals); | ||
|
||
return code; | ||
} | ||
|
||
private void Details_MouseDown(object sender, MouseButtonEventArgs e) | ||
{ | ||
if (ObjectReference is null) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please condense these