Skip to content

Commit

Permalink
#116 Converted 'Adding Object' to WorldObjectInsertion usage
Browse files Browse the repository at this point in the history
  • Loading branch information
willneedit committed Jun 22, 2024
1 parent aeab93a commit 0c9f73c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Assets/Arteranos/Scripts/Services/IPFSServiceImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ IEnumerator StartupIPFSExeCoroutine()
yield return new WaitForSeconds(2);
}

TransitionProgressStatic.Instance.OnProgressChanged(0.20f, "Starting IPFS daemon");
TransitionProgressStatic.Instance?.OnProgressChanged(0.20f, "Starting IPFS daemon");

TryStartIPFS();

Expand Down
4 changes: 2 additions & 2 deletions Assets/Arteranos/WorldEdit/UI/NewObjectPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ namespace Arteranos.WorldEdit
{
public class NewObjectPanel : UIBehaviour
{
public event Action<WorldObject> OnAddingNewObject;
public event Action<WorldObjectInsertion> OnAddingNewObject;

protected void AddingNewObject(WorldObject obj)
protected void AddingNewObject(WorldObjectInsertion obj)
=> OnAddingNewObject?.Invoke(obj);
}
}
6 changes: 5 additions & 1 deletion Assets/Arteranos/WorldEdit/UI/Panel_Primitives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ private void OnTileClicked(int index)
primitive = primitives[index].prim
};

AddingNewObject(new WorldObject(newWOP, primitives[index].name));
AddingNewObject(new()
{
asset = newWOP,
name = primitives[index].name
});
}
}
}
6 changes: 5 additions & 1 deletion Assets/Arteranos/WorldEdit/UI/Panel_glTF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ private void OnTileClicked(int index)
glTFCid = GLTFEntries[index].IPFSPath
};

AddingNewObject(new WorldObject(newWOglTF, GLTFEntries[index].FriendlyName));
AddingNewObject(new()
{
asset = newWOglTF,
name = GLTFEntries[index].FriendlyName
});
}
}
}
2 changes: 1 addition & 1 deletion Assets/Arteranos/WorldEdit/UI/WorldEditorUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private void SwitchToAdder()
}
}

private void Panel_OnAddingNewObject(WorldObject obj)
private void Panel_OnAddingNewObject(WorldObjectInsertion obj)
{
SwitchToList();
WorldObjectList.OnAddingWorldObject(obj);
Expand Down
32 changes: 29 additions & 3 deletions Assets/Arteranos/WorldEdit/UI/WorldObjectList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,38 @@ private void RequestToAdd(string obj)
OnWantsToAddItem?.Invoke();
}

public void OnAddingWorldObject(WorldObject wo)
public void OnAddingWorldObject(WorldObjectInsertion woi)
{
IEnumerator AdderCoroutine()
{
yield return wo.Instantiate(CurrentRoot.transform, editorData: EditorData);

// Put the new object into the greater picture.
// Path in its hierarchy....
Transform current = CurrentRoot.transform;
woi.path = new();
while (current.TryGetComponent(out WorldObjectComponent woc))
{
woi.path.Add(woc.Id);
current = current.parent;
}
woi.path.Reverse();

woi.components = new()
{
// ...the default transform...
new WOCTransform()
{
position = Vector3.zero,
rotation = Quaternion.identity,
scale = Vector3.one
},

// ...and color.
new WOCColor() { color = Color.white }
};

// TODO Not to directly adding, but to send the packet to the server,
// and let the UI been notified by the network manager for the server's response.
yield return woi.Apply();
RequestUpdateList();

// Finished with adding.
Expand Down

0 comments on commit 0c9f73c

Please sign in to comment.