This commit is contained in:
Robert Janetzko 2022-04-13 05:28:07 +00:00
parent ed3cb294c9
commit d53212326d
11 changed files with 3829 additions and 90 deletions

View file

@ -9,8 +9,8 @@ ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends graphviz
# [Optional] Uncomment the next lines to use go get to install anything else you need
# USER vscode

304
analyze/analyze.go Normal file
View file

@ -0,0 +1,304 @@
package analyze
import (
"encoding/json"
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"legendsbrowser/util"
"log"
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"text/template"
"github.com/iancoleman/strcase"
)
func Analyze(filex string) {
files, err := filepath.Glob("*.xml")
if err != nil {
log.Fatal(err)
}
fmt.Println(files)
files = []string{filex}
a := NewAnalyzeData()
for _, file := range files {
xmlFile, err := os.Open(file)
if err != nil {
fmt.Println(err)
}
fmt.Println("Successfully Opened", file)
defer xmlFile.Close()
converter := util.NewConvertReader(xmlFile)
analyze(converter, a)
}
createMetadata(a)
}
type analyzeData struct {
path []string
types *map[string]bool
fields *map[string]bool
isString *map[string]bool
multiple *map[string]bool
}
func NewAnalyzeData() analyzeData {
path := make([]string, 0)
types := make(map[string]bool, 0)
fields := make(map[string]bool, 0)
isString := make(map[string]bool, 0)
multiple := make(map[string]bool, 0)
return analyzeData{
path: path,
types: &types,
fields: &fields,
isString: &isString,
multiple: &multiple,
}
}
func analyzeElement(d *xml.Decoder, a analyzeData) error {
if len(a.path) > 1 {
(*a.fields)[strings.Join(a.path, ">")] = true
}
var (
data []byte
)
value := true
fields := make(map[string]bool)
Loop:
for {
tok, err := d.Token()
if err == io.EOF {
break Loop
} else if err != nil {
return err
}
switch t := tok.(type) {
case xml.StartElement:
value = false
(*a.types)[strings.Join(a.path, ">")] = true
a2 := a
a2.path = append(a.path, t.Name.Local)
if _, ok := fields[t.Name.Local]; ok {
(*a.multiple)[strings.Join(a2.path, ">")] = true
}
fields[t.Name.Local] = true
analyzeElement(d, a2)
case xml.CharData:
data = append(data, t...)
case xml.EndElement:
if value {
if _, err := strconv.Atoi(string(data)); err != nil {
(*a.isString)[strings.Join(a.path, ">")] = true
}
}
if t.Name.Local == "type" {
a.path[len(a.path)-2] = a.path[len(a.path)-2] + strcase.ToCamel(string(data))
fmt.Println(a.path)
}
return nil
}
}
return nil
}
func analyze(r io.Reader, a analyzeData) error {
d := xml.NewDecoder(r)
return analyzeElement(d, a)
}
func createMetadata(a analyzeData) {
ts := util.Keys(*a.types)
sort.Strings(ts)
fs := util.Keys(*a.fields)
sort.Strings(fs)
objects := make(map[string]Object, 0)
for _, k := range ts {
if ok, _ := isArray(k, fs); !ok {
n := k
if strings.Contains(k, ">") {
n = k[strings.LastIndex(k, ">")+1:]
}
if n == "" {
continue
}
objFields := make(map[string]Field, 0)
fmt.Println("\n", n)
for _, f := range fs {
if strings.HasPrefix(f, k+">") {
fn := f[len(k)+1:]
if !strings.Contains(fn, ">") {
fmt.Println(" ", fn)
if ok, elements := isArray(f, fs); ok {
el := elements[strings.LastIndex(elements, ">")+1:]
objFields[fn] = Field{
Name: strcase.ToCamel(fn),
Type: "array",
ElementType: &(el),
}
} else if ok, _ := isObject(f, fs); ok {
objFields[fn] = Field{
Name: strcase.ToCamel(fn),
Type: "object",
Multiple: (*a.multiple)[f],
}
} else if (*a.isString)[f] {
objFields[fn] = Field{
Name: strcase.ToCamel(fn),
Type: "string",
Multiple: (*a.multiple)[f],
}
} else {
objFields[fn] = Field{
Name: strcase.ToCamel(fn),
Type: "int",
Multiple: (*a.multiple)[f],
}
}
}
}
}
objects[n] = Object{
Name: strcase.ToCamel(n),
Id: (*a.fields)[k+">id"],
Named: (*a.fields)[k+">name"],
Typed: (*a.fields)[k+">type"],
Fields: objFields,
}
}
}
file, _ := json.MarshalIndent(objects, "", " ")
_ = ioutil.WriteFile("model.json", file, 0644)
f, err := os.Create("contributors.go")
defer f.Close()
err = packageTemplate.Execute(f, struct {
Objects map[string]Object
}{
Objects: objects,
})
if err != nil {
fmt.Println(err)
}
}
func isArray(typ string, types []string) (bool, string) {
fc := 0
elements := ""
for _, t := range types {
if !strings.HasPrefix(t, typ+">") {
continue
}
f := t[len(typ)+1:]
if strings.Contains(f, ">") {
continue
}
fc++
elements = t
}
return fc == 1, elements
}
func isObject(typ string, types []string) (bool, string) {
fc := 0
for _, t := range types {
if !strings.HasPrefix(t, typ+">") {
continue
}
fc++
}
return fc > 0, typ
}
type Object struct {
Name string `json:"name"`
Id bool `json:"id,omitempty"`
Named bool `json:"named,omitempty"`
Typed bool `json:"typed,omitempty"`
Fields map[string]Field `json:"fields"`
}
type Field struct {
Name string `json:"name"`
Type string `json:"type"`
Multiple bool `json:"multiple,omitempty"`
ElementType *string `json:"elements,omitempty"`
}
func (f Field) TypeLine(objects map[string]Object) string {
n := f.Name
if n == "Id" || n == "Name" {
n = n + "_"
}
m := ""
if f.Multiple {
m = "[]"
}
t := f.Type
if f.Type == "array" {
t = "map[int]*" + objects[*f.ElementType].Name
}
if f.Type == "object" {
t = f.Name
}
j := "`json:\"" + strcase.ToLowerCamel(f.Name) + "\"`"
return fmt.Sprintf("%s %s%s %s", n, m, t, j)
}
var packageTemplate = template.Must(template.New("").Parse(`// Code generated by go generate; DO NOT EDIT.
package generate
{{- range $name, $obj := .Objects }}
type {{ $obj.Name }} struct {
{{- range $fname, $field := $obj.Fields }}
{{ $field.TypeLine $.Objects }}
{{- end }}
}
{{- if $obj.Id }}
func (x *{{ $obj.Name }}) Id() int { return x.Id_ }
{{- end }}
{{- if $obj.Named }}
func (x *{{ $obj.Name }}) Name() string { return x.Name_ }
{{- end }}
{{- end }}
`))

