Skip to content

feat(#125): connect programming UI to robots#138

Open
strunk23 wants to merge 19 commits intomainfrom
feat/125/connect-programming-ui-to-robots
Open

feat(#125): connect programming UI to robots#138
strunk23 wants to merge 19 commits intomainfrom
feat/125/connect-programming-ui-to-robots

Conversation

@strunk23
Copy link
Copy Markdown
Contributor

closes #125

@strunk23 strunk23 marked this pull request as draft March 26, 2026 11:16
@strunk23 strunk23 marked this pull request as ready for review March 26, 2026 14:25
Copy link
Copy Markdown
Member

@PatrykPaluch PatrykPaluch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just locking cr. I will look later on this

[TextArea(10, 20)]
[SerializeField] private string code;

public string code;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about making it public like that. I think we needs to check if the robot is running to avoid mismatched "code in variable" and actually running code in engine

Comment on lines +67 to 75
public void StopTask()
{
StopAllCoroutines();
commandQueue.Clear();

cancellationTokenSource?.Cancel();
cancellationTokenSource?.Dispose();
cancellationTokenSource = null;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to double check this

catch (OperationCanceledException)
{
Debug.Log("[Programmable JsThread] Operation was cancelled");
Debug.LogError("Operation was cancelled");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is an Error or even a warning - in my opinion just info. Also, previous message was more descriptive

taskCompletedEvent = new ManualResetEvent(false);

debugI = staticDebugI++;
engineLogicInterfaces = GetComponents<IEngineLogic>();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think about moving this to startTask

Copy link
Copy Markdown
Collaborator

@Acu1000 Acu1000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bug occured when I first tried it:

Image

Steps to reproduce:

  1. Go to saves folder (you can do Debug.Log(Application.persistentDataPath))
  2. Delete JsFiles folder
  3. Start the game in the RobotAPI scene, interact with the robot to open the UI
  4. Create a new script (error happens regardless of the script's content)
  5. Click "Run"

@Acu1000
Copy link
Copy Markdown
Collaborator

Acu1000 commented Mar 27, 2026

I tried running a simple "while true: move forward, rotate 45deg" script and the robot does not seem to move in an octagonal path as expected, but I don't believe this is in the scope of this PR

Copy link
Copy Markdown
Member

@PatrykPaluch PatrykPaluch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And i created #141 so wait for it with the PlayerCamera/PlayerController changes. I will try to close #141 asap (i will assign task to me when i start working on it), but if you are bored and i'm still not assigned to this issue, then feel free to take over it 😛

Comment on lines +32 to +42
public void RunActiveFile()
{
if (IsUiInteractionInvalid("Found no files to execute")) { return; }
fileManager.RunActiveFile();
}

public void StopActiveFile()
{
if (IsUiInteractionInvalid("Found no files to stop")) { return; }
fileManager.StopActiveFile();
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run/Stop in Canvas should be replace by one button that will change to "Run"/"Stop" depending on running state. Additionally i would add running indicator - just label "running" maybe with timer but timer is not necessary.

keep in mind that program can be stopped by other sources or can finish execution by it self. So you probably need to add some event listeners to Programmable for task start and end.

@@ -11,7 +11,8 @@ namespace Cosmobot
{
public class ProgrammingUi : MonoBehaviour
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Console is not robot specific. When you open robot programming ui, player should see logs for that robot

public class RobotUiInteractionHandler : MonoBehaviour, IInteractable
{
[SerializeField]
private ProgrammingUiManager programmingUiManager;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think ProgramminUiManager should be SingletonSystem and accessible by Instance static variable (just implement SingletonSystem and replace Awake/Start with override void SystemAwake

Comment on lines +7 to +8
[SerializeField]
private PlayerCamera playerCamera;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im starting to think about implementing GameManager with all that player stuff before continuing with this PR

Copy link
Copy Markdown
Collaborator

@Acu1000 Acu1000 Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. We'll consider adding it once the current PRs are merged. I believe we can merge this one without it though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I stated in comment to this PR, we should wait until GameManager is merged. This is already an issue, and there are already two PR that make this issue more time consuming. For now GameManager is only new class and one change in Construction script. Implementing GameManager first will be easier and faster, than implementing it afterwards


private void OnEnable()
{
RobotLogger.AddAllLogEventHandler(logManager.CreateLog);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProgrammingUiLogManager is an MonoBehaviour script, so it should register event handler by its own

}

public void CreateLog(long time, LogLevel level, string message)
public void CreateLog(ProgrammableData data, LogEntry logEntry)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should check if it is necessary to instantiate new ui elements. These are still gameobject and can impact performance. Im not sure how exacly Canvas remeshing/rendering works, but im would prefer not to create new game objects if UI is not visible to user.

You can also just unsubscribe event when UI is closed and subscribe again on OpenUI.

To retrieve all logs that ware logged before opening UI you can use RobotLogger.TryGetRobotLogs function. This will also help whit changing view between robots.

Logs are dynamic so i think its good place for pooling. Create pool of those ProgrammingUiLogEntry GameObjects with some max size (eg. 200). If new logs appear after using up the pool, just reuse the oldest object. Yes, this will limit number of logs visible to player, but its better than spamming and deleting new GameObject indefinitely. Sooner or later we will use pooling so i think its good time and place to implement it. I think i have some universal pooling script i created for other project, DM me and i will send you script.

Comment on lines +10 to +13
public void CreateNewFile()
{
fileManager.CreateNewFile("file" + fileManager.GetFileCount() + ".js"); // TEMP
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if possible this should ask user for file name. Maybe rename button (just "R" for now to keep it small, we will later add icons).

If this is too much coding for this task then ignore this comment, we will probably rewrite entire UI later to UI Elements, so try not to work on Canvas specific stuff too much

Copy link
Copy Markdown
Collaborator

@Acu1000 Acu1000 Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manual setting of file names is a job for a separate task, no need to worry about it in this PR

Comment on lines +27 to +30
public void CloseUI()
{
ChangeUiState(false);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if possible add ESC to close UI


private Programmable robot;

public string Prompt { get; private set; } = "Press 'E' to interact";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Press 'E' to program the robot"
or
"Press 'E' to open programming window"
or something like that

@PatrykPaluch
Copy link
Copy Markdown
Member

PatrykPaluch commented Apr 1, 2026

#143 merged

You can now pull main and replace all "manual" player references to GameManager (for now you need to add one GameManager to the scene, this will be fixed with #137, but that will be my job, if you marge this PR faster than i #137 😄)

@PatrykPaluch
Copy link
Copy Markdown
Member

#137 was merged today, so now you will have conflicts with scenes (as you can see in merge window below). So:

  • Add working example to 0_MainTestScene (keep it simple)
  • You can keep your testing scene (RobotAPI if i remember correctly) with you feature isolated
  • If Player prefab needs some component added, a reference to external GameObject, put that GameObject in PlayerBase prefab

also remember about GameManager from my previous commend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Connect Programming UI to Robots

3 participants