This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Cranium's profile picture

Retrieve 'friendly' peripheral names

Started by Cranium, 13 May 2015 - 03:08 AM
Cranium #1
Posted 13 May 2015 - 05:08 AM
I've been working on a peripheral info viewer for a little while now, and I'm currently to the point of beautifying the GUI and making things fit together so they look nice, but right now I'm stuck at the point of trying to get a readable peripheral name for anything I wrap.

Currently, I'm using peripheral.getName() and peripheral.getType() to return network location and peripheral types respectively, but there are many peripherals that don't have a very pretty name.
Case in point:


What I'd like to do is find out how I can return a good looking name for any peripheral I wrap, without having to define a name for each and every possible peripheral out there. Granted, I could do it with an aliases file, and match the peripheral.getType() name with a GUI friendly name that I define, but that's a lot of manual work to do.

So I was hoping if anyone had any great ideas on how I would go about getting that kind of information.
Bomb Bloke #2
Posted 13 May 2015 - 07:32 AM
So if I've got this right, what you're asking boils down to "how can I retrieve information that doesn't exist"?

Well, I suppose the answer to that would be "generate it on the fly"; it wouldn't be too hard to create sets of rules for discarding terms like "tile_" or "thermalexpansion_" from your strings. Putting aside the ongoing maintenance as new mods are created, and so on.

However, from a user's perspective, I'd want to see the full names at all times (abbreviations are of no practical value, after all, and at worst will even confuse people). If it were me, I'd leave them unaltered and simply allow users to drag the labels left/right in order to reveal their full contents. You could even make the things scroll back and forth automatically.

I'd also probably switch to hiding the middle of the strings in the left column, as opposed to the end, and maybe use a single character (such as a tilde) instead of three dots.. Eg, "tile_th~whatevs".
theoriginalbit #3
Posted 13 May 2015 - 07:40 AM
you could also request Boq (OpenPeripheral maintainer) to remove the very long and verbose names for peripherals, it's kinda ridiculous.
Cranium #4
Posted 13 May 2015 - 03:43 PM
So if I've got this right, what you're asking boils down to "how can I retrieve information that doesn't exist"?

Well, I suppose the answer to that would be "generate it on the fly"; it wouldn't be too hard to create sets of rules for discarding terms like "tile_" or "thermalexpansion_" from your strings. Putting aside the ongoing maintenance as new mods are created, and so on.

However, from a user's perspective, I'd want to see the full names at all times (abbreviations are of no practical value, after all, and at worst will even confuse people). If it were me, I'd leave them unaltered and simply allow users to drag the labels left/right in order to reveal their full contents. You could even make the things scroll back and forth automatically.

I'd also probably switch to hiding the middle of the strings in the left column, as opposed to the end, and maybe use a single character (such as a tilde) instead of three dots.. Eg, "tile_th~whatevs".
As far as abbreviations, I did have a plan to be able to click on an abbreviation in that right hand window, and have it pop up a small window with the full name(as long as it's not greater than 51 characters…geez).

I somewhat like the idea of 'generating on the fly', but I fear that it's too much of a generalization, and that there's a risk of snipping vital info from the name automatically.

you could also request Boq (OpenPeripheral maintainer) to remove the very long and verbose names for peripherals, it's kinda ridiculous.
In your opinion, do you think that's something he'd be interested in doing? I assume it would have to be with a different function added, like peripheral.getRealName(peripheral)

In any case, it's sounding more like I'd have to make an 'aliases' file where I can manually set the realname of the peripherals, or have the user define their own.
Edited on 13 May 2015 - 01:44 PM
Lyqyd #5
Posted 13 May 2015 - 05:41 PM
Since you want to display localized names, the best option is to set up a system to provide localized names from one or more files, so that the English localized names can be used, but those using different languages will also be able to use/create translation strings for their language.
Cranium #6
Posted 13 May 2015 - 06:05 PM
Since you want to display localized names, the best option is to set up a system to provide localized names from one or more files, so that the English localized names can be used, but those using different languages will also be able to use/create translation strings for their language.
That's actually not a bad idea. That puts it strongly in the court of "user defined aliases", so that people can put whatever they want into a file that I just retrieve every time and match with the network location(peripheral.getNames()). If the network location ever changes, then they'd have to redefine the name, which I'm retrieving as a label.

So I guess what I'll do is this:
  1. Search all peripherals using peripheral.getNames()
  2. Add all of the peripherals to a list, and each index would be the peripheral.getNames() result, with the type being defined as peripheral.getType(), and before a user names it, it will use the realname as defined by peripheral.getType()
  3. Once a user right-clicks on the name, they will be given the option to rename it to whatever they prefer, which will replace the alias.<name>.label as whatever they type in.
Seems about right to me.
Lyqyd #7
Posted 13 May 2015 - 06:47 PM
I'd suggest a user-defined alias file as well as a basic set of language translation files, in that case. Especially if you end up open-sourcing this, you may find that other users are willing to contribute translations, so having a set of files to base the names off of to begin with is a good idea. Then anything they want to rename goes into their user aliases file to override the translation file.
Dragon53535 #8
Posted 13 May 2015 - 08:42 PM
If you do setup an alias file, then you might want to also give the option for renaming the whole type of peripheral. Such as say they have 5 chests, by changing that name, they have 5 trunks now. If that's what you were thinking of doing, there's still the option of renaming specific peripherals attached. Say they have 2 different Big Reactor reactors, you can let them change their names to Safe Reactor, and Un-Safe Reactor, or whatever.
Cranium #9
Posted 13 May 2015 - 08:56 PM
If you do setup an alias file, then you might want to also give the option for renaming the whole type of peripheral. Such as say they have 5 chests, by changing that name, they have 5 trunks now. If that's what you were thinking of doing, there's still the option of renaming specific peripherals attached. Say they have 2 different Big Reactor reactors, you can let them change their names to Safe Reactor, and Un-Safe Reactor, or whatever.
That's actually the exact thing I was planning. Since the 'network location' (the name returned from peripheral.getNames()) won't change unless the network connection is physically broken/re-established, it's trivial to assign names to specific peripherals on a network. This is, of course assuming that it's using a wired network.
Bomb Bloke #10
Posted 14 May 2015 - 01:36 AM
So to be clear, you're planning on overriding peripheral.getNames() and peripheral.getType() so that they make use of your alias system?
Cranium #11
Posted 14 May 2015 - 02:42 AM
Just getType(), since peripheral.getNames() will return me the list I need to wrap the peripherals.