745
contributors.go Normal file
View file

@ -0,0 +1,745 @@
// Code generated by go generate; DO NOT EDIT.
package generate
type Artifact struct {
AbsTileX int `json:"absTileX"`
AbsTileY int `json:"absTileY"`
AbsTileZ int `json:"absTileZ"`
HolderHfid int `json:"holderHfid"`
Id_ int `json:"id"`
Item Item `json:"item"`
Name_ string `json:"name"`
SiteId int `json:"siteId"`
StructureLocalId int `json:"structureLocalId"`
SubregionId int `json:"subregionId"`
}
func (x *Artifact) Id() int { return x.Id_ }
func (x *Artifact) Name() string { return x.Name_ }
type DanceForm struct {
Description string `json:"description"`
Id_ int `json:"id"`
}
func (x *DanceForm) Id() int { return x.Id_ }
type DfWorld struct {
Artifacts map[int]*Artifact `json:"artifacts"`
DanceForms map[int]*DanceForm `json:"danceForms"`
Entities map[int]*Entity `json:"entities"`
EntityPopulations map[int]* `json:"entityPopulations"`
HistoricalEras map[int]*HistoricalEra `json:"historicalEras"`
HistoricalEventCollections map[int]*HistoricalEventCollection `json:"historicalEventCollections"`
HistoricalEvents map[int]*HistoricalEvent `json:"historicalEvents"`
HistoricalFigures map[int]*HistoricalFigure `json:"historicalFigures"`
MusicalForms map[int]*MusicalForm `json:"musicalForms"`
PoeticForms map[int]*PoeticForm `json:"poeticForms"`
Regions map[int]*Region `json:"regions"`
Sites map[int]*Site `json:"sites"`
UndergroundRegions map[int]*UndergroundRegion `json:"undergroundRegions"`
WorldConstructions string `json:"worldConstructions"`
WrittenContents map[int]*WrittenContent `json:"writtenContents"`
}
type Entity struct {
Id_ int `json:"id"`
Name_ string `json:"name"`
}
func (x *Entity) Id() int { return x.Id_ }
func (x *Entity) Name() string { return x.Name_ }
type EntityFormerPositionLink struct {
EndYear int `json:"endYear"`
EntityId int `json:"entityId"`
PositionProfileId int `json:"positionProfileId"`
StartYear int `json:"startYear"`
}
type EntityLink struct {
EntityId int `json:"entityId"`
LinkStrength int `json:"linkStrength"`
LinkType string `json:"linkType"`
}
type EntityPositionLink struct {
EntityId int `json:"entityId"`
PositionProfileId int `json:"positionProfileId"`
StartYear int `json:"startYear"`
}
type EntitySquadLink struct {
EntityId int `json:"entityId"`
SquadId int `json:"squadId"`
SquadPosition int `json:"squadPosition"`
StartYear int `json:"startYear"`
}
type HfLink struct {
Hfid int `json:"hfid"`
LinkStrength int `json:"linkStrength"`
LinkType string `json:"linkType"`
}
type HfSkill struct {
Skill string `json:"skill"`
TotalIp int `json:"totalIp"`
}
type HistoricalEra struct {
Name_ string `json:"name"`
StartYear int `json:"startYear"`
}
func (x *HistoricalEra) Name() string { return x.Name_ }
type HistoricalEvent struct {
Id_ int `json:"id"`
Seconds72 int `json:"seconds72"`
Type string `json:"type"`
Year int `json:"year"`
}
func (x *HistoricalEvent) Id() int { return x.Id_ }
type HistoricalEventAddHfEntityLink struct {
CivId int `json:"civId"`
Hfid int `json:"hfid"`
Link string `json:"link"`
PositionId int `json:"positionId"`
}
type HistoricalEventAddHfHfLink struct {
Hfid int `json:"hfid"`
HfidTarget int `json:"hfidTarget"`
}
type HistoricalEventArtifactClaimFormed struct {
ArtifactId int `json:"artifactId"`
Circumstance string `json:"circumstance"`
Claim string `json:"claim"`
EntityId int `json:"entityId"`
HistFigureId int `json:"histFigureId"`
PositionProfileId int `json:"positionProfileId"`
}
type HistoricalEventArtifactCreated struct {
ArtifactId int `json:"artifactId"`
HistFigureId int `json:"histFigureId"`
SiteId int `json:"siteId"`
UnitId int `json:"unitId"`
}
type HistoricalEventArtifactLost struct {
ArtifactId int `json:"artifactId"`
SiteId int `json:"siteId"`
SubregionId int `json:"subregionId"`
}
type HistoricalEventArtifactStored struct {
ArtifactId int `json:"artifactId"`
HistFigureId int `json:"histFigureId"`
SiteId int `json:"siteId"`
UnitId int `json:"unitId"`
}
type HistoricalEventAssumeIdentity struct {
IdentityId int `json:"identityId"`
TargetEnid int `json:"targetEnid"`
TricksterHfid int `json:"tricksterHfid"`
}
type HistoricalEventAttackedSite struct {
AttackerCivId int `json:"attackerCivId"`
AttackerGeneralHfid int `json:"attackerGeneralHfid"`
DefenderCivId int `json:"defenderCivId"`
DefenderGeneralHfid int `json:"defenderGeneralHfid"`
SiteCivId int `json:"siteCivId"`
SiteId int `json:"siteId"`
}
type HistoricalEventBodyAbused struct {
Coords string `json:"coords"`
FeatureLayerId int `json:"featureLayerId"`
SiteId int `json:"siteId"`
SubregionId int `json:"subregionId"`
}
type HistoricalEventCeremony struct {
CivId int `json:"civId"`
FeatureLayerId int `json:"featureLayerId"`
OccasionId int `json:"occasionId"`
ScheduleId int `json:"scheduleId"`
SiteId int `json:"siteId"`
SubregionId int `json:"subregionId"`
}
type HistoricalEventChangeHfJob struct {
FeatureLayerId int `json:"featureLayerId"`
Hfid int `json:"hfid"`
SiteId int `json:"siteId"`
SubregionId int `json:"subregionId"`
}
type HistoricalEventChangeHfState struct {
Coords string `json:"coords"`
FeatureLayerId int `json:"featureLayerId"`
Hfid int `json:"hfid"`
Mood string `json:"mood"`
Reason string `json:"reason"`
SiteId int `json:"siteId"`
State string `json:"state"`
SubregionId int `json:"subregionId"`
}
type HistoricalEventChangedCreatureType struct {
ChangeeHfid int `json:"changeeHfid"`
ChangerHfid int `json:"changerHfid"`
NewCaste string `json:"newCaste"`
NewRace string `json:"newRace"`
OldCaste string `json:"oldCaste"`
OldRace string `json:"oldRace"`
}
type HistoricalEventCompetition struct {
CivId int `json:"civId"`
CompetitorHfid []int `json:"competitorHfid"`
FeatureLayerId int `json:"featureLayerId"`
OccasionId int `json:"occasionId"`
ScheduleId int `json:"scheduleId"`
SiteId int `json:"siteId"`
SubregionId int `json:"subregionId"`
WinnerHfid int `json:"winnerHfid"`
}
type HistoricalEventCreatedSite struct {
BuilderHfid int `json:"builderHfid"`
CivId int `json:"civId"`
SiteCivId int `json:"siteCivId"`
SiteId int `json:"siteId"`
}
type HistoricalEventCreatedStructure struct {
BuilderHfid int `json:"builderHfid"`
CivId int `json:"civId"`
SiteCivId int `json:"siteCivId"`
SiteId int `json:"siteId"`
StructureId int `json:"structureId"`
}
type HistoricalEventCreatedWorldConstruction struct {
CivId int `json:"civId"`
MasterWcid int `json:"masterWcid"`
SiteCivId int `json:"siteCivId"`
SiteId1 int `json:"siteId1"`
SiteId2 int `json:"siteId2"`
Wcid int `json:"wcid"`
}
type HistoricalEventCreatureDevoured struct {
FeatureLayerId int `json:"featureLayerId"`
SiteId int `json:"siteId"`
SubregionId int `json:"subregionId"`
}
type HistoricalEventEntityAllianceFormed struct {
InitiatingEnid int `json:"initiatingEnid"`
JoiningEnid int `json:"joiningEnid"`
}
type HistoricalEventEntityBreachFeatureLayer struct {
CivEntityId int `json:"civEntityId"`
FeatureLayerId int `json:"featureLayerId"`
SiteEntityId int `json:"siteEntityId"`
SiteId int `json:"siteId"`
}
type HistoricalEventEntityCreated struct {
EntityId int `json:"entityId"`
SiteId int `json:"siteId"`
StructureId int `json:"structureId"`
}
type HistoricalEventFailedFrameAttempt struct {
ConvicterEnid int `json:"convicterEnid"`
Crime string `json:"crime"`
FooledHfid int `json:"fooledHfid"`
FramerHfid int `json:"framerHfid"`
TargetHfid int `json:"targetHfid"`
}
type HistoricalEventFieldBattle struct {
AttackerCivId int `json:"attackerCivId"`
AttackerGeneralHfid int `json:"attackerGeneralHfid"`
Coords string `json:"coords"`
DefenderCivId int `json:"defenderCivId"`
DefenderGeneralHfid int `json:"defenderGeneralHfid"`
FeatureLayerId int `json:"featureLayerId"`
SubregionId int `json:"subregionId"`
}
type HistoricalEventGamble struct {
GamblerHfid int `json:"gamblerHfid"`
NewAccount int `json:"newAccount"`
OldAccount int `json:"oldAccount"`
SiteId int `json:"siteId"`
StructureId int `json:"structureId"`
}
type HistoricalEventHfAbducted struct {
FeatureLayerId int `json:"featureLayerId"`
SiteId int `json:"siteId"`
SnatcherHfid int `json:"snatcherHfid"`
SubregionId int `json:"subregionId"`
TargetHfid int `json:"targetHfid"`
}
type HistoricalEventHfAttackedSite struct {
AttackerHfid int `json:"attackerHfid"`
DefenderCivId int `json:"defenderCivId"`
SiteCivId int `json:"siteCivId"`
SiteId int `json:"siteId"`
}
type HistoricalEventHfConvicted struct {
ConvictedHfid int `json:"convictedHfid"`
ConvicterEnid int `json:"convicterEnid"`
Crime string `json:"crime"`
PrisonMonths int `json:"prisonMonths"`
}
type HistoricalEventHfDestroyedSite struct {
AttackerHfid int `json:"attackerHfid"`
DefenderCivId int `json:"defenderCivId"`
SiteCivId int `json:"siteCivId"`
SiteId int `json:"siteId"`
}
type HistoricalEventHfDied struct {
Cause string `json:"cause"`
FeatureLayerId int `json:"featureLayerId"`
Hfid int `json:"hfid"`
SiteId int `json:"siteId"`
SlayerCaste string `json:"slayerCaste"`
SlayerHfid int `json:"slayerHfid"`
SlayerItemId int `json:"slayerItemId"`
SlayerRace string `json:"slayerRace"`
SlayerShooterItemId int `json:"slayerShooterItemId"`
SubregionId int `json:"subregionId"`
}
type HistoricalEventHfGainsSecretGoal struct {
Hfid int `json:"hfid"`
SecretGoal string `json:"secretGoal"`
}
type HistoricalEventHfNewPet struct {
Coords string `json:"coords"`
FeatureLayerId int `json:"featureLayerId"`
GroupHfid int `json:"groupHfid"`
SiteId int `json:"siteId"`
SubregionId int `json:"subregionId"`
}
type HistoricalEventHfRelationshipDenied struct {
FeatureLayerId int `json:"featureLayerId"`
Reason string `json:"reason"`
ReasonId int `json:"reasonId"`
Relationship string `json:"relationship"`
SeekerHfid int `json:"seekerHfid"`
SiteId int `json:"siteId"`
SubregionId int `json:"subregionId"`
TargetHfid int `json:"targetHfid"`
}
type HistoricalEventHfSimpleBattleEvent struct {
FeatureLayerId int `json:"featureLayerId"`
Group1Hfid int `json:"group1Hfid"`
Group2Hfid int `json:"group2Hfid"`
SiteId int `json:"siteId"`
SubregionId int `json:"subregionId"`
Subtype string `json:"subtype"`
}
type HistoricalEventHfTravel struct {
Coords string `json:"coords"`
FeatureLayerId int `json:"featureLayerId"`
GroupHfid int `json:"groupHfid"`
Return string `json:"return"`
SiteId int `json:"siteId"`
SubregionId int `json:"subregionId"`
}
type HistoricalEventHfWounded struct {
FeatureLayerId int `json:"featureLayerId"`
SiteId int `json:"siteId"`
SubregionId int `json:"subregionId"`
WoundeeHfid int `json:"woundeeHfid"`
WounderHfid int `json:"wounderHfid"`
}
type HistoricalEventHfsFormedReputationRelationship struct {
FeatureLayerId int `json:"featureLayerId"`
HfRep1Of2 string `json:"hfRep1Of2"`
HfRep2Of1 string `json:"hfRep2Of1"`
Hfid1 int `json:"hfid1"`
Hfid2 int `json:"hfid2"`
IdentityId1 int `json:"identityId1"`
IdentityId2 int `json:"identityId2"`
SiteId int `json:"siteId"`
SubregionId int `json:"subregionId"`
}
type HistoricalEventItemStolen struct {
Circumstance string `json:"circumstance"`
CircumstanceId int `json:"circumstanceId"`
}
type HistoricalEventKnowledgeDiscovered struct {
First string `json:"first"`
Hfid int `json:"hfid"`
Knowledge string `json:"knowledge"`
}
type HistoricalEventMasterpieceItem struct {
EntityId int `json:"entityId"`
Hfid int `json:"hfid"`
SiteId int `json:"siteId"`
SkillAtTime int `json:"skillAtTime"`
}
type HistoricalEventMerchant struct {
DepotEntityId int `json:"depotEntityId"`
SiteId int `json:"siteId"`
TraderEntityId int `json:"traderEntityId"`
}
type HistoricalEventPerformance struct {
CivId int `json:"civId"`
FeatureLayerId int `json:"featureLayerId"`
OccasionId int `json:"occasionId"`
ScheduleId int `json:"scheduleId"`
SiteId int `json:"siteId"`
SubregionId int `json:"subregionId"`
}
type HistoricalEventPlunderedSite struct {
AttackerCivId int `json:"attackerCivId"`
DefenderCivId int `json:"defenderCivId"`
Detected string `json:"detected"`
SiteCivId int `json:"siteCivId"`
SiteId int `json:"siteId"`
}
type HistoricalEventProcession struct {
CivId int `json:"civId"`
FeatureLayerId int `json:"featureLayerId"`
OccasionId int `json:"occasionId"`
ScheduleId int `json:"scheduleId"`
SiteId int `json:"siteId"`
SubregionId int `json:"subregionId"`
}
type HistoricalEventRazedStructure struct {
CivId int `json:"civId"`
SiteId int `json:"siteId"`
StructureId int `json:"structureId"`
}
type HistoricalEventReclaimSite struct {
CivId int `json:"civId"`
SiteCivId int `json:"siteCivId"`
SiteId int `json:"siteId"`
}
type HistoricalEventRemoveHfEntityLink struct {
CivId int `json:"civId"`
Hfid int `json:"hfid"`
Link string `json:"link"`
PositionId int `json:"positionId"`
}
type HistoricalEventRemoveHfHfLink struct {
Hfid int `json:"hfid"`
HfidTarget int `json:"hfidTarget"`
}
type HistoricalEventSiteDispute struct {
Dispute string `json:"dispute"`
EntityId1 int `json:"entityId1"`
EntityId2 int `json:"entityId2"`
SiteId1 int `json:"siteId1"`
SiteId2 int `json:"siteId2"`
}
type HistoricalEventSiteTakenOver struct {
AttackerCivId int `json:"attackerCivId"`
DefenderCivId int `json:"defenderCivId"`
NewSiteCivId int `json:"newSiteCivId"`
SiteCivId int `json:"siteCivId"`
SiteId int `json:"siteId"`
}
type HistoricalEventSquadVsSquad struct {
AHfid int `json:"aHfid"`
ASquadId int `json:"aSquadId"`
DEffect int `json:"dEffect"`
DInteraction int `json:"dInteraction"`
DNumber int `json:"dNumber"`
DRace int `json:"dRace"`
DSlain int `json:"dSlain"`
DSquadId int `json:"dSquadId"`
FeatureLayerId int `json:"featureLayerId"`
SiteId int `json:"siteId"`
StructureId int `json:"structureId"`
SubregionId int `json:"subregionId"`
}
type HistoricalEventTacticalSituation struct {
ATacticianHfid int `json:"aTacticianHfid"`
ATacticsRoll int `json:"aTacticsRoll"`
DTacticianHfid int `json:"dTacticianHfid"`
DTacticsRoll int `json:"dTacticsRoll"`
FeatureLayerId int `json:"featureLayerId"`
SiteId int `json:"siteId"`
Situation string `json:"situation"`
Start string `json:"start"`
StructureId int `json:"structureId"`
SubregionId int `json:"subregionId"`
}
type HistoricalEventWrittenContentComposed struct {
Circumstance string `json:"circumstance"`
CircumstanceId int `json:"circumstanceId"`
HistFigureId int `json:"histFigureId"`
Reason string `json:"reason"`
ReasonId int `json:"reasonId"`
SiteId int `json:"siteId"`
WcId int `json:"wcId"`
}
type HistoricalEventCollection struct {
EndSeconds72 int `json:"endSeconds72"`
EndYear int `json:"endYear"`
Event []int `json:"event"`
Eventcol []int `json:"eventcol"`
Id_ int `json:"id"`
StartSeconds72 int `json:"startSeconds72"`
StartYear int `json:"startYear"`
Type string `json:"type"`
}
func (x *HistoricalEventCollection) Id() int { return x.Id_ }
type HistoricalEventCollectionBattle struct {
AttackingHfid []int `json:"attackingHfid"`
AttackingSquadDeaths []int `json:"attackingSquadDeaths"`
AttackingSquadEntityPop []int `json:"attackingSquadEntityPop"`
AttackingSquadNumber []int `json:"attackingSquadNumber"`
AttackingSquadRace []string `json:"attackingSquadRace"`
AttackingSquadSite []int `json:"attackingSquadSite"`
Coords string `json:"coords"`
DefendingHfid []int `json:"defendingHfid"`
DefendingSquadDeaths []int `json:"defendingSquadDeaths"`
DefendingSquadEntityPop []int `json:"defendingSquadEntityPop"`
DefendingSquadNumber []int `json:"defendingSquadNumber"`
DefendingSquadRace []string `json:"defendingSquadRace"`
DefendingSquadSite []int `json:"defendingSquadSite"`
FeatureLayerId int `json:"featureLayerId"`
IndividualMerc []string `json:"individualMerc"`
Name_ string `json:"name"`
NoncomHfid []int `json:"noncomHfid"`
Outcome string `json:"outcome"`
SiteId int `json:"siteId"`
SubregionId int `json:"subregionId"`
WarEventcol int `json:"warEventcol"`
}
func (x *HistoricalEventCollectionBattle) Name() string { return x.Name_ }
type HistoricalEventCollectionBeastAttack struct {
Coords string `json:"coords"`
DefendingEnid int `json:"defendingEnid"`
FeatureLayerId int `json:"featureLayerId"`
Ordinal int `json:"ordinal"`
ParentEventcol int `json:"parentEventcol"`
SiteId int `json:"siteId"`
SubregionId int `json:"subregionId"`
}
type HistoricalEventCollectionDuel struct {
AttackingHfid int `json:"attackingHfid"`
Coords string `json:"coords"`
DefendingHfid int `json:"defendingHfid"`
FeatureLayerId int `json:"featureLayerId"`
Ordinal int `json:"ordinal"`
ParentEventcol int `json:"parentEventcol"`
SiteId int `json:"siteId"`
SubregionId int `json:"subregionId"`
}
type HistoricalEventCollectionOccasion struct {
CivId int `json:"civId"`
OccasionId int `json:"occasionId"`
Ordinal int `json:"ordinal"`
}
type HistoricalEventCollectionSiteConquered struct {
AttackingEnid int `json:"attackingEnid"`
DefendingEnid int `json:"defendingEnid"`
Ordinal int `json:"ordinal"`
SiteId int `json:"siteId"`
WarEventcol int `json:"warEventcol"`
}
type HistoricalEventCollectionWar struct {
AggressorEntId int `json:"aggressorEntId"`
DefenderEntId int `json:"defenderEntId"`
Name_ string `json:"name"`
}
func (x *HistoricalEventCollectionWar) Name() string { return x.Name_ }
type HistoricalFigure struct {
Appeared int `json:"appeared"`
AssociatedType string `json:"associatedType"`
BirthSeconds72 int `json:"birthSeconds72"`
BirthYear int `json:"birthYear"`
Caste string `json:"caste"`
CurrentIdentityId int `json:"currentIdentityId"`
DeathSeconds72 int `json:"deathSeconds72"`
DeathYear int `json:"deathYear"`
Deity string `json:"deity"`
EntPopId int `json:"entPopId"`
EntityFormerPositionLink []EntityFormerPositionLink `json:"entityFormerPositionLink"`
EntityLink []EntityLink `json:"entityLink"`
EntityPositionLink []EntityPositionLink `json:"entityPositionLink"`
EntityReputation map[int]* `json:"entityReputation"`
EntitySquadLink EntitySquadLink `json:"entitySquadLink"`
Force string `json:"force"`
Goal []string `json:"goal"`
HfLink []HfLink `json:"hfLink"`
HfSkill []HfSkill `json:"hfSkill"`
HoldsArtifact int `json:"holdsArtifact"`
Id_ int `json:"id"`
InteractionKnowledge []string `json:"interactionKnowledge"`
IntrigueActor IntrigueActor `json:"intrigueActor"`
IntriguePlot []IntriguePlot `json:"intriguePlot"`
JourneyPet []string `json:"journeyPet"`
Name_ string `json:"name"`
Race string `json:"race"`
RelationshipProfileHfHistorical RelationshipProfileHfHistorical `json:"relationshipProfileHfHistorical"`
RelationshipProfileHfVisual []RelationshipProfileHfVisual `json:"relationshipProfileHfVisual"`
SiteLink SiteLink `json:"siteLink"`
Sphere []string `json:"sphere"`
UsedIdentityId int `json:"usedIdentityId"`
VagueRelationship []VagueRelationship `json:"vagueRelationship"`
}
func (x *HistoricalFigure) Id() int { return x.Id_ }
func (x *HistoricalFigure) Name() string { return x.Name_ }
type IntrigueActor struct {
Hfid int `json:"hfid"`
LocalId int `json:"localId"`
Role string `json:"role"`
Strategy string `json:"strategy"`
}
type IntriguePlot struct {
ActorId int `json:"actorId"`
ArtifactId int `json:"artifactId"`
EntityId int `json:"entityId"`
LocalId int `json:"localId"`
OnHold string `json:"onHold"`
Type string `json:"type"`
}
type Item struct {
NameString string `json:"nameString"`
PageNumber int `json:"pageNumber"`
PageWrittenContentId int `json:"pageWrittenContentId"`
WritingWrittenContentId int `json:"writingWrittenContentId"`
}
type MusicalForm struct {
Description string `json:"description"`
Id_ int `json:"id"`
}
func (x *MusicalForm) Id() int { return x.Id_ }
type PoeticForm struct {
Description string `json:"description"`
Id_ int `json:"id"`
}
func (x *PoeticForm) Id() int { return x.Id_ }
type Region struct {
Id_ int `json:"id"`
Name_ string `json:"name"`
Type string `json:"type"`
}
func (x *Region) Id() int { return x.Id_ }
func (x *Region) Name() string { return x.Name_ }
type RelationshipProfileHfHistorical struct {
Fear int `json:"fear"`
HfId int `json:"hfId"`
Love int `json:"love"`
Loyalty int `json:"loyalty"`
Respect int `json:"respect"`
Trust int `json:"trust"`
}
type RelationshipProfileHfVisual struct {
Fear int `json:"fear"`
HfId int `json:"hfId"`
KnownIdentityId int `json:"knownIdentityId"`
LastMeetSeconds72 int `json:"lastMeetSeconds72"`
LastMeetYear int `json:"lastMeetYear"`
Love int `json:"love"`
Loyalty int `json:"loyalty"`
MeetCount int `json:"meetCount"`
RepFriendly int `json:"repFriendly"`
RepInformationSource int `json:"repInformationSource"`
Respect int `json:"respect"`
Trust int `json:"trust"`
}
type Site struct {
Id_ int `json:"id"`
Type string `json:"type"`
}
func (x *Site) Id() int { return x.Id_ }
type SiteCamp struct {
Coords string `json:"coords"`
Name_ string `json:"name"`
Rectangle string `json:"rectangle"`
}
func (x *SiteCamp) Name() string { return x.Name_ }
type SiteCave struct {
Coords string `json:"coords"`
Name_ string `json:"name"`
Rectangle string `json:"rectangle"`
Structures map[int]*Structure `json:"structures"`
}
func (x *SiteCave) Name() string { return x.Name_ }
type SiteDarkFortress struct {
Coords string `json:"coords"`
Name_ string `json:"name"`
Rectangle string `json:"rectangle"`
Structures map[int]*Structure `json:"structures"`
}
func (x *SiteDarkFortress) Name() string { return x.Name_ }
type SiteDarkPits struct {
Coords string `json:"coords"`
Name_ string `json:"name"`
Rectangle string `json:"rectangle"`
}
func (x *SiteDarkPits) Name() string { return x.Name_ }
type SiteForestRetreat struct {
Coords string `json:"coords"`
Name_ string `json:"name"`
Rectangle string `json:"rectangle"`
Structures map[int]*Structure `json:"structures"`
}
func (x *SiteForestRetreat) Name() string { return x.Name_ }
type SiteFortress struct {
Coords string `json:"coords"`
Name_ string `json:"name"`
Rectangle string `json:"rectangle"`
Structures map[int]*Structure `json:"structures"`
}
func (x *SiteFortress) Name() string { return x.Name_ }
type SiteHamlet struct {
Coords string `json:"coords"`
Name_ string `json:"name"`
Rectangle string `json:"rectangle"`
Structures map[int]*Structure `json:"structures"`
}
func (x *SiteHamlet) Name() string { return x.Name_ }
type SiteHillocks struct {
Coords string `json:"coords"`
Name_ string `json:"name"`
Rectangle string `json:"rectangle"`
}
func (x *SiteHillocks) Name() string { return x.Name_ }
type SiteLabyrinth struct {
Coords string `json:"coords"`
Name_ string `json:"name"`
Rectangle string `json:"rectangle"`
}
func (x *SiteLabyrinth) Name() string { return x.Name_ }
type SiteLair struct {
Coords string `json:"coords"`
Name_ string `json:"name"`
Rectangle string `json:"rectangle"`
}
func (x *SiteLair) Name() string { return x.Name_ }
type SiteShrine struct {
Coords string `json:"coords"`
Name_ string `json:"name"`
Rectangle string `json:"rectangle"`
}
func (x *SiteShrine) Name() string { return x.Name_ }
type SiteTown struct {
Coords string `json:"coords"`
Name_ string `json:"name"`
Rectangle string `json:"rectangle"`
Structures map[int]*Structure `json:"structures"`
}
func (x *SiteTown) Name() string { return x.Name_ }
type SiteVault struct {
Coords string `json:"coords"`
Name_ string `json:"name"`
Rectangle string `json:"rectangle"`
}
func (x *SiteVault) Name() string { return x.Name_ }
type SiteLink struct {
EntityId int `json:"entityId"`
LinkType string `json:"linkType"`
OccupationId int `json:"occupationId"`
SiteId int `json:"siteId"`
SubId int `json:"subId"`
}
type Structure struct {
LocalId int `json:"localId"`
Type string `json:"type"`
}
type StructureTemple struct {
EntityId int `json:"entityId"`
Name_ string `json:"name"`
}
func (x *StructureTemple) Name() string { return x.Name_ }
type UndergroundRegion struct {
Id_ int `json:"id"`
Type string `json:"type"`
}
func (x *UndergroundRegion) Id() int { return x.Id_ }
type VagueRelationship struct {
ChildhoodFriend string `json:"childhoodFriend"`
Hfid int `json:"hfid"`
JealousObsession string `json:"jealousObsession"`
WarBuddy string `json:"warBuddy"`
}
type WrittenContent struct {
AuthorHfid int `json:"authorHfid"`
AuthorRoll int `json:"authorRoll"`
Form string `json:"form"`
FormId int `json:"formId"`
Id_ int `json:"id"`
Style []string `json:"style"`
Title string `json:"title"`
}
func (x *WrittenContent) Id() int { return x.Id_ }

