Starsector API
Loading...
Searching...
No Matches
DumpMemory.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.rulecmd;
2
3import java.awt.Color;
4import java.util.ArrayList;
5import java.util.Collections;
6import java.util.List;
7import java.util.Map;
8
9import com.fs.starfarer.api.Global;
10import com.fs.starfarer.api.campaign.InteractionDialogAPI;
11import com.fs.starfarer.api.campaign.rules.MemKeys;
12import com.fs.starfarer.api.campaign.rules.MemoryAPI;
13import com.fs.starfarer.api.impl.campaign.DebugFlags;
14import com.fs.starfarer.api.util.Misc;
15import com.fs.starfarer.api.util.Misc.Token;
16
24public class DumpMemory extends BaseCommandPlugin {
25
26 public static final String OPTION_ID = "DumpMemory.option_dump_memory";
27
28 public boolean execute(String ruleId, InteractionDialogAPI dialog, List<Token> params, Map<String, MemoryAPI> memoryMap) {
29 //if (dialog == null) return false;
30
31 //System.out.println("Transponder: " + dialog.getInteractionTarget().isTransponderOn());
32
33 List<String> memKeys = new ArrayList<String>(memoryMap.keySet());
34 Collections.sort(memKeys);
35 memKeys.remove(MemKeys.LOCAL);
36 memKeys.add(MemKeys.LOCAL);
37
38 Color HIGHLIGHT_COLOR = Global.getSettings().getColor("buttonShortcut");
39 Color GRAY_COLOR = new Color(100,100,100);
40
41
42 for (String memKey : memKeys) {
43 String text = "";
44 MemoryAPI memory = memoryMap.get(memKey);
45 //text += memKey.toUpperCase() + "\n";
46 List<String> keys = new ArrayList<String>(memory.getKeys());
47 Collections.sort(keys);
48
49 List<Color> highlightColors = new ArrayList<Color>();
50 List<String> highlightList = new ArrayList<String>();
51 for (String key : keys) {
52 Object value = memory.get(key);
53
54 String varName = "$" + memKey + ".";
55 if (memKey.equals(MemKeys.LOCAL)) {
56 varName = "$";
57 }
58 if (key.startsWith("$")) {
59 varName += key.substring(1);
60 //highlightList.add(key.substring(1));
61 } else {
62 varName += key;
63 //highlightList.add(key);
64 }
65
66 if (varName.length() > 35) {
67 varName = varName.substring(0, 35) + "...";
68 }
69
70 highlightColors.add(HIGHLIGHT_COLOR);
71 highlightList.add(varName);
72
73 text += varName;
74 if (value instanceof Boolean || value instanceof String || value instanceof Float || value instanceof Integer || value instanceof Long) {
75 text += " = " + value.toString();
76 } else if (value != null) {
77 text += " = " + value.getClass().getSimpleName() + "@" + value.hashCode();
78 } else {
79 text += " = " + "null";
80 }
81 float expire = memory.getExpire(key);
82 if (expire >= 0) {
83 String eText = "(e=" + (float)((int)(expire * 10)/10f) + ")";
84 if (expire == 0) {
85 eText = "(e=0)";
86 }
87 highlightColors.add(GRAY_COLOR);
88 highlightList.add(eText);
89 text += " " + eText;
90 }
91 text += "\n";
92 }
93 if (dialog != null) {
94 //dialog.getTextPanel().setFontSmallInsignia();
95 dialog.getTextPanel().addParagraph(text);
96 dialog.getTextPanel().setHighlightColorsInLastPara(highlightColors.toArray(new Color[0]));
97 dialog.getTextPanel().highlightInLastPara(highlightList.toArray(new String [0]));
98 //dialog.getTextPanel().setFontInsignia();
99 } else {
101 System.out.println(text);
102 }
103 }
104 //dialog.getTextPanel().highlightInLastPara(HIGHLIGHT_COLOR, highlightList.toArray(new String [0]));
105 }
106
107 return true;
108 }
109
110 public static void addOption(InteractionDialogAPI dialog) {
111 dialog.getOptionPanel().addOption(">> (dev) dump memory", DumpMemory.OPTION_ID, Misc.getGrayColor(), null);
112 }
113}
114
115
116
117
118
static SettingsAPI getSettings()
Definition Global.java:51
static void addOption(InteractionDialogAPI dialog)
boolean execute(String ruleId, InteractionDialogAPI dialog, List< Token > params, Map< String, MemoryAPI > memoryMap)