skadistats.clarity.model.FieldPath Java Examples

The following examples show how to use skadistats.clarity.model.FieldPath. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EntityState.java    From clarity with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
default String dump(String title, Function<FieldPath, String> nameResolver) {
    final TextTable table = new TextTable.Builder()
            .setFrame(TextTable.FRAME_COMPAT)
            .addColumn("FP")
            .addColumn("Property")
            .addColumn("Value")
            .setTitle(title)
            .build();

    int i = 0;
    final Iterator<FieldPath> iter = fieldPathIterator();
    while (iter.hasNext()) {
        FieldPath fp = iter.next();
        table.setData(i, 0, fp);
        table.setData(i, 1, nameResolver.apply(fp));
        table.setData(i, 2, getValueForFieldPath(fp));
        i++;
    }

    return table.toString();
}
 
Example #2
Source File: PropertyChange.java    From clarity with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
boolean applyInternal(Object[] value) {
    Entity e = (Entity) value[0];
    int eIdx = e.getIndex();
    TriState classMatchState = classMatchesForEntity.get(eIdx);
    if (classMatchState == TriState.UNSET) {
        classMatchState = TriState.fromBoolean(classPattern.matcher(e.getDtClass().getDtName()).matches());
        classMatchesForEntity.set(eIdx, classMatchState);
    }
    if (classMatchState != TriState.YES) {
        return false;
    }
    FieldPath fp = (FieldPath) value[1];
    TriState propertyMatchState = propertyMatchesForEntity[eIdx].get(fp);
    if (propertyMatchState == null) {
        propertyMatchState = TriState.fromBoolean(propertyPattern.matcher(e.getDtClass().getNameForFieldPath(fp)).matches());
        propertyMatchesForEntity[eIdx].put(fp, propertyMatchState);
    }
    if (propertyMatchState != TriState.YES) {
        return false;
    }
    return true;
}
 
Example #3
Source File: SpawnsAndDeaths.java    From clarity-examples with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void processLifeStateChange(Entity e, FieldPath p) {
    int oldState = currentLifeState.containsKey(e.getIndex()) ? currentLifeState.get(e.getIndex()) : 2;
    int newState = e.getPropertyForFieldPath(p);
    if (oldState != newState) {
        currentLifeState.put(e.getIndex(), newState);
        switch(newState) {
            case 0:
                if (evSpawned != null) {
                    evSpawned.raise(e);
                }
                break;
            case 1:
                if (evDying != null) {
                    evDying.raise(e);
                }
                break;
            case 2:
                if (evDied != null) {
                    evDied.raise(e);
                }
                break;
        }
    }
}
 
Example #4
Source File: Main.java    From clarity-examples with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@OnEntityUpdated
public void onUpdated(Entity e, FieldPath[] updatedPaths, int updateCount) {
    if (!isHero(e)) {
        return;
    }
    ensureFieldPaths(e);
    boolean update = false;
    for (int i = 0; i < updateCount; i++) {
        if (updatedPaths[i].equals(mana) || updatedPaths[i].equals(maxMana)) {
            update = true;
            break;
        }
    }
    if (update) {
        System.out.format("%s (%s/%s)\n", e.getDtClass().getDtName(), e.getPropertyForFieldPath(mana), e.getPropertyForFieldPath(maxMana));
    }
}
 
Example #5
Source File: Main.java    From clarity-examples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnEntityCreated
public void onCreated(Entity e) {
    FieldPath fp = e.getDtClass().getFieldPathForName("CBodyComponent.m_hModel");
    if (fp == null) {
        return;
    }
    Long resourceHandle = e.getPropertyForFieldPath(fp);
    if (resourceHandle == null || resourceHandle == 0L) {
        return;
    }
    Resources.Entry entry = resources.getEntryForResourceHandle(resourceHandle);
    System.out.format("model for entity at %d (%d): %s\n", e.getIndex(), resourceHandle, entry);
}
 
Example #6
Source File: PropertyChange.java    From clarity with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnEntityCreated
@Order(1000)
public void onEntityCreated(Entity e) {
    final Iterator<FieldPath> iter = e.getState().fieldPathIterator();
    while(iter.hasNext()) {
        evPropertyChanged.raise(e, iter.next());
    }
}
 
Example #7
Source File: ObjectArrayEntityState.java    From clarity with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Iterator<FieldPath> fieldPathIterator() {
    return new SimpleIterator<FieldPath>() {
        int i = 0;
        @Override
        public FieldPath readNext() {
            return i < state.length ? new S1FieldPath(i++) : null;
        }
    };
}
 