7
generate.go Normal file
View file

@ -0,0 +1,7 @@
//go:build ignore
package main
// func main() {
// generate.Generate()
// }

64
generate/model.go Normal file
View file

@ -0,0 +1,64 @@
package generate
import (
"bufio"
"log"
"net/http"
"os"
"strings"
"text/template"
"time"
)
func Generate() {
const url = "https://github.com/golang/go/raw/master/CONTRIBUTORS"
rsp, err := http.Get(url)
die(err)
defer rsp.Body.Close()
sc := bufio.NewScanner(rsp.Body)
carls := []string{}
for sc.Scan() {
if strings.Contains(sc.Text(), "Carl") {
carls = append(carls, sc.Text())
}
}
die(sc.Err())
f, err := os.Create("contributors.go")
die(err)
defer f.Close()
packageTemplate.Execute(f, struct {
Timestamp time.Time
URL string
Carls []string
}{
Timestamp: time.Now(),
URL: url,
Carls: carls,
})
}
func die(err error) {
if err != nil {
log.Fatal(err)
}
}
var packageTemplate = template.Must(template.New("").Parse(`// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at
// {{ .Timestamp }}
// using data from
// {{ .URL }}
package project
var Contributors = []string{
{{- range .Carls }}
{{ printf "%q" . }},
{{- end }}
}
`))

