Skip to content

Commit

Permalink
Merge pull request #16 from Rockdtben/ExtractObjectTreeItem
Browse files Browse the repository at this point in the history
Extracts out Item from ObjectTree
  • Loading branch information
Rockdtben authored Jan 30, 2018
2 parents 6cf70bd + ec4d981 commit cee33ba
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 193 deletions.
7 changes: 4 additions & 3 deletions src/main/java/com/github/monster860/fastdmm/FastDMM.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.github.monster860.fastdmm.objtree.ModifiedType;
import com.github.monster860.fastdmm.objtree.ObjInstance;
import com.github.monster860.fastdmm.objtree.ObjectTree;
import com.github.monster860.fastdmm.objtree.ObjectTreeItem;
import com.github.monster860.fastdmm.objtree.ObjectTreeParser;

import org.lwjgl.LWJGLException;
Expand Down Expand Up @@ -101,7 +102,7 @@ public class FastDMM extends JFrame implements ActionListener, TreeSelectionList
SortedSet<String> filters;
public ObjectTree objTree;

public ObjectTree.Item selectedObject;
public ObjectTreeItem selectedObject;
public ObjInstance selectedInstance;

private boolean hasLoadedImageThisFrame = false;
Expand Down Expand Up @@ -371,8 +372,8 @@ public void stateChanged(ChangeEvent e) {

@Override
public void valueChanged(TreeSelectionEvent arg0) {
if (arg0.getPath().getLastPathComponent() instanceof ObjectTree.Item) {
selectedObject = (ObjectTree.Item) arg0.getPath().getLastPathComponent();
if (arg0.getPath().getLastPathComponent() instanceof ObjectTreeItem) {
selectedObject = (ObjectTreeItem) arg0.getPath().getLastPathComponent();
instancesVis.setModel(selectedObject);
if(selectedInstance == null || objTree.get(selectedInstance.typeString()) != selectedObject)
selectedInstance = selectedObject;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/github/monster860/fastdmm/dmmmap/DMM.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.github.monster860.fastdmm.FastDMM;
import com.github.monster860.fastdmm.editing.DMMDiff;
import com.github.monster860.fastdmm.objtree.ObjectTree;
import com.github.monster860.fastdmm.objtree.ObjectTreeItem;

// DMM loader - Where you will get confused by all the regex.

Expand Down Expand Up @@ -346,7 +347,7 @@ public void setSize(int nMinX, int nMinY, int nMinZ, int nMaxX, int nMaxY, int n
maxY = nMaxY;
maxZ = nMaxZ;

ObjectTree.Item world = objTree.get("/world");
ObjectTreeItem world = objTree.get("/world");
if(world == null)
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.github.monster860.fastdmm.objtree.ModifiedType;
import com.github.monster860.fastdmm.objtree.ObjInstance;
import com.github.monster860.fastdmm.objtree.ObjectTree;
import com.github.monster860.fastdmm.objtree.ObjectTreeItem;

public class TileInstance {
public List<ObjInstance> objs;
Expand Down Expand Up @@ -177,7 +178,7 @@ public String addObject(ObjInstance obj) {
// Removes the bottom-most occurence of the obj.
public String removeObject(ObjInstance obj) {
TileInstance ti = new TileInstance(new ArrayList<>(objs), dmm);
ObjectTree.Item replacement = null;
ObjectTreeItem replacement = null;
if(obj.istype("/area"))
replacement = dmm.objTree.get(dmm.objTree.get("/world").getVar("area"));
else if(obj.istype("/turf")) {
Expand All @@ -197,7 +198,7 @@ else if(obj.istype("/turf")) {

public String removeObjectOrSubtypes(ObjInstance obj) {
TileInstance ti = new TileInstance(new ArrayList<>(objs), dmm);
ObjectTree.Item replacement = null;
ObjectTreeItem replacement = null;
if(obj.istype("/area"))
replacement = dmm.objTree.get(dmm.objTree.get("/world").getVar("area"));
else if(obj.istype("/turf")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.github.monster860.fastdmm.dmmmap.Location;
import com.github.monster860.fastdmm.objtree.ModifiedType;
import com.github.monster860.fastdmm.objtree.ObjInstance;
import com.github.monster860.fastdmm.objtree.ObjectTree;
import com.github.monster860.fastdmm.objtree.ObjectTreeItem;

public class MakeActiveObjectListener implements ActionListener {
FastDMM editor;
Expand All @@ -28,10 +28,10 @@ public void actionPerformed(ActionEvent e) {
if(editor.dmm == null)
return;
synchronized(editor) {
editor.selectedObject = oInstance instanceof ObjectTree.Item ? (ObjectTree.Item)oInstance : ((ModifiedType)oInstance).parent;
editor.selectedObject = oInstance instanceof ObjectTreeItem ? (ObjectTreeItem)oInstance : ((ModifiedType)oInstance).parent;
editor.selectedInstance = oInstance;
List<Object> path = new LinkedList<>();
ObjectTree.Item curr = editor.selectedObject;
ObjectTreeItem curr = editor.selectedObject;
while(curr != null && (curr.istype("/area") || curr.istype("/mob") || curr.istype("/obj") || curr.istype("/turf"))) {
path.add(0, curr);
curr = curr.parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import javax.swing.table.AbstractTableModel;

import com.github.monster860.fastdmm.objtree.ModifiedType;
import com.github.monster860.fastdmm.objtree.ObjectTree;
import com.github.monster860.fastdmm.objtree.ObjectTreeItem;

public class ModifiedTypeTableModel extends AbstractTableModel {
private static final long serialVersionUID = 3829092639624884439L;
Expand All @@ -26,16 +26,16 @@ public void rebuildTableList() {
displayedKeys.clear();
displayedVals.clear();

List<ObjectTree.Item> parentTypes = new ArrayList<>();
for(ObjectTree.Item currItem = type.parent; currItem != null ;currItem = currItem.parent) {
List<ObjectTreeItem> parentTypes = new ArrayList<>();
for(ObjectTreeItem currItem = type.parent; currItem != null ;currItem = currItem.parent) {
parentTypes.add(0, currItem);
}

Set<String> usedVars = new HashSet<>();
usedVars.add("type"); // These vars are represented in the object tree for the sole purpose of compatibility with games that modify parentType.
usedVars.add("parentType");

for(ObjectTree.Item currItem : parentTypes) {
for(ObjectTreeItem currItem : parentTypes) {
TreeMap<String, String> sortedVars = new TreeMap<String, String>();
for(Map.Entry<String,String> ent : currItem.vars.entrySet()) {
if(usedVars.contains(ent.getKey()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import com.github.monster860.fastdmm.FastDMM;
import com.github.monster860.fastdmm.dmirender.DMI;
import com.github.monster860.fastdmm.dmirender.IconSubstate;
import com.github.monster860.fastdmm.objtree.ObjectTree;
import com.github.monster860.fastdmm.objtree.ObjectTree.Item;
import com.github.monster860.fastdmm.objtree.ObjectTreeItem;

public class ObjectTreeRenderer extends DefaultTreeCellRenderer {
private static final long serialVersionUID = 931493078348635512L;
Expand All @@ -20,8 +19,8 @@ public ObjectTreeRenderer(FastDMM fdmm) {
}
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
if(value instanceof ObjectTree.Item) {
ObjectTree.Item item = (ObjectTree.Item)value;
if(value instanceof ObjectTreeItem) {
ObjectTreeItem item = (ObjectTreeItem)value;
setText(item.parentlessName());
setToolTipText(item.path);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public static final ObjInstance fromString(String s, ObjectTree objtree, DMM dmm
}

public static final ModifiedType deriveFrom(ObjInstance i) {
if(i instanceof ObjectTree.Item){
if(i instanceof ObjectTreeItem){
ModifiedType mt = new ModifiedType(new TreeMap<>(), i.typeString());
mt.parent = (ObjectTree.Item)i;
mt.parent = (ObjectTreeItem)i;
return mt;
} else {
ModifiedType p = (ModifiedType)i;
Expand All @@ -65,7 +65,7 @@ public static final ModifiedType deriveFrom(ObjInstance i) {

public Map<String, String> vars;
public String parentType;
public ObjectTree.Item parent;
public ObjectTreeItem parent;

@Override
public String getVar(String key) {
Expand Down
Loading

0 comments on commit cee33ba

Please sign in to comment.