Example #8
Source File: PropertyChange.java    From clarity with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnEntityUpdated
@Order(1000)
public void onUpdate(Entity e, FieldPath[] fieldPaths, int num) {
    for (int i = 0; i < num; i++) {
        evPropertyChanged.raise(e, fieldPaths[i]);
    }
}
 
Example #9
Source File: Parse.java    From parser with MIT License 5 votes vote down vote up
public <T> T getEntityProperty(Entity e, String property, Integer idx) {
	try {
     if (e == null) {
         return null;
     }
     if (idx != null) {
         property = property.replace("%i", Util.arrayIdxToString(idx));
     }
     FieldPath fp = e.getDtClass().getFieldPathForName(property);
     return e.getPropertyForFieldPath(fp);
	}
	catch (Exception ex) {
		return null;
	}
}
 
Example #10
Source File: VarSubTableField.java    From clarity with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void collectFieldPaths(S2ModifiableFieldPath fp, List<FieldPath> entries, ArrayEntityState state) {
    ArrayEntityState subState = state.sub(fp.cur());
    int len = subState.length();
    if (len > 0) {
        fp.down();
        fp.down();
        for (int i = 0; i < len; i++) {
            fp.set(fp.last() - 1, i);
            properties.getSerializer().collectFieldPaths(fp, entries, subState.sub(i));
        }
        fp.up(2);
    }
}
 
Example #11
Source File: VarArrayField.java    From clarity with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void collectFieldPaths(S2ModifiableFieldPath fp, List<FieldPath> entries, ArrayEntityState state) {
    ArrayEntityState subState = state.sub(fp.cur());
    fp.down();
    for (int i = 0; i < subState.length(); i++) {
        if (subState.has(i)) {
            fp.cur(i);
            entries.add(fp.unmodifiable());
        }
    }
    fp.up(1);
}
 
Example #12
Source File: SpawnsAndDeaths.java    From clarity-examples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnEntityUpdated
public void onUpdated(Context ctx, Entity e, FieldPath[] fieldPaths, int num) {
    FieldPath p = getFieldPathForEntity(e);
    if (p != null) {
        for (int i = 0; i < num; i++) {
            if (fieldPaths[i].equals(p)) {
                processLifeStateChange(e, p);
                break;
            }
        }
    }
}
 
Example #13
Source File: SpawnsAndDeaths.java    From clarity-examples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnEntityCreated
public void onCreated(Context ctx, Entity e) {
    clearCachedState(e);
    ensureFieldPathForEntityInitialized(e);
    FieldPath p = getFieldPathForEntity(e);
    if (p != null) {
        processLifeStateChange(e, p);
    }
}
 
Example #14
Source File: Main.java    From clarity-examples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnEntityPropertyChanged(classPattern = "CDOTA_Unit_Hero_.*", propertyPattern = "m_lifeState")
public void onEntityPropertyChanged(Context ctx, Entity e, FieldPath fp) {
    System.out.format(
            "%6d %s: %s = %s\n",
            ctx.getTick(),
            e.getDtClass().getDtName(),
            e.getDtClass().getNameForFieldPath(fp),
            e.getPropertyForFieldPath(fp)
    );
}
 
Example #15
Source File: ObservableEntity.java    From clarity-analyzer with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ObservableEntity(Entity entity) {
    this.entity = entity;
    index = new ReadOnlyStringWrapper(String.valueOf(entity.getIndex()));
    name = new ReadOnlyStringWrapper(entity.getDtClass().getDtName());
    Iterator<FieldPath> iter = entity.getState().fieldPathIterator();
    while (iter.hasNext()) {
        FieldPath fp = iter.next();
        indices.add(fp);
        properties.add(new ObservableEntityProperty(entity, fp));
    }
}
 
Example #16
Source File: Serializer.java    From clarity with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void collectFieldPaths(S2ModifiableFieldPath fp, List<FieldPath> entries, ArrayEntityState state) {
    for (int i = 0; i < fields.length; i++) {
        if (state.has(i)) {
            fp.cur(i);
            fields[i].collectFieldPaths(fp, entries, state);
        }
    }
}
 
