use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class CoreCommands method editScreen.
/**
* Opens the NUI editor for a ui screen
*
* @param uri String containing ui screen name
* @return String containing final message
*/
@Command(shortDescription = "Opens the NUI editor for a ui screen", requiredPermission = PermissionManager.NO_PERMISSION)
public String editScreen(@CommandParam(value = "uri", suggester = ScreenSuggester.class) String uri) {
if (!nuiEditorSystem.isEditorActive()) {
nuiEditorSystem.toggleEditor();
}
Set<ResourceUrn> urns = assetManager.resolve(uri, UIElement.class);
switch(urns.size()) {
case 0:
return String.format("No asset found for screen '%s'", uri);
case 1:
ResourceUrn urn = urns.iterator().next();
((NUIEditorScreen) nuiManager.getScreen(NUIEditorScreen.ASSET_URI)).selectAsset(urn);
return "Success";
default:
return String.format("Multiple matches for screen '%s': {%s}", uri, Arrays.toString(urns.toArray()));
}
}
use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class CoreCommands method findBlockMatches.
/**
* List blocks that match searched string
*
* @param searchLowercase searched string
* @return List of blocks that match searched string
*/
private List<String> findBlockMatches(String searchLowercase) {
ResourceUrn curUrn;
List<String> outputList = new ArrayList<>();
for (ResourceUrn urn : assetManager.getAvailableAssets(BlockFamilyDefinition.class)) {
// Current urn for logging purposes to find the broken urn
curUrn = urn;
try {
Optional<BlockFamilyDefinition> def = assetManager.getAsset(urn, BlockFamilyDefinition.class);
if (def.isPresent() && def.get().isLoadable() && matchesSearch(searchLowercase, def.get())) {
outputList.add(new BlockUri(def.get().getUrn()).toString());
}
} catch (Exception e) {
// If a prefab is broken , it will throw an exception
console.addMessage("Note : Search may not return results if invalid assets are present");
console.addMessage("Error parsing : " + curUrn.toString());
console.addMessage(e.toString());
}
}
return outputList;
}
use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class CoreCommands method editSkin.
/**
* Opens the NUI editor for a ui skin
*
* @param uri String containing name of ui skin
* @return String containing final message
*/
@Command(shortDescription = "Opens the NUI editor for a ui skin", requiredPermission = PermissionManager.NO_PERMISSION)
public String editSkin(@CommandParam(value = "uri", suggester = SkinSuggester.class) String uri) {
if (!nuiSkinEditorSystem.isEditorActive()) {
nuiSkinEditorSystem.toggleEditor();
}
Set<ResourceUrn> urns = assetManager.resolve(uri, UISkinAsset.class);
switch(urns.size()) {
case 0:
return String.format("No asset found for screen '%s'", uri);
case 1:
ResourceUrn urn = urns.iterator().next();
((NUISkinEditorScreen) nuiManager.getScreen(NUISkinEditorScreen.ASSET_URI)).selectAsset(urn);
return "Success";
default:
return String.format("Multiple matches for screen '%s': {%s}", uri, Arrays.toString(urns.toArray()));
}
}
use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class AssetSuggester method suggest.
@Override
public Set<String> suggest(EntityRef sender, Object... resolvedParameters) {
Map<String, Set<ResourceUrn>> resourceMap = Maps.newHashMap();
Set<String> suggestions = Sets.newHashSet();
for (ResourceUrn resolvedParameter : assetManager.getAvailableAssets(assetType)) {
String resourceName = resolvedParameter.getResourceName().toString();
if (!resourceMap.containsKey(resourceName)) {
resourceMap.put(resourceName, Sets.newHashSet());
}
resourceMap.get(resourceName).add(resolvedParameter);
}
for (String key : resourceMap.keySet()) {
Set<ResourceUrn> set = resourceMap.get(key);
if (set.size() == 1) {
suggestions.add(set.iterator().next().getResourceName().toString());
} else {
for (ResourceUrn resourceUrn : set) {
suggestions.add(resourceUrn.toString());
}
}
}
return suggestions;
}
use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class MovementDebugCommands method restoreSpeed.
@Command(shortDescription = "Restore normal speed values", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String restoreSpeed(@Sender EntityRef client) {
ClientComponent clientComp = client.getComponent(ClientComponent.class);
Optional<Prefab> prefab = Assets.get(new ResourceUrn("engine:player"), Prefab.class);
CharacterMovementComponent moveDefault = prefab.get().getComponent(CharacterMovementComponent.class);
CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class);
if (move != null && moveDefault != null) {
move.jumpSpeed = moveDefault.jumpSpeed;
move.speedMultiplier = moveDefault.speedMultiplier;
move.runFactor = moveDefault.runFactor;
move.stepHeight = moveDefault.stepHeight;
move.slopeFactor = moveDefault.slopeFactor;
move.distanceBetweenFootsteps = moveDefault.distanceBetweenFootsteps;
clientComp.character.saveComponent(move);
}
return "Normal speed values restored";
}
Aggregations