feat: add renames
This commit is contained in:
parent
3725cffb90
commit
42b1e8e358
3 changed files with 62 additions and 6 deletions
|
@ -1,4 +1,9 @@
|
||||||
defmodule PortingTools.Mappings.Agent do
|
defmodule PortingTools.Mappings.Agent do
|
||||||
|
@moduledoc """
|
||||||
|
This module manages and loads the mappings
|
||||||
|
and renames.
|
||||||
|
"""
|
||||||
|
|
||||||
use Agent, restart: :transient
|
use Agent, restart: :transient
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
@ -6,22 +11,64 @@ defmodule PortingTools.Mappings.Agent do
|
||||||
Agent.start_link(&init/0, name: __MODULE__)
|
Agent.start_link(&init/0, name: __MODULE__)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defmodule PortingTools.Mappings.Agent.State do
|
||||||
|
defstruct [:mappings, :renames]
|
||||||
|
end
|
||||||
|
|
||||||
def init() do
|
def init() do
|
||||||
Logger.info("Reading mappings")
|
%PortingTools.Mappings.Agent.State{
|
||||||
|
mappings: load_mappings(),
|
||||||
|
renames: load_renames()
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_mappings() do
|
||||||
|
Logger.info("reading mappings")
|
||||||
|
|
||||||
mappings =
|
mappings =
|
||||||
File.ls!("mappings")
|
File.ls!("mappings")
|
||||||
|> Stream.flat_map(&File.stream!("mappings/#{&1}"))
|
|> Stream.flat_map(&File.stream!("mappings/#{&1}"))
|
||||||
|> Stream.map(&String.split(&1, ","))
|
|> Stream.map(&String.split(&1, ","))
|
||||||
|> Enum.reduce(%{}, fn [remapped, orig | _], map ->
|
|> Enum.reduce(%{}, fn [remapped, orig | _], map ->
|
||||||
Map.put(map, remapped, orig)
|
Map.put(map, String.trim(remapped), String.trim(orig))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Logger.info("Done reading mappings")
|
Logger.info("read #{map_size(mappings)} mappings")
|
||||||
mappings
|
mappings
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def load_renames() do
|
||||||
|
Logger.info("reading renames")
|
||||||
|
|
||||||
|
renames =
|
||||||
|
File.stream!("renames.csv")
|
||||||
|
|> Stream.map(&String.split(&1, ","))
|
||||||
|
|> Enum.reduce(%{}, fn [old, new | _], map ->
|
||||||
|
Map.put(map, String.trim(old), String.trim(new))
|
||||||
|
end)
|
||||||
|
|
||||||
|
Logger.info("read #{map_size(renames)} renames")
|
||||||
|
|
||||||
|
renames
|
||||||
|
end
|
||||||
|
|
||||||
def map(key) do
|
def map(key) do
|
||||||
Agent.get(__MODULE__, &Map.get(&1, key))
|
mapping = Agent.get(__MODULE__, &Map.get(&1.mappings, key))
|
||||||
|
|
||||||
|
case mapping do
|
||||||
|
nil ->
|
||||||
|
Logger.warn("tried to map unknown symbol")
|
||||||
|
nil
|
||||||
|
|
||||||
|
m ->
|
||||||
|
case Agent.get(__MODULE__, &Map.get(&1.renames, m)) do
|
||||||
|
nil ->
|
||||||
|
m
|
||||||
|
|
||||||
|
r ->
|
||||||
|
Logger.info("found rename for #{m} -> #{r}")
|
||||||
|
r
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@ defmodule PortingTools.ResourceLoc do
|
||||||
end
|
end
|
||||||
|
|
||||||
def init(_init_arg) do
|
def init(_init_arg) do
|
||||||
Logger.info("Initializing Resourceloc server @ #{__MODULE__}")
|
Logger.info("initializing Resourceloc server @ #{__MODULE__}")
|
||||||
{:ok, nil}
|
{:ok, nil}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ defmodule PortingTools.ResourceLoc do
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_call({:resolve, str}, _from, state) do
|
def handle_call({:resolve, str}, _from, state) do
|
||||||
Logger.info("Got resolve request")
|
Logger.info("got ResourceLoc resolve request")
|
||||||
|
|
||||||
try do
|
try do
|
||||||
["mods", mod | rest] =
|
["mods", mod | rest] =
|
||||||
|
|
9
renames.csv
Normal file
9
renames.csv
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
getBlockTileEntity,getTileEntity
|
||||||
|
fontRenderer,fontRendererObj
|
||||||
|
getInvName,getInventoryName
|
||||||
|
tagAt,getCompoundTagAt
|
||||||
|
isInvNameLocalized,hasCustomInventoryName
|
||||||
|
getTexture,bindTexture
|
||||||
|
bindTextureByName,bindTexture
|
||||||
|
username,getDisplayName()
|
||||||
|
getLastAttackingEntity,getLastAttacker
|
|
Loading…
Reference in a new issue