Example #17
Source File: Wards.java    From parser with MIT License 5 votes vote down vote up
@OnEntityCreated
public void onCreated(Context ctx, Entity e) {      
    if (!isWard(e)) return;
    
    FieldPath lifeStatePath;
    
    clearCachedState(e);
    ensureFieldPathForEntityInitialized(e);
    if ((lifeStatePath = getFieldPathForEntity(e)) != null) {
        processLifeStateChange(e, lifeStatePath);
    }
}
 
Example #18
Source File: Wards.java    From parser with MIT License 5 votes vote down vote up
@OnEntityUpdated
public void onUpdated(Context ctx, Entity e, FieldPath[] fieldPaths, int num) {
    FieldPath p;
    if ((p = getFieldPathForEntity(e)) != null) {
        for (int i = 0; i < num; i++) {
            if (fieldPaths[i].equals(p)) {
                toProcess.add(new ProcessEntityCommand(e, p));
                break;
            }
        }
    }
}
 
Example #19
Source File: S2DTClass.java    From clarity with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public String getNameForFieldPath(FieldPath fp) {
    List<String> parts = new ArrayList<>();
    serializer.accumulateName(fp.s2(), 0, parts);
    StringBuilder b = new StringBuilder();
    for (String part : parts) {
        if (b.length() != 0) {
            b.append('.');
        }
        b.append(part);
    }
    return b.toString();
}
 
Example #20
Source File: Wards.java    From parser with MIT License 5 votes vote down vote up
public  void processLifeStateChange(Entity e, FieldPath p) {
    int oldState = currentLifeState.containsKey(e.getIndex()) ? currentLifeState.get(e.getIndex()) : 2;
    int newState = e.getPropertyForFieldPath(p);
    if (oldState != newState) {
        switch(newState) {
            case 0:
                if (evPlaced != null) {
                    evPlaced.raise(e);
                }
                break;
            case 1:
                String killer;
                if ((killer = wardKillersByWardClass.get(getWardTargetName(e.getDtClass().getDtName())).poll()) != null) {
                    if (evKilled != null) {
                        evKilled.raise(e, killer);
                    }
                } else {
                    if (evExpired != null) {
                        evExpired.raise(e);
                    }
                }
                break;
        }
    }
    
    currentLifeState.put(e.getIndex(), newState);
}
 
Example #21
Source File: MapControl.java    From clarity-analyzer with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void add(int from, List<? extends ObservableEntity> entities) {
    for (int i = 0; i < entities.size(); i++) {
        ObservableEntity oe = entities.get(i);
        Entity e = oe.getEntity();
        if (e == null) {
            continue;
        }
        FieldPath fp = e.getDtClass().getFieldPathForName("CBodyComponent.m_cellX");
        if (fp == null) {
            continue;
        }

        String name = oe.getEntity().getDtClass().getDtName();
        EntityIcon icon;
        if (name.equals("CDOTAPlayer")) {
            icon = new CameraIcon(oe);
        } else if (name.equals("CDOTA_BaseNPC_Barracks")) {
            icon = new BuildingIcon(oe, 250);
        } else if (name.equals("CDOTA_BaseNPC_Tower")) {
            icon = new BuildingIcon(oe, 200);
        } else if (name.equals("CDOTA_BaseNPC_Building")) {
            icon = new BuildingIcon(oe, 150);
        } else if (name.equals("CDOTA_BaseNPC_Fort")) {
            icon = new BuildingIcon(oe, 300);
        } else if (name.startsWith("CDOTA_Unit_Hero_")) {
            icon = new HeroIcon(oe);
        } else {
            icon = new DefaultIcon(oe);
        }

        mapEntities[from + i] = icon;
        icons.getChildren().add(icon.getShape());
    }
}
 
Example #22
Source File: Main.java    From clarity-examples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public V resolveValue(int index, int team, int pos) {
    String fieldPathString = pattern
            .replaceAll("%i", Util.arrayIdxToString(index))
            .replaceAll("%t", Util.arrayIdxToString(team))
            .replaceAll("%p", Util.arrayIdxToString(pos));
    String compiledName = entityName.replaceAll("%n", getTeamName(team));
    Entity entity = getEntity(compiledName);
    FieldPath fieldPath = entity.getDtClass().getFieldPathForName(fieldPathString);
    return entity.getPropertyForFieldPath(fieldPath);
}
 
Example #23
Source File: FixedSubTableField.java    From clarity with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void collectFieldPaths(S2ModifiableFieldPath fp, List<FieldPath> entries, ArrayEntityState state) {
    int i = fp.cur();
    if (state.has(i)) {
        fp.down();
        properties.getSerializer().collectFieldPaths(fp, entries, state.sub(i));
        fp.up(1);
    }
}
 
