Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
Argent77 committed Jul 29, 2023
2 parents 0b09c29 + b1646fa commit 1b3d4df
Show file tree
Hide file tree
Showing 74 changed files with 2,438 additions and 522 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
sed -i 's/debug="false"/debug="true"/' build.xml
ant -noinput -buildfile build.xml
- name: Upload artifact
if: ${{ github.actor != 'NearInfinityBrowser' }}
uses: pyTooling/Actions/releaser@r0
with:
tag: nightly
Expand Down
6 changes: 3 additions & 3 deletions src/org/infinity/NearInfinity.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import javax.swing.plaf.FontUIResource;

import org.infinity.datatype.ProRef;
import org.infinity.datatype.ResourceRef;
import org.infinity.datatype.Song2daBitmap;
import org.infinity.datatype.SpellProtType;
import org.infinity.datatype.Summon2daBitmap;
Expand Down Expand Up @@ -135,7 +136,7 @@

public final class NearInfinity extends JFrame implements ActionListener, ViewableContainer {
// the current Near Infinity version
private static final String VERSION = "v2.4-20230714";
private static final String VERSION = "v2.4-20230729";

// the minimum supported Java version
private static final int JAVA_VERSION_MIN = 8;
Expand Down Expand Up @@ -1503,9 +1504,8 @@ private void cacheResourceIcons(boolean threaded) {
sizeList.add(IconCache.getDefaultListIconSize());
}
if (!sizeList.isEmpty()) {
final String[] types = { "ITM", "SPL" };
int[] sizes = sizeList.stream().mapToInt(Integer::intValue).toArray();
for (final String type : types) {
for (final String type : ResourceRef.getIconExtensions()) {
final List<ResourceEntry> resources = ResourceFactory.getResources(type);
if (resources != null) {
for (final ResourceEntry e : resources) {
Expand Down
22 changes: 19 additions & 3 deletions src/org/infinity/check/AbstractChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,20 @@ public abstract class AbstractChecker extends AbstractSearcher implements Action
private final String key;

/** Resources, selected for check. */
protected List<ResourceEntry> files;
private List<ResourceEntry> files;

public AbstractChecker(String title, String key, String[] filetypes) {
public AbstractChecker(String title, String[] filetypes) {
super(CHECK_MULTI_TYPE_FORMAT, NearInfinity.getInstance());
settingsWindow = new ChildFrame(title, true);
settingsWindow.setIconImage(Icons.ICON_REFRESH_16.getIcon().getImage());
this.key = key;

// generating unique key for this checker type
String className = getClass().getSimpleName();
if (className.isEmpty()) {
className = getClass().getName();
}
this.key = className;

selector = new FileTypeSelector("Select files to check:", key, filetypes, null);

final JPanel bpanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
Expand Down Expand Up @@ -85,6 +92,15 @@ protected boolean runCheck(List<ResourceEntry> entries) {
return runSearch("Checking", entries);
}

/**
* Returns a list of resources for checking.
*
* @return List of resources of the selected types.
*/
protected List<ResourceEntry> getFiles() {
return files;
}

@Override
public void actionPerformed(ActionEvent event) {
if (event.getSource() == bStart) {
Expand Down
79 changes: 79 additions & 0 deletions src/org/infinity/check/EffectValidationChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Near Infinity - An Infinity Engine Browser and Editor
// Copyright (C) 2001 Jon Olav Hauglid
// See LICENSE.txt for license information

package org.infinity.check;

import java.util.ArrayList;
import java.util.List;

import org.infinity.NearInfinity;
import org.infinity.datatype.EffectBitmap;
import org.infinity.datatype.EffectType;
import org.infinity.datatype.IsNumeric;
import org.infinity.resource.AbstractStruct;
import org.infinity.resource.Profile;
import org.infinity.resource.Resource;
import org.infinity.resource.ResourceFactory;
import org.infinity.resource.StructEntry;
import org.infinity.resource.effects.BaseOpcode;
import org.infinity.resource.effects.DefaultOpcode;
import org.infinity.resource.key.ResourceEntry;
import org.infinity.search.ReferenceHitFrame;

/**
* Checks for invalid effect opcodes.
*/
public class EffectValidationChecker extends AbstractChecker {
/** Window with check results. */
private final ReferenceHitFrame hitFrame;

public EffectValidationChecker() {
super("Effects Validation Checker", getSupportedResourceTypes());
hitFrame = new ReferenceHitFrame("Invalid Effect Opcodes", NearInfinity.getInstance());
}

@Override
public void run() {
if (runCheck(getFiles())) {
hitFrame.close();
} else {
hitFrame.setVisible(true);
}
}

@Override
protected Runnable newWorker(ResourceEntry entry) {
return () -> {
final Resource resource = ResourceFactory.getResource(entry);
if (resource instanceof AbstractStruct) {
search(entry, (AbstractStruct) resource);
}
advanceProgress();
};
}

private void search(ResourceEntry entry, AbstractStruct struct) {
for (final StructEntry field : struct.getFlatFields()) {
if (field instanceof EffectType || field instanceof EffectBitmap) {
int value = ((IsNumeric) field).getValue();
final BaseOpcode opcode = BaseOpcode.getOpcode(value);
if (opcode instanceof DefaultOpcode) {
synchronized (hitFrame) {
hitFrame.addHit(entry, entry.getSearchString(), field);
}
}
}
}
}

private static String[] getSupportedResourceTypes() {
final List<String> retVal = new ArrayList<>();
for (final String type : new String[] { "CRE", "EFF", "ITM", "SPL" }) {
if (Profile.isResourceTypeSupported(type)) {
retVal.add(type);
}
}
return retVal.toArray(new String[0]);
}
}
4 changes: 2 additions & 2 deletions src/org/infinity/check/EffectsIndexChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public class EffectsIndexChecker extends AbstractChecker {
private final ReferenceHitFrame hitFrame;

public EffectsIndexChecker() {
super("Effects Index Checker", "EffectsIndexChecker", new String[] { "ITM", "SPL" });
super("Effects Index Checker", new String[] { "ITM", "SPL" });
hitFrame = new ReferenceHitFrame("Mis-indexed Effects", NearInfinity.getInstance());
}

// --------------------- Begin Interface Runnable ---------------------

@Override
public void run() {
if (runCheck(files)) {
if (runCheck(getFiles())) {
hitFrame.close();
} else {
hitFrame.setVisible(true);
Expand Down
4 changes: 2 additions & 2 deletions src/org/infinity/check/IDSRefChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public final class IDSRefChecker extends AbstractChecker {
private final ReferenceHitFrame hitFrame;

public IDSRefChecker() {
super("IDSRef Checker", "IDSRefChecker", new String[] { "CRE", "EFF", "ITM", "PRO", "SPL" });
super("IDSRef Checker", new String[] { "CRE", "EFF", "ITM", "PRO", "SPL" });
hitFrame = new ReferenceHitFrame("Unknown IDS references", NearInfinity.getInstance());
}

// --------------------- Begin Interface Runnable ---------------------

@Override
public void run() {
if (runCheck(files)) {
if (runCheck(getFiles())) {
hitFrame.close();
} else {
hitFrame.setVisible(true);
Expand Down
4 changes: 2 additions & 2 deletions src/org/infinity/check/ResRefChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public final class ResRefChecker extends AbstractChecker {
private List<String> extraValues;

public ResRefChecker() {
super("ResRef Checker", "ResRefChecker", FILE_TYPES);
super("ResRef Checker", FILE_TYPES);
hitFrame = new ReferenceHitFrame("Illegal ResourceRefs", NearInfinity.getInstance());

final ResourceEntry spawnRef = ResourceFactory.getResourceEntry("SPAWNGRP.2DA");
Expand All @@ -42,7 +42,7 @@ public ResRefChecker() {

@Override
public void run() {
if (runCheck(files)) {
if (runCheck(getFiles())) {
hitFrame.close();
} else {
hitFrame.setVisible(true);
Expand Down
Loading

0 comments on commit 1b3d4df

Please sign in to comment.