mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-06-06 21:08:48 +08:00
Add support to insert a new language to kirikiri scn script
This commit is contained in:
@@ -85,6 +85,26 @@ impl From<f32> for PsbValueFixed {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PsbObjectFixed> for PsbValueFixed {
|
||||
fn from(value: PsbObjectFixed) -> Self {
|
||||
PsbValueFixed::Object(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PsbListFixed> for PsbValueFixed {
|
||||
fn from(value: PsbListFixed) -> Self {
|
||||
PsbValueFixed::List(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&[PsbValueFixed]> for PsbValueFixed {
|
||||
fn from(value: &[PsbValueFixed]) -> Self {
|
||||
PsbValueFixed::List(PsbListFixed {
|
||||
values: value.to_vec(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl PsbValueFixed {
|
||||
/// Converts this value to original PSB value type.
|
||||
pub fn to_psb(self, warn_on_none: bool) -> PsbValue {
|
||||
@@ -284,6 +304,33 @@ impl PsbValueFixed {
|
||||
}
|
||||
}
|
||||
|
||||
/// Clears all members in a list. If this value is not a list, it will be converted to an empty list.
|
||||
pub fn clear_members(&mut self) {
|
||||
match self {
|
||||
PsbValueFixed::List(l) => {
|
||||
l.clear();
|
||||
}
|
||||
_ => {
|
||||
*self = PsbValueFixed::List(PsbListFixed { values: vec![] });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Inserts a new member at the specified index in a list. If this value is not a list, it will be converted to a list.
|
||||
/// If the index is out of bounds, the value will be appended to the end of the list.
|
||||
pub fn insert_member<T: Into<PsbValueFixed>>(&mut self, index: usize, value: T) {
|
||||
match self {
|
||||
PsbValueFixed::List(l) => {
|
||||
l.insert(index, value);
|
||||
}
|
||||
_ => {
|
||||
*self = PsbValueFixed::List(PsbListFixed {
|
||||
values: vec![value.into()],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the resource ID if this value is a resource reference.
|
||||
pub fn resource_id(&self) -> Option<u64> {
|
||||
match self {
|
||||
@@ -615,6 +662,21 @@ impl PsbListFixed {
|
||||
self.values.len()
|
||||
}
|
||||
|
||||
/// Clears all values in the list.
|
||||
pub fn clear(&mut self) {
|
||||
self.values.clear();
|
||||
}
|
||||
|
||||
/// Inserts a new value at the specified index in the list.
|
||||
/// If the index is out of bounds, the value will be appended to the end of the list.
|
||||
pub fn insert<V: Into<PsbValueFixed>>(&mut self, index: usize, value: V) {
|
||||
if index <= self.values.len() {
|
||||
self.values.insert(index, value.into());
|
||||
} else {
|
||||
self.values.push(value.into());
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts this PSB list to a JSON value.
|
||||
#[cfg(feature = "json")]
|
||||
pub fn to_json(&self) -> JsonValue {
|
||||
|
||||
Reference in New Issue
Block a user