Skip to content

Commit

Permalink
Console now runs on the main menu
Browse files Browse the repository at this point in the history
  • Loading branch information
LazyWizard committed Oct 5, 2024
1 parent 9b4a9e7 commit b43f781
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
14 changes: 13 additions & 1 deletion src/main/java/org/lazywizard/console/BaseCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ enum CommandContext
*
* @since 2.0
*/
COMBAT_SIMULATION;
COMBAT_SIMULATION,
/**
* Command was entered on the main menu.
*/
// TODO: Add @since whenever I get around to untangling the version number mess
MAIN_MENU;

/**
* Returns whether this context is on the combat map.
Expand Down Expand Up @@ -127,6 +132,13 @@ public boolean isInMarket()
return (this == CAMPAIGN_MARKET);
}

/**
* Returns whether the player is viewing the main menu.
*
* @return {@code true} if the player is at the main menu, {@code false} otherwise.
*/
public boolean isInMainMenu() { return (this == MAIN_MENU); }

/**
* Returns whether the player is in campaign mode, including in campaign battles (even refit simulation
* battles).
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/lazywizard/console/CommandStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ else if (context.isInCombat())
return tags.contains("combat") || (!tags.contains("campaign") && !tags.contains("market"));
}

return true;
return !context.isInMainMenu();
}

/**
Expand Down
29 changes: 15 additions & 14 deletions src/main/java/org/lazywizard/console/commands/SourceOf.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.lazywizard.console.commands;

import java.util.Collections;
import java.util.List;
import org.lazywizard.console.BaseCommand;
import org.lazywizard.console.CommandStore;
import org.lazywizard.console.CommandStore.StoredCommand;
import org.lazywizard.console.Console;

// TODO: Extend to cover ships/weapons/modspecs/commodities/etc
import java.util.Collections;
import java.util.List;

public class SourceOf implements BaseCommand
{
@Override
Expand All @@ -18,29 +18,30 @@ public CommandResult runCommand(String args, CommandContext context)
return CommandResult.BAD_SYNTAX;
}

if ("all".equalsIgnoreCase(args))
if ("all".equalsIgnoreCase(args) || "commands".equalsIgnoreCase(args))
{
Console.showMessage("Loaded commands come from the following mods:");
List<String> allCommands = CommandStore.getLoadedCommands();
final List<String> allCommands = CommandStore.getLoadedCommands();
Collections.sort(allCommands, String.CASE_INSENSITIVE_ORDER);
for (String tmp : allCommands)
{
StoredCommand command = CommandStore.retrieveCommand(tmp);
Console.showMessage(" - "+ tmp + ": " + command.getSource());
final StoredCommand command = CommandStore.retrieveCommand(tmp);
Console.showMessage(" - " + tmp + ": " + command.getSource());
}

return CommandResult.SUCCESS;
}

StoredCommand command = CommandStore.retrieveCommand(args);
if (command == null)
final StoredCommand command = CommandStore.retrieveCommand(args);
if (command != null)
{
Console.showMessage("No command with the name '" + args + "' was found!");
return CommandResult.ERROR;
Console.showMessage("Command '" + args + "' is from the following mod:\n"
+ " - " + command.getSource());
return CommandResult.SUCCESS;
}

Console.showMessage("Command '" + args + "' is from the following mod:\n"
+ " - " + command.getSource());
return CommandResult.SUCCESS;
// TODO: Extend to cover ships/weapons/modspecs/commodities/classes/files/etc
Console.showMessage("No command with the name '" + args + "' was found!");
return CommandResult.ERROR;
}
}
3 changes: 2 additions & 1 deletion src/main/kotlin/org/lazywizard/console/ConsolePlugins.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ internal class ConsoleCombatListener : BaseEveryFrameCombatPlugin(), ConsoleList
context = when {
engine.isSimulation -> CommandContext.COMBAT_SIMULATION
engine.isInCampaign -> CommandContext.COMBAT_CAMPAIGN
else -> CommandContext.COMBAT_MISSION
engine.missionId != null -> CommandContext.COMBAT_MISSION
else -> CommandContext.MAIN_MENU
}

engine.customData["consolePlugin"] = this
Expand Down

0 comments on commit b43f781

Please sign in to comment.