Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
0.3.6 release
Browse files Browse the repository at this point in the history
  • Loading branch information
ElusiveMori committed Mar 6, 2020
1 parent 5027d9e commit 5a8c737
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.3.6

* Fixed an issue (for the umptienth time) related to incorrect handling of backwards slashes in Ceres.
* Ceres no longer writes out object data files if there were no object data modifications. This means it doesn't create blank object data files anymore, and it also won't touch your existing object data if you do not modify it in Ceres.

# 0.3.5

* Fixed an issue with `map:addDir` and `dir` mapmode.
Expand Down
8 changes: 1 addition & 7 deletions ceres-binaries/src/bin/ceres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@ fn main() {
dotenv::dotenv().ok();

let matches = clap_app!(Ceres =>
(version: "0.3.5")
(version: "0.3.6")
(author: "mori <[email protected]>")
(about: "Ceres is a build tool, script compiler and map preprocessor for WC3 Lua maps.")
(@subcommand build =>
(about: "Uses the build.lua file in the current directory to build a map.")
(setting: clap::AppSettings::TrailingVarArg)
(@arg manifest: --manifest +takes_value)
(@arg dir: --dir -d +takes_value "Sets the project directory.")
(@arg BUILD_ARGS: ... "Arguments to pass to the build script.")
)
(@subcommand run =>
(about: "Uses the build.lua file in the current directory to build and run a map.")
(setting: clap::AppSettings::TrailingVarArg)
(@arg manifest: --manifest +takes_value)
(@arg dir: --dir -d +takes_value "Sets the project directory.")
(@arg BUILD_ARGS: ... "Arguments to pass to the build script.")
)
Expand Down Expand Up @@ -58,10 +56,6 @@ fn run_build(arg: &clap::ArgMatches, mode: ceres_core::CeresRunMode) -> Result<(
.map(std::iter::Iterator::collect)
.unwrap_or_else(Vec::new);

let manifest_port = arg
.value_of("manifest")
.map(|s| u16::from_str_radix(s, 10).unwrap());

ceres_core::run_build_script(mode, project_dir, script_args)?;

Ok(())
Expand Down
26 changes: 19 additions & 7 deletions ceres-core/src/lua/mpq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,18 @@ impl LuaUserData for Viewer {
Ok(wrap_result(ctx, result))
});

methods.add_method_mut("files", |_, obj, _: ()| Ok(obj.archive.files()));
methods.add_method_mut("files", |_, obj, _: ()| {
if let Some(files) = obj.archive.files() {
return Ok(Some(
files
.iter()
.map(|p| p.replace("\\", "/"))
.collect::<Vec<_>>(),
));
}

Ok(None)
});

methods.add_method_mut("extractTo", |ctx, obj, path: LuaString| {
let result = readflow_extract(&mut obj.archive, path);
Expand Down Expand Up @@ -133,26 +144,27 @@ fn readflow_extract(archive: &mut FileArchive, path: LuaString) -> Result<bool,
let files = archive
.files()
.ok_or_else(|| StringError::new("no listfile found"))?;
for file in files {
let contents = archive.read_file(&file);
for file_path in files {
let contents = archive.read_file(&file_path);

if let Err(error) = contents {
eprintln!("mpq.extractTo(): could not read file {}: {}", file, error);
eprintln!("mpq.extractTo(): could not read file {}: {}", file_path, error);
continue;
}

let out_path = path.join(&file);
let file_path = file_path.replace("\\", "/");
let out_path = path.join(&file_path);

if let Err(error) = fs::create_dir_all(out_path.parent().unwrap()) {
eprintln!(
"mpq.extractTo(): could not create directory for file {}: {}",
file, error
file_path, error
);
continue;
}

if let Err(error) = fs::write(out_path, contents.unwrap()) {
eprintln!("mpq.extractTo(): could not write file {}: {}", file, error);
eprintln!("mpq.extractTo(): could not write file {}: {}", file_path, error);
continue;
}
}
Expand Down
5 changes: 4 additions & 1 deletion ceres-core/src/lua/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,11 @@ impl LuaObjectStoreWrapper {
) -> Result<LuaValue<'lua>, LuaError> {
let mut data = data.borrow_mut::<LuaObjectStoreWrapper>()?;
let kind = data.kind;
let data = &mut data.inner;
let mut data = &mut data.inner;
let value = LuaString::from_lua(value, ctx)?;

w3obj::read::read_object_file(value.as_bytes(), data, kind).map_err(LuaError::external)?;
data.reset_dirty();

Ok(LuaValue::Nil)
}
Expand Down Expand Up @@ -501,6 +502,7 @@ impl LuaObjectStoreWrapper {
b"setObject" => return Ok(StaticMethods::objstore_setobject_fn(ctx)),
b"ext" => return Ok(kind.to_ext().to_lua(ctx)?),
b"typestr" => return Ok(kind.to_typestr().to_lua(ctx)?),
b"isDirty" => return Ok(data_inner.is_dirty().to_lua(ctx)?),
_ => {}
}
}
Expand Down Expand Up @@ -545,6 +547,7 @@ fn open_store_from_str(
) -> Result<LuaObjectStoreWrapper, anyhow::Error> {
let mut data = ObjectStore::default();
w3obj::read::read_object_file(source, &mut data, kind)?;
data.reset_dirty();

Ok(LuaObjectStoreWrapper { inner: data, kind })
}
Expand Down
6 changes: 4 additions & 2 deletions ceres-core/src/resource/buildscript_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,10 @@ function mapMeta:initObjects()
end

function mapMeta:commitObjectStorage(storage)
local data = storage:writeToString()
self:addFileString("war3map." .. storage.ext, data)
if storage.isDirty then
local data = storage:writeToString()
self:addFileString("war3map." .. storage.ext, data)
end
end

function mapMeta:commitObjects()
Expand Down
21 changes: 21 additions & 0 deletions ceres-formats/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub struct Object {
id: ObjectId,
parent_id: Option<ObjectId>,
fields: BTreeMap<ObjectId, Field>,
dirty: bool,
}

impl Object {
Expand All @@ -70,6 +71,7 @@ impl Object {
kind,
parent_id: None,
fields: Default::default(),
dirty: true,
}
}

Expand All @@ -79,6 +81,7 @@ impl Object {
kind,
parent_id: Some(parent_id),
fields: Default::default(),
dirty: true,
}
}

Expand All @@ -102,6 +105,14 @@ impl Object {
self.kind
}

pub fn is_dirty(&self) -> bool {
self.dirty
}

pub fn set_dirty(&mut self, dirty: bool) {
self.dirty = dirty
}

pub fn fields(&self) -> impl Iterator<Item = (&ObjectId, &Field)> {
self.fields.iter()
}
Expand All @@ -128,10 +139,14 @@ impl Object {
}

pub fn unset_simple_field(&mut self, id: ObjectId) {
self.dirty = true;

self.fields.remove(&id);
}

pub fn unset_leveled_field(&mut self, id: ObjectId, level: u32) {
self.dirty = true;

if let Some(field) = self.fields.get_mut(&id) {
if let FieldKind::Leveled { values } = &mut field.kind {
values.retain(|dv| dv.level != level)
Expand All @@ -140,12 +155,16 @@ impl Object {
}

pub fn set_simple_field(&mut self, id: ObjectId, value: Value) {
self.dirty = true;

let kind = FieldKind::Simple { value };
let field = Field { id, kind };
self.fields.insert(id, field);
}

pub fn set_leveled_field(&mut self, id: ObjectId, level: u32, value: Value) {
self.dirty = true;

let field = self.fields.entry(id).or_insert_with(|| Field {
id,
kind: FieldKind::Leveled {
Expand Down Expand Up @@ -175,6 +194,8 @@ impl Object {
/// in our use case. Just override the fields in this object
/// from the fields in the other.
pub fn add_from(&mut self, other: &Object) {
self.dirty = true;

for (id, field) in &other.fields {
self.fields.insert(*id, field.clone());
}
Expand Down
18 changes: 18 additions & 0 deletions ceres-formats/src/objectstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ impl Default for ObjectStoreStock {
}

impl ObjectStore {
pub fn is_dirty(&self) -> bool {
for object in self.objects.values() {
let object = object.borrow();
if object.is_dirty() {
return true;
}
}

false
}

pub fn reset_dirty(&self) {
for object in self.objects.values() {
let mut object = object.borrow_mut();
object.set_dirty(false);
}
}

pub fn objects(&self) -> impl Iterator<Item = &Rc<RefCell<Object>>> {
self.objects.values()
}
Expand Down

0 comments on commit 5a8c737

Please sign in to comment.