Example #24
Source File: FixedArrayField.java    From clarity with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void collectFieldPaths(S2ModifiableFieldPath fp, List<FieldPath> entries, ArrayEntityState state) {
    ArrayEntityState subState = state.sub(fp.cur());
    fp.down();
    for (int i = 0; i < subState.length(); i++) {
        if (subState.has(i)) {
            fp.cur(i);
            entries.add(fp.unmodifiable());
        }
    }
    fp.up(1);
}
 
Example #25
Source File: ObservableEntity.java    From clarity-analyzer with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public <T> ObjectBinding<T> getPropertyBinding(Class<T> propertyClass, String property, T defaultValue) {
    FieldPath fp = entity.getDtClass().getFieldPathForName(property);
    if (fp == null) {
        return Bindings.createObjectBinding(() -> defaultValue);
    } else {
        ObjectBinding<T> ob = getPropertyForFieldPath(fp).rawProperty();
        return Bindings.createObjectBinding(() -> ob.get(), ob);
    }
}
 
Example #26
Source File: ObservableEntity.java    From clarity-analyzer with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void update(FieldPath[] fieldPaths, int num) {
    for (int i = 0; i < num; i++) {
        int idx = getIndexForFieldPath(fieldPaths[i]);
        if (idx < 0) {
            ensureChangeOpen();
            idx = - idx - 1;
            indices.add(idx, fieldPaths[i]);
            properties.add(idx, new ObservableEntityProperty(entity, fieldPaths[i]));
            nextAdd(idx, idx);
        } else {
            properties.get(idx).setDirty(true);
        }
    }
}
 
Example #27
Source File: ObservableEntityList.java    From clarity-analyzer with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnEntityUpdated
public void onUpdate(Entity entity, FieldPath[] fieldPaths, int num) {
    lock.lock();
    try {
        markChange(CF_PROP);
        int i = entity.getIndex();
        ObservableEntity e = changes[i] == null ? entities[i] : changes[i];
        e.update(fieldPaths, num);
    } finally {
        lock.unlock();
    }
}
 
Example #28
Source File: SimpleField.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void collectFieldPaths(S2ModifiableFieldPath fp, List<FieldPath> entries, ArrayEntityState state) {
    entries.add(fp.unmodifiable());
}
 
Example #29
Source File: S1DTClass.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public String getNameForFieldPath(FieldPath fp) {
    return this.receiveProps[fp.s1().idx()].getVarName();
}
 
Example #30
Source File: Entities.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@OnReset
public void onReset(Demo.CDemoStringTables packet, ResetPhase phase) {
    switch (phase) {
        case START:
            resetInProgress = true;
            resetCapsule = entities.createCapsule();
            break;

        case CLEAR:
            entities = new ClientFrame(entityCount);
            for (int i = 0; i < classBaselines.length; i++) {
                classBaselines[i].reset();
            }
            for (int i = 0; i < entityBaselines.length; i++) {
                entityBaselines[i][0].reset();
                entityBaselines[i][1].reset();
            }
            break;

        case COMPLETE:
            resetInProgress = false;

            //updateEventDebug = true;

            Entity entity;
            for (int eIdx = 0; eIdx < entityCount; eIdx++) {
                entity = entities.getEntity(eIdx);
                if (resetCapsule.isExistent(eIdx)) {
                    if (entity == null || entity.getHandle() != resetCapsule.getHandle(eIdx)) {
                        Entity deletedEntity = entityRegistry.get(resetCapsule.getHandle(eIdx));
                        if (resetCapsule.isActive(eIdx)) {
                            emitLeftEvent(deletedEntity);
                        }
                        emitDeletedEvent(deletedEntity);
                    }
                }
                if (entity != null) {
                    if (!resetCapsule.isExistent(eIdx) || entity.getHandle() != resetCapsule.getHandle(eIdx)) {
                        emitCreatedEvent(entity);
                        if (entity.isActive()) {
                            emitEnteredEvent(entity);
                        }
                    } else {
                        Iterator<FieldPath> iter = entity.getState().fieldPathIterator();
                        int n = 0;
                        while (iter.hasNext()) {
                            updatedFieldPaths[n++] = iter.next();
                        }
                        emitUpdatedEvent(entity, n);
                    }
                }
            }

            resetCapsule = null;

            //updateEventDebug = false;

            evUpdatesCompleted.raise();
            break;
    }
}