Added UnitXrossConverter

This commit is contained in:
Willem Cazander 2022-10-11 17:31:59 +02:00
parent 84738628af
commit d97076d436
159 changed files with 9197 additions and 96 deletions

View file

@ -8,6 +8,7 @@ import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import love.distributedrebirth.gdxapp4d.app.glyphdemo.apps.DemoUnicodePlaneDeskApp;
import love.distributedrebirth.gdxapp4d.app.glyphdemo.apps.DemoUnitConverterDeskApp;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
import love.distributedrebirth.gdxapp4d.app.glyphdemo.apps.DemoGlyphSetDeskApp;
import love.distributedrebirth.gdxapp4d.app.glyphdemo.apps.DemoNumberPartDeskApp;
@ -17,6 +18,7 @@ import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4LocaleService;
import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4Unicode4DService;
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppLauncher;
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppMenuSection;
import net.forwardfire.unitxc.UnitXCManager;
@Component
@BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
@ -34,15 +36,20 @@ public class GlyphDemoComponent {
@Reference
private VrGem4Unicode4DService unicode4DService;
@Reference
private UnitXCManager unitManager;
private final static String I18N_BUNDLE = "love.distributedrebirth.gdxapp4d.app.glyphdemo.Messages";
private final DeskAppLauncher unicodeLauncher;
private final DeskAppLauncher baseGlyphLauncher;
private final DeskAppLauncher basePartLauncher;
private final DeskAppLauncher unitConverterLauncher;
public GlyphDemoComponent() {
unicodeLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Demo Unicode Plane", () -> new DemoUnicodePlaneDeskApp(createBundle(), unicode4DService));
baseGlyphLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Demo Glyph Set", () -> new DemoGlyphSetDeskApp(createBundle()));
basePartLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Demo Number Parts", () -> new DemoNumberPartDeskApp(createBundle()));
unicodeLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Unicode Plane", () -> new DemoUnicodePlaneDeskApp(createBundle(), unicode4DService));
baseGlyphLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Glyph Set", () -> new DemoGlyphSetDeskApp(createBundle()));
basePartLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Number Parts", () -> new DemoNumberPartDeskApp(createBundle()));
unitConverterLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Unitˣᶜ Converter", () -> new DemoUnitConverterDeskApp(unitManager));
}
private ResourceBundle createBundle() {
@ -55,6 +62,7 @@ public class GlyphDemoComponent {
deskAppService.installDeskApp(unicodeLauncher);
deskAppService.installDeskApp(baseGlyphLauncher);
deskAppService.installDeskApp(basePartLauncher);
deskAppService.installDeskApp(unitConverterLauncher);
}
@Deactivate
@ -63,5 +71,6 @@ public class GlyphDemoComponent {
deskAppService.removeDeskApp(unicodeLauncher);
deskAppService.removeDeskApp(baseGlyphLauncher);
deskAppService.removeDeskApp(basePartLauncher);
deskAppService.removeDeskApp(unitConverterLauncher);
}
}

View file

@ -0,0 +1,164 @@
package love.distributedrebirth.gdxapp4d.app.glyphdemo.apps;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import imgui.ImGui;
import imgui.flag.ImGuiTableFlags;
import imgui.type.ImDouble;
import imgui.type.ImInt;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.AbstractDeskApp;
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppContourSection;
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppRenderer;
import net.forwardfire.unitxc.UnitXCManager;
import net.forwardfire.unitxc.model.UnitXCGroup;
import net.forwardfire.unitxc.model.UnitXCType;
@BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
public class DemoUnitConverterDeskApp extends AbstractDeskApp implements DeskAppRenderer {
private final UnitXCManager unitManager;
private final List<UnitXCType> unitTypes;
private final List<UnitXCGroup> unitGroups;
private final Map<String, String> unitTypesFlags;
private final Map<String, String> unitTypesValues;
private final String[] unitGroupNames;
private final ImDouble convertValue = new ImDouble(1234);
private final ImInt convertFromGroup = new ImInt();
private final ImInt convertFromType = new ImInt();
private final ImInt unitTypeLimit = new ImInt(5432);
private final List<UnitXCType> convertFromTypes;
private final long totalUnits;
private String[] convertFromTypeNames;
public DemoUnitConverterDeskApp(UnitXCManager unitManager) {
this.unitManager = unitManager;
this.unitTypes = new ArrayList<>();
this.unitGroups = unitManager.getConfig().getUnitGroups();
this.unitTypesFlags = new HashMap<>();
this.unitTypesValues = new HashMap<>();
this.convertFromTypes = new ArrayList<>();
List<String> names = new ArrayList<>();
for (UnitXCGroup typeGroup:unitGroups) {
names.add(typeGroup.getName().getValue("und"));
}
unitGroupNames = names.toArray(new String[names.size()]);
long ts = 0l;
for (UnitXCGroup typeGroup:unitManager.getConfig().getUnitGroups()) {
UnitXCType type = unitManager.getUnitType(typeGroup.getBaseTypeId());
if (type == null) {
throw new IllegalStateException("No base type for: "+typeGroup.getId()+" needs: "+typeGroup.getBaseTypeId());
}
long tc = typeGroup.getUnitTypeSize();
ts += tc;
}
this.totalUnits = ts;
updateConvertFromType();
updateUnitType();
}
public void create() {
getContours().setTitle("Unitˣᶜ Converter");
getContours().registrateContour(DeskAppContourSection.MAIN, this);
}
@Override
public void render() {
ImGui.text("Total units loaded: "+totalUnits);
// TODO: don't do update on render thread
if (ImGui.inputDouble("ConvertValue", convertValue)) {
updateUnitType();
}
if (ImGui.combo("ConvertFromGroup", convertFromGroup, unitGroupNames)) {
updateConvertFromType();
updateUnitType();
}
if (ImGui.combo("ConvertFromType", convertFromType, convertFromTypeNames)) {
updateUnitType();
}
UnitXCGroup typeGroup = unitGroups.get(convertFromGroup.get());
if (ImGui.sliderInt("Limit of: "+typeGroup.getUnitTypeSize(), unitTypeLimit.getData(), 1000, 100000)) {
updateUnitType();
}
int flags = ImGuiTableFlags.ScrollX | ImGuiTableFlags.RowBg | ImGuiTableFlags.BordersOuter | ImGuiTableFlags.BordersV | ImGuiTableFlags.Resizable;
ImGui.beginTable("unit-types", 4, flags);
ImGui.tableSetupColumn("value");
ImGui.tableSetupColumn("id");
ImGui.tableSetupColumn("name");
ImGui.tableSetupColumn("flags");
ImGui.tableHeadersRow();
for (UnitXCType unitType:unitTypes) {
ImGui.tableNextRow();
ImGui.tableNextColumn();
ImGui.text(unitTypesValues.get(unitType.getId()));
ImGui.tableNextColumn();
ImGui.text(unitType.getId());
ImGui.tableNextColumn();
ImGui.text(unitType.getName());
ImGui.tableNextColumn();
ImGui.text(unitTypesFlags.get(unitType.getId()));
ImGui.tableNextColumn();
}
ImGui.endTable();
}
private void updateConvertFromType() {
convertFromTypes.clear();
convertFromType.set(0);
int i = 0;
UnitXCGroup typeGroup = unitGroups.get(convertFromGroup.get());
Iterator<String> types = typeGroup.getUnitTypeIds();
List<String> names = new ArrayList<>();
while (types.hasNext()) {
i++;
if (i>1000) {
break;
}
UnitXCType unitType = typeGroup.getUnitType(types.next());
names.add(unitType.getName());
convertFromTypes.add(unitType);
}
convertFromTypeNames = names.toArray(new String[names.size()]);
}
private void updateUnitType() {
unitTypes.clear();
unitTypesFlags.clear();
unitTypesValues.clear();
int limitCounter = 0;
UnitXCType fromType = convertFromTypes.get(convertFromType.get());
UnitXCGroup typeGroup = unitGroups.get(convertFromGroup.get());
Iterator<String> types = typeGroup.getUnitTypeIds();
while (types.hasNext()) {
limitCounter++;
if (limitCounter>unitTypeLimit.get()) {
break;
}
UnitXCType unitType = typeGroup.getUnitType(types.next());
unitTypes.add(unitType);
unitTypesFlags.put(unitType.getId(), StringUtils.join(unitType.getTypeFlags(), ","));
try {
double convertRaw = convertValue.get();
double convertOut = unitManager.getConverter().convert(convertRaw, fromType.getId(), unitType.getId());
unitTypesValues.put(unitType.getId(), String.valueOf(convertOut));
} catch (IllegalArgumentException ignore) {
//java.lang.IllegalArgumentException: from and to groups are not equals: second != metre
break; // cross group jump is ~supported, but in here its is a bug somewhere and i also get;
// [libjvm.so] AccessInternal::PostRuntimeDispatch<G1BarrierSet::AccessBarrier<0ul, G1BarrierSet>, (AccessInternal::BarrierType)2, 0ul>::oop_access_barrier(void*)+0x1
}
}
}
}

View file

@ -1,11 +1,11 @@
DemoGlyphSetDeskApp.title=Demo Glyph Set
DemoGlyphSetDeskApp.title=Glyph Set
DemoGlyphSetDeskApp.showBase27=\uE219\u2005\uE362\u2005\uE0C0\u2005\uE13F\u2005\uE2F4\u2005\uE387\u2005\uE400
DemoGlyphSetDeskApp.colScript=\uE2F4\u2005\uE3A1\u2005\uE08B\u2005\uE1CB\u2005\uE2AA\u2005\uE20F
DemoGlyphSetDeskApp.col10Num=\uE386\u2005\uE216\u2005\uE171\u2005\uE153\u2005\uE0C0\u2005\uE08C\u2005\uE2F4
DemoGlyphSetDeskApp.col16Num=\uE386\u2005\uE3FF\u2005\uE216\u2005\uE171\u2005\uE153\u2005\uE0C0\u2005\uE08C\u2005\uE2F4
DemoGlyphSetDeskApp.col27Num=\uE387\u2005\uE400\u2005\uE216\u2005\uE171\u2005\uE153\u2005\uE0C0\u2005\uE08C\u2005\uE2F4
DemoNumberPartDeskApp.title=Demo Number Parts
DemoNumberPartDeskApp.title=Number Parts
DemoNumberPartDeskApp.selectBase=\uE0C0\u2005\uE13F\u2005\uE2F4
DemoNumberPartDeskApp.selectName=\uE216\u2005\uE13F\u2005\uE153\u2005\uE3EC
DemoNumberPartDeskApp.selectPurpose=\uE203\u2005\uE171\u2005\uE08C\u2005\uE203\u2005\uE2F4\u2005\uE3EC
@ -13,7 +13,7 @@ DemoNumberPartDeskApp.showBase10=\uE219\u2005\uE362\u2005\uE0C0\u2005\uE13F\u200
DemoNumberPartDeskApp.showBase16=\uE219\u2005\uE362\u2005\uE0C0\u2005\uE13F\u2005\uE2F4\u2005\uE386\u2005\uE3FF
DemoNumberPartDeskApp.showBase27=\uE219\u2005\uE362\u2005\uE0C0\u2005\uE13F\u2005\uE2F4\u2005\uE387\u2005\uE400
DemoUnicodePlaneDeskApp.title=Demo Unicode Plane
DemoUnicodePlaneDeskApp.title=Unicode Plane
DemoUnicodePlaneDeskApp.colPlane=Unicode Plane
DemoUnicodePlaneDeskApp.colText=Example
DemoUnicodePlaneDeskApp.render4DPlane0=Show all in unicode4D

View file

@ -1,11 +1,11 @@
DemoGlyphSetDeskApp.title=Demo Glyph Set
DemoGlyphSetDeskApp.title=Glyph Set
DemoGlyphSetDeskApp.showBase27=Toon basis27
DemoGlyphSetDeskApp.colScript=Script
DemoGlyphSetDeskApp.col10Num=10Nummer
DemoGlyphSetDeskApp.col16Num=16Nummer
DemoGlyphSetDeskApp.col27Num=27Nummer
DemoNumberPartDeskApp.title=Demo Nummer Onderdeel
DemoNumberPartDeskApp.title=Nummer Onderdeel
DemoNumberPartDeskApp.selectBase=Basis
DemoNumberPartDeskApp.selectName=Naam:
DemoNumberPartDeskApp.selectPurpose=Doel:
@ -13,7 +13,7 @@ DemoNumberPartDeskApp.showBase10=Toon basis10
DemoNumberPartDeskApp.showBase16=Toon basis16
DemoNumberPartDeskApp.showBase27=Toon basis27
DemoUnicodePlaneDeskApp.title=Demo Unicode Vlak
DemoUnicodePlaneDeskApp.title=Unicode Vlak
DemoUnicodePlaneDeskApp.colPlane=Unicode Vlak
DemoUnicodePlaneDeskApp.colText=Voorbeeld
DemoUnicodePlaneDeskApp.render4DPlane0=Toon alles in unicode4D