25
main.go
View file

@ -1,23 +1,40 @@
package main
import (
"flag"
"fmt"
"legendsbrowser/analyze"
"legendsbrowser/model"
"legendsbrowser/server"
"net/http"
_ "net/http/pprof"
"os"
"runtime"
"github.com/gorilla/mux"
"github.com/pkg/profile"
)
var world model.World
func main() {
// defer profile.Start(profile.MemProfile).Stop()
// go func() {
// http.ListenAndServe(":8081", nil)
// }()
var a string
flag.StringVar(&a, "a", "", "analyze a file")
flag.Parse()
if len(a) == 0 {
fmt.Println("Usage: defaults.go -a")
flag.PrintDefaults()
os.Exit(1)
} else {
analyze.Analyze(a)
os.Exit(1)
}
defer profile.Start(profile.MemProfile).Stop()
go func() {
http.ListenAndServe(":8081", nil)
}()
fmt.Println("Hallo Welt!")

2633
model.json Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,12 +1,9 @@
package model
import "encoding/xml"
type HistoricalEvent struct {
XMLName xml.Name `xml:"historical_event" json:"-"`
Id_ int `xml:"id" json:"id"`
Year int `xml:"year" json:"year"`
Seconds int `xml:"seconds72" json:"seconds72"`
Id_ int `xml:"id" json:"id"`
Year int `xml:"year" json:"year"`
Seconds int `xml:"seconds72" json:"seconds72"`
TypedObject
ASupportMercEnid *int `xml:"a_support_merc_enid" json:"aSupportMercEnid,omitempty" legend:"entity"`
@ -226,7 +223,7 @@ type HistoricalEvent struct {
WounderHfid *int `xml:"wounder_hfid" json:"wounderHfid,omitempty" legend:"hf"`
WrongfulConviction *string `xml:"wrongful_conviction" json:"wrongfulConviction,omitempty"`
OtherElements
//OtherElements
}
func (r *HistoricalEvent) Id() int { return r.Id_ }

View file

@ -1,40 +1,34 @@
package model
import "encoding/xml"
type Region struct {
XMLName xml.Name `xml:"region" json:"-"`
NamedObject
Type string `xml:"type" json:"type"`
OtherElements
// OtherElements
EventObject
}
type UndergroundRegion struct {
XMLName xml.Name `xml:"underground_region" json:"-"`
NamedObject
Type string `xml:"type" json:"type"`
Depth *int `xml:"depth" json:"depth,omitempty"`
OtherElements
// OtherElements
EventObject
}
type Landmass struct {
XMLName xml.Name `xml:"landmass" json:"-"`
NamedObject
OtherElements
// OtherElements
EventObject
}
type Site struct {
XMLName xml.Name `xml:"site" json:"-"`
NamedObject
Type string `xml:"type" json:"type"`
Coords string `xml:"coords" json:"coords"`
Rectangle string `xml:"rectangle" json:"rectangle"`
Structures []Structure `xml:"structures>structure" json:"structures"`
OtherElements
// OtherElements
EventObject
}
@ -42,23 +36,20 @@ type Site struct {
// func (obj Site) name() string { return obj.Name }
type Structure struct {
XMLName xml.Name `xml:"structure" json:"-"`
LocalId int `xml:"local_id" json:"localId"`
Name string `xml:"name" json:"name"`
Type string `xml:"type" json:"type"`
OtherElements
LocalId int `xml:"local_id" json:"localId"`
Name string `xml:"name" json:"name"`
Type string `xml:"type" json:"type"`
// OtherElements
EventObject
}
type WorldConstruction struct {
XMLName xml.Name `xml:"world_construction" json:"-"`
NamedObject
OtherElements
// OtherElements
EventObject
}
type Artifact struct {
XMLName xml.Name `xml:"artifact" json:"-"`
NamedObject
SiteId int `xml:"site_id" json:"siteId"`
AbsTileX *int `xml:"abs_tile_x" json:"absTileX,omitempty"`
@ -69,13 +60,12 @@ type Artifact struct {
StructureLocalId *int `xml:"structure_local_id" json:"structureLocalId,omitempty"`
SubregionId *int `xml:"subregion_id" json:"subregionId,omitempty"`
OtherElements
// OtherElements
EventObject
}
type HistoricalFigure struct {
XMLName xml.Name `xml:"historical_figure" json:"-"`
NamedObject
Race *string `xml:"race" json:"race"`
@ -115,7 +105,7 @@ type HistoricalFigure struct {
// UsedIdentityId *[]int `xml:"used_identity_id" json:"usedIdentityId,omitempty" legend:"entity"`
// // vague_relationship object
OtherElements
// OtherElements
EventObject
}
@ -123,7 +113,6 @@ type HistoricalFigure struct {
func (r *HistoricalFigure) Type() string { return "hf" }
type HistoricalEventCollection struct {
XMLName xml.Name `xml:"historical_event_collection" json:"-"`
NamedObject
Year int `xml:"year"`
Seconds int `xml:"seconds72"`
@ -175,45 +164,38 @@ type HistoricalEventCollection struct {
DefendingSquadAnimated *[]string `xml:"defending_squad_animated" json:"defendingSquadAnimated,omitempty"`
TargetEntityId *int `xml:"target_entity_id" json:"targetEntityId,omitempty" legend:"entity"`
OtherElements
// OtherElements
}
type Entity struct {
XMLName xml.Name `xml:"entity" json:"-"`
NamedObject
OtherElements
// OtherElements
EventObject
}
type EntityPopulation struct {
XMLName xml.Name `xml:"entity_population" json:"-"`
OtherElements
// OtherElements
}
type HistoricalEra struct {
XMLName xml.Name `xml:"historical_era" json:"-"`
NamedObject
StartYear *int `xml:"start_year" json:"startYear,omitempty"`
OtherElements
// OtherElements
}
type DanceForm struct {
XMLName xml.Name `xml:"dance_form" json:"-"`
ArtForm
}
type MusicalForm struct {
XMLName xml.Name `xml:"musical_form" json:"-"`
ArtForm
}
type PoeticForm struct {
XMLName xml.Name `xml:"poetic_form" json:"-"`
ArtForm
}
type WrittenContent struct {
XMLName xml.Name `xml:"written_content" json:"-"`
NamedObject
AuthorHfid *int `xml:"author_hfid" json:"authorHfid,omitempty" legend:"hf"`
@ -223,7 +205,7 @@ type WrittenContent struct {
Style *[]string `xml:"style" json:"style,omitempty"`
Title *string `xml:"title" json:"title,omitempty"`
OtherElements
// OtherElements
EventObject
}
@ -232,6 +214,6 @@ type ArtForm struct {
Description *string `xml:"description" json:"description,omitempty"`
OtherElements
// OtherElements
EventObject
}

View file

@ -4,7 +4,7 @@ import (
"encoding/xml"
"errors"
"fmt"
"io"
"legendsbrowser/util"
"os"
"reflect"
"strings"
@ -15,22 +15,6 @@ type World struct {
Name string `xml:"name"`
AltName string `xml:"altname"`
// Regions []*Region `xml:"regions>region"`
// UndergroundRegions []*UndergroundRegion `xml:"underground_regions>underground_region"`
// Landmasses []*Landmass `xml:"landmasses>landmass"`
// Sites []*Site `xml:"sites>site"`
// WorldConstructions []*WorldConstruction `xml:"world_constructions>world_construction"`
// Artifacts []*Artifact `xml:"artifacts>artifact"`
// HistoricalFigures []*HistoricalFigure //`xml:"historical_figures>historical_figure"`
// HistoricalEvents []*HistoricalEvent //`xml:"historical_events>historical_event"`
// HistoricalEventCollections []*HistoricalEventCollection `xml:"historical_event_collections>historical_event_collection"`
// HistoricalEras []*HistoricalEra `xml:"historical_eras>historical_era"`
// Entities []*Entity `xml:"entities>entity"`
// EntityPopulations []*EntityPopulation `xml:"entity_populations>entity_population"`
// DanceForms []*DanceForm `xml:"dance_forms>dance_form"`
// MusicalForms []*MusicalForm `xml:"musical_forms>musical_form"`
// PoeticForms []*PoeticForm `xml:"poetic_forms>poetic_form"`
// WrittenContents []*WrittenContent `xml:"written_contents>written_content"`
OtherElements
RegionMap map[int]*Region `xml:"regions>region"`
@ -45,32 +29,11 @@ type World struct {
HistoricalEraMap map[int]*HistoricalEra `xml:"historical_eras>historical_era"`
EntityMap map[int]*Entity `xml:"entities>entity"`
DanceFormMap map[int]*DanceForm `xml:"dance_forms>dance_form"`
MusicalFormMap map[int]*MusicalForm //`xml:"musical_forms>musical_form"`
PoeticFormMap map[int]*PoeticForm // `xml:"poetic_forms>poetic_form"`
MusicalFormMap map[int]*MusicalForm `xml:"musical_forms>musical_form"`
PoeticFormMap map[int]*PoeticForm `xml:"poetic_forms>poetic_form"`
WrittenContentMap map[int]*WrittenContent `xml:"written_contents>written_content"`
}
var cp437 = []byte(" \t\n \r !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ CueaaaaceeeiiiAAEaAooouuyOU faiounN ")
// var cp437 = []byte(" \t\n \r !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñÑ ")
type ConvertReader struct {
r io.Reader
read int
}
func (c *ConvertReader) Read(b []byte) (n int, err error) {
n, err = c.r.Read(b)
if c.read == 0 && n > 35 {
copy(b[30:35], []byte("UTF-8"))
}
c.read += n
for i := range b {
b[i] = cp437[b[i]]
}
return n, err
}
func (w *World) Load(file string) {
xmlFile, err := os.Open(file)
if err != nil {
@ -80,7 +43,7 @@ func (w *World) Load(file string) {
fmt.Println("Successfully Opened users.xml")
defer xmlFile.Close()
converter := &ConvertReader{r: xmlFile}
converter := util.NewConvertReader(xmlFile)
// byteValue, _ := io.ReadAll(converter)
// fmt.Println(len(byteValue))
@ -182,7 +145,6 @@ Loop:
f.Set(reflect.MakeMapWithSize(ty.Type, 0))
}
parseMap(d, ty, f)
val.Field(ty.Index[0]).SetMapIndex(reflect.ValueOf(6), reflect.New(ty.Type.Elem().Elem()))
}
} else {
d.Skip()

28
util/cp473.go Normal file
View file

@ -0,0 +1,28 @@
package util
import "io"
var cp437 = []byte(" \t\n \r !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ CueaaaaceeeiiiAAEaAooouuyOU faiounN ")
// var cp437 = []byte(" \t\n \r !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñÑ ")
type ConvertReader struct {
r io.Reader
read int
}
func NewConvertReader(r io.Reader) *ConvertReader {
return &ConvertReader{r: r}
}
func (c *ConvertReader) Read(b []byte) (n int, err error) {
n, err = c.r.Read(b)
if c.read == 0 && n > 35 {
copy(b[30:35], []byte("UTF-8"))
}
c.read += n
for i := range b {
b[i] = cp437[b[i]]
}
return n, err
}